您的位置:首页 > 编程语言 > Python开发

菜鸟学Python(8):功能键的读取

2007-04-05 21:22 399 查看
我知道怎么读取功能键了。先getch一下得到a,如果等于0或者224,就说明是功能键,再getch下一个得到b,那么这个功能键的扫描码就是a+(b*256) 。
可以看看下面这个例子:


import msvcrt


while 1:


if msvcrt.kbhit(): # Key pressed?


a = ord(msvcrt.getch()) # get first byte of keyscan code


if a == 0 or a == 224: # is it a function key?


b = ord(msvcrt.getch()) # get next byte of key scan code


x = a + (b*256) # cook it.


return x # return cooked scancode


else:


return a # else return ascii code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: