fenrir/src/fenrir-package/core/inputManager.py

44 lines
1.7 KiB
Python
Raw Normal View History

#!/bin/python
2016-07-07 15:40:10 -04:00
import evdev
from evdev import InputDevice
from select import select
class inputManager():
def __init__(self):
2016-07-07 15:40:10 -04:00
self.devices = map(evdev.InputDevice, (evdev.list_devices()))
self.devices = {dev.fd: dev for dev in self.devices}
2016-07-08 20:48:22 -04:00
#for dev in self.devices.values(): print(dev)
2016-07-07 15:40:10 -04:00
2016-07-08 05:24:34 -04:00
def getKeyPressed(self, environment):
2016-07-16 18:56:18 -04:00
timeout = True
2016-07-13 15:40:19 -04:00
try:
r, w, x = select(self.devices, [], [],0.4)
2016-07-14 17:00:02 -04:00
environment['runtime']['globalLock'].acquire(True)
2016-07-13 15:40:19 -04:00
if r != []:
2016-07-16 18:56:18 -04:00
timeout = False
2016-07-13 15:40:19 -04:00
for fd in r:
for event in self.devices[fd].read():
if event.type == evdev.ecodes.EV_KEY:
if event.value != 0:
2016-07-25 18:06:18 -04:00
environment['input']['currShortcut'][str(event.code)] = 1 #event.value
2016-07-13 15:40:19 -04:00
else:
try:
2016-07-14 17:25:33 -04:00
del(environment['input']['currShortcut'][str(event.code)])
2016-07-13 15:40:19 -04:00
except:
pass
except:
pass
2016-07-08 12:33:32 -04:00
environment['input']['currShortcutString'] = self.getShortcutString(environment)
2016-07-16 18:56:18 -04:00
return environment, timeout
2016-07-08 12:33:32 -04:00
def getShortcutString(self, environment):
if environment['input']['currShortcut'] == {}:
return ''
currShortcutStringList = []
2016-07-10 12:34:44 -04:00
for key in environment['input']['currShortcut']:
2016-07-08 12:33:32 -04:00
currShortcutStringList.append("%s-%s" % (environment['input']['currShortcut'][key], key))
2016-07-10 12:34:44 -04:00
currShortcutStringList = sorted(currShortcutStringList)
2016-07-08 12:33:32 -04:00
return str(currShortcutStringList)[1:-1].replace(" ","").replace("'","")
2016-07-10 12:34:44 -04:00