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 :

我知道Linux从/dev/input/mice中给出了9-bit 2的赞美数据。我也知道你可以通过/dev/hidraw0获得数据,hidraw是你的USB设备,可以从隐藏的数据中提取原始数据。我知道发送的数据是移动的delta(位移)而不是位置。我还可以通过“cat /dev/input/mice”来查看gibberish数据。我的问题是:

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.)

你能告诉我用Python语言怎么读这些数据吗?我更喜欢把数据写成简单的整数。但事实证明这是困难的。真正的问题是读取该死的数据。是否有办法读取比特并进行比特运算?(目前我并不担心根用户相关的问题。请假定脚本是在root中运行的。

(My main reference was http://www.computer-engineering.org/ps2mouse/)

(我的主要参考资料是http://www.computer engineer.org/ps2mouse/)

3 个解决方案

#1


11

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

我在一个基本设备上,无法访问X或…所以事件。py不工作。

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

这是我简单的解码代码部分,用来解释“弃用”/dev/输入/鼠标:

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

更多相关文章

  1. DELPHI10.2的LINUX数据库开发环境配置
  2. 远程连接腾讯云MySQL数据库
  3. Linux网络设备驱动架構學習(三)
  4. thinkphp连接mysql数据库查询数据显示
  5. Linux系统Oracle12.2 RAC集群实施维护_Oracle数据库12cR2(项目实
  6. Linux设备驱动剖析之Input(三)
  7. 保护SD卡Raspberry Pi上的数据
  8. Linux内核数据结构之链表
  9. 对linux字符设备的理解(整体架构)

随机推荐

  1. php中什么是魔术引号
  2. php如何设置日期
  3. php之日期时间操作一箩筐
  4. wampserver怎么下载
  5. PHP如何实现短网址
  6. php适合做微服务么
  7. php array_chunk函数怎么用
  8. php技术栈是什么
  9. php中的array_fill函数怎么用
  10. php怎么做页面静态化