What I'm trying to figure out right now is how to use a python script to record a keypress if the active window is an emulator. Every solution I've found requires the active window to be script which contains the keypress detector. Any idea on how to access system keyboard state in windows without it being the active window?
1 Answer
this solution uses the pynput library
from pynput import keyboard
def on_press(key):
try:
print('alphanumeric key {0} pressed'.format(
key.char))
except AttributeError:
print('special key {0} pressed'.format(
key))
def on_release(key):
print('{0} released'.format(
key))
if key == keyboard.Key.esc:
# Stop listener
return False
# Collect events until released
with keyboard.Listener(
on_press=on_press,
on_release=on_release) as listener:
listener.join()