Long story short: I have a keyboard with a touchpad which is recognized as a "pointer" on xinput, and has "keyboard pointer" capabilities in libinput (in opposition to being recognized as a touchpad). The libinput property "Disable-w-typing" is not avaliabe (it has "n/a" as the value on "libinput list-devices"). Also Ubuntu doesn't recognize it as a touchpad, so I can't use the Ubuntu embedded solution for disabling the touchpad while typing.
Reading through lots of related questions here and elsewhere, I've managed to adapt this python script to my problem. Here's my version of it:
import os import time import subprocess import threading def main(): touch = os.popen("xinput list --id-only 'pointer:SINO WEALTH USB KEYBOARD'").read()[:-1] keyboard = os.popen("xinput list --id-only 'keyboard:SINO WEALTH USB KEYBOARD'").read()[:-1] subprocess.call('xinput set-prop '+touch+' 142 1', shell=True) p = subprocess.Popen('xinput test '+keyboard, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) clickTime = [0, 0] def checkTime(): keys = [37, 50, 62, 64, 105, 108, 133] while True: out = p.stdout.readline() if len(out) < 1: break key = int(out.split()[-1]) if key not in keys: clickTime = time.time() t = threading.Thread(target=checkTime) t.start() lastTime = 0 touchpad = True while True: inactive = time.time() - clickTime # print ('inactive for', inactive) if inactive > 1: if not touchpad: print ('Enable touchpad') subprocess.call('xinput set-prop '+touch+' 142 1', shell=True) touchpad = True else: if touchpad: print ('Disable touchpad') subprocess.call('xinput set-prop '+touch+' 142 0', shell=True) touchpad = False time.sleep(0.5) retval = p.wait() if __name__ == '__main__': main()
The script works just fine. As soon as I start typing the touchpad is disabled. The only problem is that it takes about 1s for the touchpad to get enabled back, which is kinda long, and I haven't found no way to make this delay smaller. Setting "time.sleep(0.5)" to a smaller number seems like an obvious choice, but setting it to 0.05 for example, only seems to make the script more cpu-hungry, but it makes no visible change on the delay between me stop typing and the touchpad getting reactivated.
My goal precisely is to able to deactivate the touchpad while typing and get the touchpad activated back around 300ms after I stop typing.
I don't need to solve this problem using python necessarily, but that's the only way I was able to address it on the first place. As answers, I can accept suggestions for changing this very python script, or maybe guidance on how to solve this with a bash script, or really any idea that guide me to solve this (thinking outside the box is welcome also).
Running Ubuntu 19.04.