|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
想编个程式,但是需要侦测鼠标和键盘是否有点击。(系统是Linux--debian),在網上找到如下代碼:
鼠标设备文件是『/dev/input/mice』,读3个字节,三个字节的值分别是『Button类型』,『X的相对位移』,『Y的相对位移』。取Button的低3位(Button & 0x07)。 0x01 -> LeftButtonDown, 0x02 -> RightButtonDown.
import struct
mou = open( "/dev/input/mice", "rb" );
def m_event():
m = mou.read(3)
b = ord( m[0] )
bl = b & 0x1
bm = ( b & 0x4 ) > 0
br = ( b & 0x2 ) > 0
x,y = struct.unpack( "bb", m[1:] )
print "Left:%d, Middle: %d, Right: %d, x: %d, y: %d\n" % (bl,bm,br, x, y)
while( 1 ):
m_event()
mou.close();
上面的程式在debian上執行有點問題,因為debian的 /dev/input/ 下沒有mice。取而代之的是event0,event1,***event4。將/input/mice---->改為/input/enent2 后,發現程式可以在鼠標點擊時打印東西。但沒辦法找出規律。應該是debian和其它LINUX 不同造成的。有沒有大神可以告訴我,event2是否存储着鼠标的输入?代表button点击类型的是哪几个字节?程式怎么改才能侦测鼠标左、右键点击 ?键盘呢,如何侦测? |
|