Question

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!

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top