initial but unfinished key consumation

This commit is contained in:
chrys
2016-08-11 14:37:46 +02:00
parent 205222c99e
commit b4f01f76f0
8 changed files with 192 additions and 36 deletions

View File

@ -1,41 +0,0 @@
#!/bin/python
import evdev
from evdev import InputDevice, UInput
from select import select
import time
iDevices = map(evdev.InputDevice, (evdev.list_devices()))
iDevices = {dev.fd: dev for dev in iDevices if dev.fn in ['/dev/input/event18']}
uDevices = {}
for fd in iDevices:
dev = iDevices[fd]
dev.capabilities()
uDevices[fd] = UInput()
dev.grab()
# dev.capabilities(),
# dev.name,
# dev.info.vendor,
# dev.info.product,
# dev.version,
# dev.info.bustype,
# '/dev/uinput'
# )
i = 0
while i < 10:
r, w, x = select(iDevices, [], [])
if r != []:
i += 1
for fd in r:
for event in iDevices[fd].read():
if event.code != 30:
uDevices[fd].write_event(event)
uDevices[fd].syn()
#print('Devicename:'+ devices[fd].name + ' Devicepath:' + devices[fd].fn + ' Events:' + str(devices[fd].active_keys(verbose=True)) + ' Value:' + str(event.value))
for fd in iDevices:
iDevices[fd].ungrab()

View File

@ -2,4 +2,5 @@
generalInformation = {
'running': True,
'consumeKey': False,
}

View File

@ -1,35 +1,43 @@
#!/bin/python
import evdev
from evdev import InputDevice
from evdev import InputDevice, UInput
from select import select
import time
class inputManager():
def __init__(self):
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)
self.iDevices = {}
self.uDevices = {}
self.getDevices()
def getKeyPressed(self, environment):
timeout = True
try:
r, w, x = select(self.devices, [], [], environment['runtime']['settingsManager'].getSettingAsFloat(environment, 'screen', 'screenUpdateDelay'))
environment['runtime']['globalLock'].acquire(True)
r, w, x = select(self.iDevices, [], [], environment['runtime']['settingsManager'].getSettingAsFloat(environment, 'screen', 'screenUpdateDelay'))
if r != []:
timeout = False
for fd in r:
for event in self.devices[fd].read():
if event.type == evdev.ecodes.EV_KEY:
if event.value != 0:
environment['input']['currShortcut'][str(event.code)] = 1 #event.value
else:
try:
del(environment['input']['currShortcut'][str(event.code)])
except:
pass
except:
pass
for event in self.iDevices[fd].read():
if event.code == 82: # a
environment['generalInformation']['consumeKey'] = True
if not environment['generalInformation']['consumeKey']:
self.uDevices[fd].write_event(event)
self.uDevices[fd].syn()
time.sleep(0.01)
else:
if event.type == evdev.ecodes.EV_KEY:
if event.value != 0:
environment['input']['currShortcut'][str(event.code)] = 1 #event.value
else:
try:
del(environment['input']['currShortcut'][str(event.code)])
except:
pass
except Exception as e:
self.freeDevices()
environment['input']['currShortcutString'] = self.getShortcutString(environment)
environment['generalInformation']['consumeKey'] = environment['input']['currShortcut'] != {}
return environment, timeout
def getShortcutString(self, environment):
@ -40,4 +48,46 @@ class inputManager():
currShortcutStringList.append("%s-%s" % (environment['input']['currShortcut'][key], key))
currShortcutStringList = sorted(currShortcutStringList)
return str(currShortcutStringList)[1:-1].replace(" ","").replace("'","")
def getDevices(self):
self.iDevices = map(evdev.InputDevice, (evdev.list_devices()))
self.iDevices = {dev.fd: dev for dev in self.iDevices if 1 in dev.capabilities()}
for fd in self.iDevices:
dev = self.iDevices[fd]
cap = dev.capabilities()
del cap[0]
print(dev.name)
self.uDevices[fd] = UInput(
cap,
dev.name,
dev.info.vendor
# dev.info.product,
# dev.version,
# dev.info.bustype,
# '/dev/uinput'
)
dev.grab()
def freeDevices(self):
for fd in self.iDevices:
try:
self.iDevices[fd].ungrab()
except:
pass
try:
self.iDevices[fd].close()
except:
pass
try:
self.uDevices[fd].close()
except:
pass
self.iDevices.clear()
self.uDevices.clear()
def __del__(self):
self.freeDevices()

View File

@ -37,14 +37,11 @@ class fenrir():
self.environment = self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onScreenChanged')
if self.environment['commandInfo']['currCommand'] != '':
self.handleCommands()
self.environment['runtime']['globalLock'].release()
def updateScreen(self):
return
self.environment['runtime']['globalLock'].acquire(True)
self.environment = self.environment['runtime']['screenDriver'].analyzeScreen(self.environment,'updateScreen')
self.environment = self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onScreenChanged')
self.environment['runtime']['globalLock'].release()
time.sleep(0.5)
def handleCommands(self):
@ -61,6 +58,8 @@ class fenrir():
self.environment['runtime']['soundDriver'].shutdown()
if self.environment['runtime']['speechDriver'] != None:
self.environment['runtime']['speechDriver'].shutdown()
self.environment['runtime']['inputManager'].freeDevices()
def captureSignal(self, siginit, frame):
self.shutdownRequest()