I'm trying to build an AI for an NES game using a python script to interact with an emulator. I couldn't really find an API for said emulator (Mesen) so I decided to use OpenCV to look at the screen and somehow simulate keyboard presses to give inputs to the game. However, the two keyboard libraries I found (keyboard and pynput) and the Windows 32 API don't seem to be able to give inputs to the emulator. Text editors can detect the keys pressed using these libraries but the emulator seems to just ignore it. I have tried it with a different GBA emulator (Visual Boy Advance) and that can't detect the keyboard presses either.
For anyone else who stumbles by this and is having the same problem (I am also using the mesen emulator). Use the pydirectinput library.
import pyautogui
import pydirectinput
pydirectinput.press("s")