Найти - Пользователи
Полная версия: Python и USB-мышь в Linux
Начало » Python для экспертов » Python и USB-мышь в Linux
1 2
well
Извините, что так долго молчал - уезжал по-делам. Вот как я сделал:
import os
f = os.popen('/usr/bin/hexdump /dev/input/mice', 'rb', 1)
data  = f.read(512)
while(data):
        print data,
        data  =  f.read(512)
Но данные выдаются только когда буфер заполняется. Как мне сделать, чтобы буфер был равен 1 символу?

Да еще и hexdump почему-то каждый раз разные данные дает :(
well
Все решилось на много проще:
#!/usr/bin/python
f = file("/dev/input/mice")
l, r = 0, 0
while 1:
        buttons = ord(f.read(3)[0])
        nl, nr = buttons&1, buttons&2
        if l and not nl:
                print "left release"
        if r and not nr:
                print "right release"
        l, r = nl, nr
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB