2016-07-07 13:43:31 -04:00
|
|
|
#!/bin/python
|
|
|
|
|
2016-07-07 15:40:10 -04:00
|
|
|
import evdev
|
|
|
|
from evdev import InputDevice
|
|
|
|
from select import select
|
|
|
|
|
2016-07-07 13:43:31 -04:00
|
|
|
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}
|
|
|
|
for dev in self.devices.values(): print(dev)
|
|
|
|
|
2016-07-08 05:24:34 -04:00
|
|
|
def getKeyPressed(self, environment):
|
2016-07-07 15:40:10 -04:00
|
|
|
r, w, x = select(self.devices, [], [])
|
2016-07-08 12:33:32 -04:00
|
|
|
currShortcut = environment['input']['currShortcut']
|
2016-07-07 15:40:10 -04:00
|
|
|
for fd in r:
|
|
|
|
for event in self.devices[fd].read():
|
|
|
|
if event.type == evdev.ecodes.EV_KEY:
|
2016-07-08 12:33:32 -04:00
|
|
|
if event.value != 0:
|
|
|
|
currShortcut[str(event.code)] = event.value
|
|
|
|
else:
|
|
|
|
del(currShortcut[str(event.code)])
|
|
|
|
environment['input']['currShortcut'] = currShortcut
|
|
|
|
environment['input']['currShortcutString'] = self.getShortcutString(environment)
|
2016-07-08 05:24:34 -04:00
|
|
|
return environment
|
2016-07-08 12:33:32 -04:00
|
|
|
|
|
|
|
def getShortcutString(self, environment):
|
|
|
|
if environment['input']['currShortcut'] == {}:
|
|
|
|
return ''
|
|
|
|
currShortcutStringList = []
|
|
|
|
for key in sorted(environment['input']['currShortcut'] ):
|
|
|
|
currShortcutStringList.append("%s-%s" % (environment['input']['currShortcut'][key], key))
|
|
|
|
return str(currShortcutStringList)[1:-1].replace(" ","").replace("'","")
|