boppreh / keyboard

Hook and simulate global keyboard events on Windows and Linux.
MIT License
3.77k stars 432 forks source link

Keyboard press and release not registered by running application #546

Open emma-makes opened 2 years ago

emma-makes commented 2 years ago

I'm writing a bot which plays classic GameBoy games using lr-gambatte. I'm currently exploring options to control the game using a python bot, which sends the keystrokes to the game. The target is a Raspberry Pi Zero running Retropie/EmulationStation/Retroarch/gambatte.

I have the following proof of concept code, which works fine in the TTY displayed on the Pi's screen. Once I open EmulationStation or lr-gambatte, the key presses are not registered. I've had similar results with uinput (https://pypi.org/project/python-uinput/, which seems to be abandoned). With uinput, keystrokes were registered in the EmulationStation GUI, but not in the running game in gambatte.

import keyboard

keyboard.press_and_release('a')
keyboard.press_and_release('left')
keyboard.press_and_release('down')
keyboard.press_and_release('right')
keyboard.press_and_release('up')
keyboard.press_and_release('a')

I understand if you don't see this as an issue your project, but was wondering if you have an idea, what could be causing this or how it could be addressed.

ItsJustAGitHubMichealWhosGonnaSeeIt5Ppl commented 6 months ago

Did you ever resolve this? I cannot get any of the keyboard/keypress python modules to work