Skip to content

Instantly share code, notes, and snippets.

@namakemono22
Last active February 2, 2024 05:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save namakemono22/6f6eef0a047c9632b872e07278cd9d47 to your computer and use it in GitHub Desktop.
Save namakemono22/6f6eef0a047c9632b872e07278cd9d47 to your computer and use it in GitHub Desktop.
python キーボード検知
import keyboard
while True:
if keyboard.is_pressed("q"): #qが押されたらTrue
break
if keyboard.read_key() == "p": #上記と一緒
break
対応キー(合ってないかも)
'a''b''c'…
'escape': 'esc',
'return': 'enter',
'del': 'delete',
'control': 'ctrl',
'left arrow': 'left',
'up arrow': 'up',
'down arrow': 'down',
'right arrow': 'right',
' ': 'space', # Prefer to spell out keys that would be hard to read.
'\x1b': 'esc',
'\x08': 'backspace',
'\n': 'enter',
'\t': 'tab',
'\r': 'enter',
'scrlk': 'scroll lock',
'prtscn': 'print screen',
'prnt scrn': 'print screen',
'snapshot': 'print screen',
'ins': 'insert',
'pause break': 'pause',
'ctrll lock': 'caps lock',
'capslock': 'caps lock',
'number lock': 'num lock',
'numlock': 'num lock',
'space bar': 'space',
'spacebar': 'space',
'linefeed': 'enter',
'win': 'windows',
# Mac keys
'command': 'windows',
'cmd': 'windows',
'control': 'ctrl',
'option': 'alt',
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment