简体   繁体   中英

EOFError in Shortcut Script: (raw) Keyboad-Input in Python

My first Python script should be a Keyboard-Shortcut-Quiz:

As a lot of Keyboard Shortcuts only work in combination with CTRL, SHIFT or WIN/OS Key the most "answers" of the quiz will contain on of those "system-keys".

Unfortunately this System Keys are leading to "EOFError: EOF when reading a line".

answer = str(input("How do you switch to the Desktop?"))

if answer in ['^D']:
    print("Right!")

I tested it with ['D'] instead of ['^D'] and the script worked fine. Its clear that the ^ which stands for CTRL is the reason for the error.

Now I am asking myself on how to read RAW keyboard shortcuts combinations properly in python. (I know that raw_input is just input now with Python 3.)

PS: I didnt came across a solution on how to read the input of the WIN Key properly, is this even possible?

Using the method you're using, you can't take the input of ctrl and parse it to be readable by python unless you use AHK( AutoHotKey ). I highly recommend you try it out, it takes inputs such as 'ctrl' and you can 'mash it together' the way you need to use it. I'm sorry I couldn't offer much more than this, but it seems like the most viable alternative!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM