2

I have a convertible laptop for which there isn't great Linux support: the desktop environment is unable to detect when the device is in tablet mode, so the keyboard and touchpad are always active, which makes tablet mode almost useless. I've solved this problem by writing a simple Python script that grabs the keyboard and mouse input devices and proxies events to the system until a specific key sequence is received. At this point, it stops proxying events until the same key sequence is seen again.

The code is effectively a slightly more complex version of this example (which reproduces the problem):

import evdev
import selectors

dev = evdev.InputDevice('/dev/input/event5')
ui = evdev.UInput.from_device(dev)
dev.grab()

selector = selectors.DefaultSelector()
selector.register(dev, selectors.EVENT_READ)

while True:
    for key, mask in selector.select(0.1):
        dev = key.fileobj

        for event in dev.read():
            cat = evdev.categorize(event)
            print(cat)
            ui.write_event(event)

/dev/input/event5 is the touchpad. The system has the following devices:

Available devices:
/dev/input/event0:      Lid Switch
/dev/input/event1:      Power Button
/dev/input/event2:      Sleep Button
/dev/input/event3:      Power Button
/dev/input/event4:      AT Translated Set 2 keyboard
/dev/input/event5:      SynPS/2 Synaptics TouchPad
/dev/input/event6:      Wacom HID 5072 Pen
/dev/input/event7:      Wacom HID 5072 Finger
/dev/input/event8:      HDA Intel PCH Mic
/dev/input/event9:      HDA Intel PCH Headphone
/dev/input/event10:     HDA Intel PCH HDMI/DP,pcm=3
/dev/input/event11:     PC Speaker
/dev/input/event12:     ThinkPad Extra Buttons
/dev/input/event13:     Integrated Camera: Integrated C
/dev/input/event14:     Video Bus

When this code runs, movements and regular click actions work just fine, but a two-fingered click, which normally acts like a right-button click, no longer works. Since this code is just taking events and re-sending them, why is this behavior different? How would I get the two-fingered click to work as expected?

larsks
  • 277,717
  • 41
  • 399
  • 399

1 Answers1

-1

I think what you need is very similar to this, altered of course to your needs

Python_Touchscreen_RightClick.py

if this doesn't work for you you can also try and use Gesture Event from python-libinput

Tch
  • 1,055
  • 5
  • 11
  • I don't think that code particularly addresses the question, which is more about why, when proxying all events from the actual input devices, I am losing funcitonality. – larsks Jan 31 '21 at 13:55
  • your first question was - why is this behavior different?, and the second - How would I get the two-fingered click to work as expected? I thought if you read the code you would answer your first question by yourself. so there you go - it is loosing functionality because you don't have a check for a two finger touch before you proxy the event – Tch Jan 31 '21 at 14:23
  • But I am not trying to *simulate* a two-finger click. I am trying to figure out *why I don't see it in the first place*. The code to which you've linked doesn't do any good unless I can tell when I receive a multi-touch guesture, which is the entire problem I'm trying to solve. – larsks Jan 31 '21 at 14:25