From 6e7ec83c52b1470aa40d6ac1e66c0e472bf1b153 Mon Sep 17 00:00:00 2001 From: cgnmause Date: Sun, 11 Nov 2018 09:06:41 -0100 Subject: [PATCH] Added check if the device is a keyboard --- scripts/Reader.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/scripts/Reader.py b/scripts/Reader.py index 9c49e6a61..80a82ea18 100644 --- a/scripts/Reader.py +++ b/scripts/Reader.py @@ -5,12 +5,23 @@ import os.path import sys -from evdev import InputDevice, categorize, ecodes, list_devices +from evdev import InputDevice, categorize, ecodes, list_devices, ecodes from select import select class Reader: + + def is_Keyboard(self, device): + device_key_list = device.capabilities()[ecodes.EV_KEY] + + if self.mandatory_keys.issubset(device_key_list) and self.reserved_key.isdisjoint(device_key_list): + return True + else: + return False + def __init__(self): path = os.path.dirname(os.path.realpath(__file__)) self.keys = "X^1234567890XXXXqwertzuiopXXXXasdfghjklXXXXXyxcvbnmXXXXXXXXXXXXXXXXXXXXXXX" + self.mandatory_keys = {i for i in range(ecodes.KEY_ESC, ecodes.KEY_D)} + self.reserved_key = {0} if not os.path.isfile(path + '/deviceName.txt'): sys.exit('Please run RegisterDevice.py first') else: @@ -18,7 +29,7 @@ def __init__(self): deviceName = f.read() devices = [InputDevice(fn) for fn in list_devices()] for device in devices: - if device.name == deviceName: + if device.name == deviceName and self.is_Keyboard(device): self.dev = device break try: