python模拟鼠标点击linux_使用Python获取鼠标增量! (在Linux中)

I know that Linux gives out a 9-bit 2's compliment data out of the /dev/input/mice. I also know that you can get that data via /dev/hidraw0 where hidraw is your USB device giving out raw data from the HID. I know the data sent is the delta of the movement (displacement) rather than position. By the by I can also view gibberish data via the "cat /dev/input/mice". My question is :

Can you please tell me by using the Python language how can I read this data? I really rather get that data as in simple integers. But it has proven hard. The real problem is reading the damn data. Is there a way to read bits and do bit arithmetic? ( Currently i'm not worrying over root user related issues. Please assume the script is run in root.)

解决方案

I'm on a basic device and not having access to X or ... so event.py doesn't works.

So here's my simpler decode code part to interpret from "deprecated" '/dev/input/mice':

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();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值