我现在要弄清楚的是如果活动窗口是模拟器,如何使用python脚本来记录按键。我发现的每个解决方案都要求活动窗口是包含按键检测器的脚本。有关如何在Windows中访问系统键盘状态而不是活动窗口的任何想法吗?
答案 0 :(得分:0)
此解决方案使用pynput
库
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()