python 获取鼠标全局动作

2017-10-29  本文已影响0人  zmc_94d8

import struct

file = open( "/dev/input/mice","rb" );

def getMouseEvent():

    buf= file.read(3);

    button = ord( buf[0] );

    bLeft = button & 0x1;

    bMiddle = ( button & 0x4 ) > 0;

    bRight = ( button & 0x2 ) > 0;

    x,y= struct.unpack( "bb", buf[1:] );

    print ("L:%d, M: %d, R: %d, x: %d, y: %d\n" %(bLeft,bMiddle,bRight, x, y) );

    #return stuffs

while( 1 ):

getMouseEvent();

file.close();

上一篇 下一篇

猜你喜欢

热点阅读