Answer the question
In order to leave comments, you need to log in
How to receive events simultaneously from several devices?
Good afternoon!
Preamble: I bought a trackball that does not have a scroll wheel, but this is perhaps its only drawback. Through xorg.conf, you can configure it so that, while holding one of the buttons, scroll with the ball. But, as luck would have it, the button I needed (the most convenient) did not fit for this.
I am writing a small Python script (under ubuntu), which, analyzing the flow of events from input devices, sends messages to the system as if I am scrolling when certain conditions occur.
Well, for example, "if I drove very slowly for 0.5 seconds (delta_x and delta_y no more than 1-2), then scroll further until I move the ball strongly", or "if the left mouse button was pressed for at least 0.5 seconds, and the ball did not moved, then scroll until I pull the ball"
There are some good results, but still something is not right.
I want to experiment with the keyboard. I suspect that it will be much more convenient if you hold down some key that is not particularly needed in Linux (for example, win), and at the same time emulate scrolling through ball movements.
This is how I listen to the device:
from evdev.device import InputDevice
input_device = InputDevice('/dev/input/event12')
for event in input_device.read_loop():
# обрабатываем поступающие события
pass
input_device = InputDevice('/dev/input/event12')
input_device2 = InputDevice('/dev/input/event3')
for event in itertools.chain(input_device.read_loop(), input_device2.read_loop()):
# сюда попадают события только от того генератора, что указан первым
pass
Answer the question
In order to leave comments, you need to log in
itertools.izip concatenates two iterators the way you want, but that's probably not what you want, since events from different device files can occur at different rates. Look towards select is better.
UPDATE: even an example is available at python-evdev.readthedocs.org/en/latest/tutorial.ht...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question