Use constants for mouse and keyboard device names

This commit is contained in:
RunasSudo 2019-11-18 14:55:57 +11:00
parent 2899bba549
commit 50dd3f3c0e
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A

View File

@ -20,6 +20,9 @@ MOUSEHOLD_Y = 728//2
MOUSEHOLD_W = 0
MOUSEHOLD_H = 0
DEVICE_MOUSE = 'Logitech USB Optical Mouse'
DEVICE_KEYBOARD = 'AT Translated Set 2 keyboard'
import asyncio
import re
import subprocess
@ -57,7 +60,7 @@ async def mouseinp():
# Get mouse device
p = await asyncio.create_subprocess_exec('xinput', 'list', stdout=subprocess.PIPE)
stdout, _ = await p.communicate()
device = re.search('Logitech USB Optical Mouse.*?id=([0-9]+)', stdout.decode('utf-8')).group(1)
device = re.search(DEVICE_MOUSE + '.*?id=([0-9]+)', stdout.decode('utf-8')).group(1)
print('Mouse device {}'.format(device), file=sys.stderr)
p_test = await asyncio.create_subprocess_exec('xinput', 'test', device, stdout=subprocess.PIPE)
@ -78,7 +81,7 @@ async def keyboardinp():
# Get keyboard device
p = await asyncio.create_subprocess_exec('xinput', 'list', stdout=subprocess.PIPE)
stdout, _ = await p.communicate()
device = re.search('AT Translated Set 2 keyboard.*?id=([0-9]+)', stdout.decode('utf-8')).group(1)
device = re.search(DEVICE_KEYBOARD + '.*?id=([0-9]+)', stdout.decode('utf-8')).group(1)
print('Keyboard device {}'.format(device), file=sys.stderr)
p_test = await asyncio.create_subprocess_exec('xinput', 'test', device, stdout=subprocess.PIPE)