Use constants for mouse and keyboard device names
This commit is contained in:
parent
2899bba549
commit
50dd3f3c0e
@ -20,6 +20,9 @@ MOUSEHOLD_Y = 728//2
|
|||||||
MOUSEHOLD_W = 0
|
MOUSEHOLD_W = 0
|
||||||
MOUSEHOLD_H = 0
|
MOUSEHOLD_H = 0
|
||||||
|
|
||||||
|
DEVICE_MOUSE = 'Logitech USB Optical Mouse'
|
||||||
|
DEVICE_KEYBOARD = 'AT Translated Set 2 keyboard'
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
@ -57,7 +60,7 @@ async def mouseinp():
|
|||||||
# Get mouse device
|
# Get mouse device
|
||||||
p = await asyncio.create_subprocess_exec('xinput', 'list', stdout=subprocess.PIPE)
|
p = await asyncio.create_subprocess_exec('xinput', 'list', stdout=subprocess.PIPE)
|
||||||
stdout, _ = await p.communicate()
|
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)
|
print('Mouse device {}'.format(device), file=sys.stderr)
|
||||||
|
|
||||||
p_test = await asyncio.create_subprocess_exec('xinput', 'test', device, stdout=subprocess.PIPE)
|
p_test = await asyncio.create_subprocess_exec('xinput', 'test', device, stdout=subprocess.PIPE)
|
||||||
@ -78,7 +81,7 @@ async def keyboardinp():
|
|||||||
# Get keyboard device
|
# Get keyboard device
|
||||||
p = await asyncio.create_subprocess_exec('xinput', 'list', stdout=subprocess.PIPE)
|
p = await asyncio.create_subprocess_exec('xinput', 'list', stdout=subprocess.PIPE)
|
||||||
stdout, _ = await p.communicate()
|
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)
|
print('Keyboard device {}'.format(device), file=sys.stderr)
|
||||||
|
|
||||||
p_test = await asyncio.create_subprocess_exec('xinput', 'test', device, stdout=subprocess.PIPE)
|
p_test = await asyncio.create_subprocess_exec('xinput', 'test', device, stdout=subprocess.PIPE)
|
||||||
|
Reference in New Issue
Block a user