Pregunta

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!

¿Fue útil?

Solución

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top