0

I'm writing voice control software for disabled people helpful in playing games. I don't know how to manage to hold keyboard keys and mouse buttons in Python, but working in games. So I could, for example, make voice command to move forward in meaning of holding W key. I can spam key presses, it works in some games but in most cases it doesn't. I have been trying different modules but none of seems to work in games. I know how to make button presses but holding keys doesn't work. Probably, I should use native Windows keyboard and mouse functions but I don't know where to start even. I will be glad for any help with the task and advices.

I have tried pynput, pyautogui, keyboard. They all let me press keys but not hold them.

Kaveen Perera
  • 414
  • 3
  • 12
ViperEx76
  • 21
  • 2

1 Answers1

0

If you know how to identify a button press (down) event, the key is pressed and held until you identify a button release event.

When a key press event is occurred, if the key release event doesn't occur within a set time period (10-20ms), it can be counted as a keypress and you can trigger the action. You can use a mix of event listeners and global variables to track keypresses and state of the actions, depending on the complexity of your application.

You can find everything you need for pynput here

See this link for keypress timing

Kaveen Perera
  • 414
  • 3
  • 12
  • Thank you for answer but I think you didn't understand what I'm trying to do. I don't want recognize key press or hold, I want simulate it. For example, user say go forward and program simulate holding W. I have tried pynput, pyautogui, keyboard modules and no one work in games. They can simulate key presses but not holding. – ViperEx76 Sep 02 '23 at 07:10