是否有使用msvcrt时哪些数字表示哪些字符的列表?

时间:2017-04-06 16:29:19

标签: python msvcrt

我确定那里有几个,但我不确定我是否正确写字,所以我找不到任何东西。如果我说错了,这就是我的意思:

while 1:
    char = msvcrt.getch()
    if char == chr(27):
        break

这是针对特定按键的测试(例如,如果我没有记错的话),但是说我想测试空格键,那将是多少?或者,理想情况下,有一个列表供我参考吗?

1 个答案:

答案 0 :(得分:0)

Well, I understand your situation. It's really annoying when this happens. There are several approaches. One of them, which is my favourite, is to create a very tiny program with 4 lines of code that tells you the number of any key. All what you have to do is create a new program and paste the following in:

import msvcrt
while True:
   key = msvcrt.getch()
   key = ord(key)
   print(key)

What this does is it waits for you to press any key and then prints out the number of it. If you wanted a list on the internet or something im afraid i couldn't find anything, however this will work.

Also, make sure you save this code on your desktop and run it by double clicking on it. Espescially if you have windows( don't know why but it doesn't work on the interpreter.) I hope it helps! Please comment for any problems below.