문제

Hello I am making a program to read chat and if the chat is a certain thing it presses a certain key. I have noticed that the code works, but not when I am in a game. CODE:

 if (message.equals("up"))
            {
                try {
                    Robot robot = new Robot();

                    robot.keyPress(KeyEvent.VK_W); // press a
                    robot.keyRelease(KeyEvent.VK_W); // release a

                } catch (AWTException e) {
                   e.printStackTrace();
                }
            }

I have tried making so that there are more keypresses because I thought it might be the rate that it inputs at is to fast to detect. I am at a lost any help is very welcome!

도움이 되었습니까?

해결책

You need to add code to wait some period of time between key presses. Keystrokes of that speed will likely be read as 'bouncing'. See this link on debouncing

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top