Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added check if the device is a keyboard #327

Merged
merged 1 commit into from
Dec 25, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions scripts/Reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,31 @@
import os.path
import sys

from evdev import InputDevice, categorize, ecodes, list_devices
from evdev import InputDevice, categorize, ecodes, list_devices, ecodes
MiczFlor marked this conversation as resolved.
Show resolved Hide resolved
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:
with open(path + '/deviceName.txt','r') as f:
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:
Expand Down