How to read wheel scroll information with / dev / input / mice?

For a home robotics project, I need to read information about raw mouse movement. I partially succeeded with this using the python script from this SO answer . It basically reads / dev / input / mice and converts the hexadecimal input to integers:

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) ) while True: getMouseEvent() file.close() 

This works great, except that there is no information on the wheelset. Does anyone know how I can get (preferably with python) scroll wheel information from / dev / input / mice?

[EDIT] Well, although I was unable to read / dev / input / mice, I think I found a solution. I just found the evdev module (sudo pip install evdev) with which you can read input events. Now I have the following code:

 from evdev import InputDevice from select import select dev = InputDevice('/dev/input/event3') # This can be any other event number. On my Raspi it turned out to be event0 while True: r,w,x = select([dev], [], []) for event in dev.read(): # The event.code for a scroll wheel event is 8, so I do the following if event.code == 8: print(event.value) 

Now I'm going to check it out on my crucible and see how it works. Thanks for all the inspired guys and girls!

+4
source share
1 answer

If you have only 3 bytes per event in / dev / input / mice, this means that your mouse is configured as a PS / 2 mouse without a wheel. If you configure the mouse as an IMPS / 2 mouse, there must be a fourth byte in / dev / input / mice for each event. The last byte will contain information about the wheel.

+1
source

All Articles