简体   繁体   English

快捷方式脚本中的 EOFError:(原始)Python 中的键盘输入

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

My first Python script should be a Keyboard-Shortcut-Quiz:我的第一个 Python 脚本应该是键盘快捷方式测验:

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".由于许多键盘快捷键只能与 CTRL、SHIFT 或 WIN/OS 键结合使用,因此测验的大多数“答案”将包含这些“系统键”中的一个。

Unfortunately this System Keys are leading to "EOFError: EOF when reading a line".不幸的是,这个系统键会导致“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.我用['D']而不是['^D']对其进行了测试,并且脚本运行良好。 Its clear that the ^ which stands for CTRL is the reason for the error.很明显,代表 CTRL 的^是错误的原因。

Now I am asking myself on how to read RAW keyboard shortcuts combinations properly in python.现在我问自己如何在 python 中正确读取 RAW 键盘快捷键组合。 (I know that raw_input is just input now with Python 3.) (我知道raw_input现在只是用 Python 3 input 。)

PS: I didnt came across a solution on how to read the input of the WIN Key properly, is this even possible? PS:我没有遇到关于如何正确读取WIN键输入的解决方案,这甚至可能吗?

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 ).使用您正在使用的方法,除非您使用 AHK( AutoHotKey ),否则您无法获取 ctrl 的输入并将其解析为 python 可读。 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.我强烈建议您尝试一下,它接受诸如“ctrl”之类的输入,并且您可以按照您需要的方式“将它混合在一起”。 I'm sorry I couldn't offer much more than this, but it seems like the most viable alternative!很抱歉,我不能提供比这更多的东西,但这似乎是最可行的选择!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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