Skip to content

Instantly share code, notes, and snippets.

@mcprat
Created December 31, 2020 18:37
Show Gist options
  • Save mcprat/111173f85fb1ff70eb00c74d023937c6 to your computer and use it in GitHub Desktop.
Save mcprat/111173f85fb1ff70eb00c74d023937c6 to your computer and use it in GitHub Desktop.
Windows python keyboard scan code script
import msvcrt
print('Press key to output Windows keyboard scan codes (Ctrl + Break to quit): ', end='\n\n', flush=True)
while True:
key = msvcrt.getwch()
if ord(key) in (0, 224):
ext = msvcrt.getwch()
else:
ext = None
print(ord(key), end=' ', flush=True)
if ext != None:
print(ord(ext), end='', flush=True)
print('\r')
print('in hex:')
print(hex(ord(key)), end=' ', flush=True)
if ext != None:
print(hex(ord(ext)), end='\n\n', flush=True)
print('\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment