本文實例講述了Python功能鍵的讀取方法。分享給大家供大家參考。具體分析如下:
先getch一下得到a,如果等于0或者224,就說明是功能鍵,再getch下一個得到b,那么這個功能鍵的掃描碼就是a+(b*256) 。
可以看看下面這個例子:
1
2
3
4
5
6
7
8
9
10
|
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 |
希望本文所述對大家的Python程序設(shè)計有所幫助。