0

Specifically, I am creating a Python 3.4 program that runs entirely in the terminal. Is there a cross platform way to detect if a specific key is down? I can do it on Windows using the win32 function getAsyncKeyState(), but don't have a way to test keys on OSX or Linux.

I know about getch(), but that doesn't let me test for some keys (such as shift) and waits for key repetition.

fuzzything44
  • 701
  • 4
  • 15
  • Possible duplicate of [What's the simplest way of detecting keyboard input in python from the terminal?](http://stackoverflow.com/questions/13207678/whats-the-simplest-way-of-detecting-keyboard-input-in-python-from-the-terminal) – Neil Locketz Sep 22 '16 at 20:47

1 Answers1

-1

If you start up a tkinter window and hide it bind keypresses?

from tkinter import *

root = Tk()
root.bind("<Control-e>", exit)
root.mainloop()
root.withdraw()

while True:
    name = input("What's Your Name? ")
    print(name)

This will hide the window once it is made checking for Ctrl+E keypresses and when it gets one it exits the program.

Hope This Helps :)