Python功能鍵的讀取方法
更新時間:2015年05月28日 14:45:10 作者:wayne92
這篇文章主要介紹了Python功能鍵的讀取方法,涉及Python鍵盤事件的相關操作技巧,需要的朋友可以參考下
本文實例講述了Python功能鍵的讀取方法。分享給大家供大家參考。具體分析如下:
先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
希望本文所述對大家的Python程序設計有所幫助。

