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')
Now I'm going to check it out on my crucible and see how it works. Thanks for all the inspired guys and girls!
source share