0

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

1 Answer 1

0

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()
Sign up to request clarification or add additional context in comments.

1 Comment

This works exactly how I wanted it to, thank you so much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.