Skip to content

Instantly share code, notes, and snippets.

@rochacbruno
Created April 18, 2022 20:49
Show Gist options
  • Save rochacbruno/e652c090151754d47d7bf28005b4397d to your computer and use it in GitHub Desktop.
Save rochacbruno/e652c090151754d47d7bf28005b4397d to your computer and use it in GitHub Desktop.
curses detect key pressed python - detect each types key
import curses
import os
def main(win):
win.nodelay(True)
key = ""
win.clear()
win.addstr("Detected key:")
while True:
try:
key = win.getkey()
win.clear()
win.addstr("Detected key:")
win.addstr(str(key))
if key == os.linesep:
break
except Exception:
# No input
pass
curses.wrapper(main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment