Проблема в том, что мне нужно захватить события прокрутки колесика мыши (вверх или вниз) и уменьшить его, как со 100 отсчетов прокрутки до 1 (не так уж точно).Все это в Python 2.7 на Raspberry Pi 3. Другие события затем прокрутки необходимо продолжить.Моя идея состояла в том, чтобы повторно отправить все события с помощью функции write () .Для этого я использую evdev .
Пока что работает прокрутка.Я не могу найти способ только остановить события прокрутки и продолжить другие события мыши.С помощью dev.grab () все события останавливаются, и кажется, что это блокирует функцию dev.write ().
Есть предложения, как достичь этой цели?
Код на данный момент:
import evdev
from evdev import UInput, AbsInfo, InputDevice, categorize, ecodes
from pprint import pprint
import sys
import time
#get the mouse and use it in dev
devices = [evdev.InputDevice(path) for path in evdev.list_devices()]
foundMouse = None
for device in devices:
if "mouse" in device.name.lower():
foundMouse = device
print("Mouse found, using: ", device.path, device.name, device.phys)
break
if foundMouse is None:
print("No mouse found, exiting...")
sys.exit()
dev = InputDevice(device.path)
#pprint(dev.capabilities(verbose=True, absinfo=True))
#i guess these are not working because of the dev.grab()
#simulatedUserInput = UInput(dev.capabilities(), name='simulated-device', version=0x3)
simulatedUserInput = UInput()
#i guess this will block the dev.write(), bud it's not clear from the documentation
dev.grab()
scrollUps = 0
scrollDowns = 0
startingTime = time.time()
amountOfScrollsToReactOn = 10 #will be 100 or so, bud for testing just 10
for event in dev.read_loop():
#catch the scroll wheel
if event.type == evdev.ecodes.EV_REL and event.code == evdev.ecodes.REL_WHEEL:
#if event.type == 0x02 and event.code == 0x08:
currentTime = time.time()
#print((currentTime - startingTime))
if event.value > 0:
scrollUps+=1
scrollDowns = 0
elif event.value < 0:
scrollDowns+=1
scrollUps = 0
if (currentTime - startingTime) > 10:
startingTime = time.time()
scrollUps = 0
scrollDowns = 0
#if scrolled x amount of times in 10 seconds
elif (currentTime - startingTime) < 10 and (scrollUps > amountOfScrollsToReactOn or scrollDowns > amountOfScrollsToReactOn):
if scrollUps > amountOfScrollsToReactOn:
print("UP")
elif scrollDowns > amountOfScrollsToReactOn:
print("DOWN")
startingTime = time.time()
scrollDowns = 0
scrollUps = 0
#pprint(str(event.type) + " " + str(event.code) + " " + str(event.value))
#print(categorize(event))
else:
#pprint("sending: " + str(event.type) + " " + str(event.code) + " " + str(event.value))
#both below are not doing anything
#here the point is to reroute the other events then scrolling, bud any other way to archive this would be the solution
#dev.write(e.EV_KEY, e.KEY_A, 0)
simulatedUserInput.write(event.type, event.code, event.value)
simulatedUserInput.syn()