Simulate keyboard key press in Python to play games on Linux?

432 Views Asked by At

I'd like to simulate keyboard events, mainly WASD from Python to control games on Linux.

So far, I've tried PyKey and Keyboard module but unfortunately, they are unable to simulate the keypress in a way that games detect it as continuous movement and so most games just don't work with these.

Are there any alternatives to these modules? Is there something like DirectInput for Linux?

1

There are 1 best solutions below

0
On

You could look into pyautogui and achieve your task with the following sample command: pyautogui.press('w')

I have not tried it for games specifically, but it may work!