implement synth

This commit is contained in:
chrys 2019-01-29 23:07:20 +01:00
parent e2ecacfb2a
commit b5c94a506d
3 changed files with 63 additions and 34 deletions

View File

@ -47,6 +47,9 @@ class inputDriver():
def removeAllDevices(self):
if not self._initialized:
return
def sendKey(self):
if not self._initialized:
return
def __del__(self):
if not self._initialized:
return

View File

@ -53,16 +53,32 @@ class inputManager():
if self.env['input']['eventBuffer'] != []:
return
if not self.noKeyPressed():
return
return
if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'):
return
return
if self.env['runtime']['screenManager'].getCurrScreenIgnored():
self.ungrabAllDevices()
else:
self.grabAllDevices()
self.executeDeviceGrab = False
def sendKeys(self, keyMacro):
pass
for e in keyMacro:
key = ''
value = 0
if len(e) != 2:
continue
if isinstance(e[0], int) and isinstance(e[1], str):
key = e[1].upper()
value = e[0]
elif isinstance(e[1], int) and isinstance(e[0], str):
key = e[0].upper()
value = e[1]
else:
continue
if key.upper() == 'SLEEP':
time.sleep(value)
else:
self.env['runtime']['inputDriver'].sendKey(key, value)
def handleInputEvent(self, eventData):
#print(eventData)
if not eventData:
@ -70,9 +86,9 @@ class inputManager():
# a hang apears.. try to fix
if self.env['input']['eventBuffer'] == []:
if self.env['input']['currInput'] != []:
self.env['input']['currInput'] = []
self.env['input']['shortcutRepeat'] = 1
self.env['input']['currInput'] = []
self.env['input']['shortcutRepeat'] = 1
self.env['input']['prevInput'] = self.env['input']['currInput'].copy()
if eventData['EventState'] == 0:
if eventData['EventName'] in self.env['input']['currInput']:
@ -81,7 +97,7 @@ class inputManager():
self.env['input']['currInput'] = sorted(self.env['input']['currInput'])
elif len(self.env['input']['currInput']) == 0:
self.env['input']['shortcutRepeat'] = 1
self.lastInputTime = time.time()
self.lastInputTime = time.time()
elif eventData['EventState'] == 1:
if not eventData['EventName'] in self.env['input']['currInput']:
self.env['input']['currInput'].append(eventData['EventName'])
@ -94,10 +110,10 @@ class inputManager():
self.env['input']['shortcutRepeat'] += 1
else:
self.env['input']['shortcutRepeat'] = 1
self.handleLedStates(eventData)
self.handleLedStates(eventData)
self.lastInputTime = time.time()
elif eventData['EventState'] == 2:
self.lastInputTime = time.time()
self.lastInputTime = time.time()
self.env['input']['oldNumLock'] = self.env['input']['newNumLock']
self.env['input']['newNumLock'] = self.env['runtime']['inputDriver'].getLedState()
@ -109,7 +125,7 @@ class inputManager():
if self.noKeyPressed():
self.env['input']['prevInput'] = []
self.handleDeviceGrab()
def handleLedStates(self, mEvent):
try:
if mEvent['EventName'] == 'KEY_NUMLOCK':
@ -173,24 +189,24 @@ class inputManager():
elif eventName == 'KEY_LEFTMETA':
eventName = 'KEY_META'
elif eventName == 'KEY_RIGHTMETA':
eventName = 'KEY_META'
eventName = 'KEY_META'
if self.isFenrirKey(eventName):
eventName = 'KEY_FENRIR'
if self.isScriptKey(eventName):
eventName = 'KEY_SCRIPT'
eventName = 'KEY_SCRIPT'
return eventName
def clearEventBuffer(self):
try:
self.env['runtime']['inputDriver'].clearEventBuffer()
except Exception as e:
pass
pass
def setLastDeepestInput(self, currentDeepestInput):
self.lastDeepestInput = currentDeepestInput
def clearLastDeepInput(self):
self.lastDeepestInput = []
def getLastInputTime(self):
return self.lastInputTime
return self.lastInputTime
def getLastDeepestInput(self):
return self.lastDeepestInput
def writeEventBuffer(self):
@ -211,7 +227,7 @@ class inputManager():
shortcut.append(self.env['input']['shortcutRepeat'])
shortcut.append(self.getLastDeepestInput())
return str(shortcut)
def getPrevShortcut(self):
shortcut = []
shortcut.append(self.env['input']['shortcutRepeat'])
@ -223,7 +239,7 @@ class inputManager():
shortcut.append(self.env['input']['shortcutRepeat'])
if inputSequence:
shortcut.append(inputSequence)
else:
else:
shortcut.append(self.env['input']['currInput'])
if len(self.env['input']['prevInput']) < len(self.env['input']['currInput']):
if self.env['input']['shortcutRepeat'] > 1 and not self.shortcutExists(str(shortcut)):
@ -231,20 +247,20 @@ class inputManager():
self.env['input']['shortcutRepeat'] = 1
shortcut.append(self.env['input']['shortcutRepeat'])
shortcut.append(self.env['input']['currInput'])
self.env['runtime']['debug'].writeDebugOut("currShortcut " + str(shortcut) ,debug.debugLevel.INFO)
self.env['runtime']['debug'].writeDebugOut("currShortcut " + str(shortcut) ,debug.debugLevel.INFO)
return str(shortcut)
def currKeyIsModifier(self):
if len(self.getLastDeepestInput()) != 1:
return False
return (self.env['input']['currInput'][0] =='KEY_FENRIR') or (self.env['input']['currInput'][0] == 'KEY_SCRIPT')
def isFenrirKey(self, eventName):
return eventName in self.env['input']['fenrirKey']
def isScriptKey(self, eventName):
return eventName in self.env['input']['scriptKey']
def getCommandForShortcut(self, shortcut):
if not self.shortcutExists(shortcut):
return ''
@ -261,7 +277,7 @@ class inputManager():
break
line = line.replace('\n','')
if line.replace(" ","") == '':
continue
continue
if line.replace(" ","").startswith("#"):
continue
if line.count("=") != 1:
@ -289,12 +305,12 @@ class inputManager():
shortcut.append(shortcutRepeat)
shortcut.append(sorted(shortcutKeys))
if len(shortcutKeys) != 1 and not 'KEY_FENRIR' in shortcutKeys:
self.env['runtime']['debug'].writeDebugOut("invalid shortcut (missing KEY_FENRIR): "+ str(shortcut) + ' command:' +commandName ,debug.debugLevel.ERROR)
continue
self.env['runtime']['debug'].writeDebugOut("invalid shortcut (missing KEY_FENRIR): "+ str(shortcut) + ' command:' +commandName ,debug.debugLevel.ERROR)
continue
self.env['runtime']['debug'].writeDebugOut("Shortcut: "+ str(shortcut) + ' command:' +commandName ,debug.debugLevel.INFO, onAnyLevel=True)
self.env['bindings'][str(shortcut)] = commandName
self.env['bindings'][str(shortcut)] = commandName
kbConfig.close()
# fix bindings
self.env['bindings'][str([1, ['KEY_F1', 'KEY_FENRIR']])] = 'TOGGLE_TUTORIAL_MODE'
def isValidKey(self, key):
return key in inputData.keyNames
return key in inputData.keyNames

View File

@ -10,7 +10,7 @@ _evdevAvailableError = ''
_udevAvailableError = ''
try:
import evdev
from evdev import InputDevice, UInput
from evdev import InputDevice, UInput, ecodes as e
_evdevAvailable = True
except Exception as e:
@ -43,6 +43,7 @@ class driver(inputDriver):
self.gDevices = {}
self.iDeviceNo = 0
self.watchDog = Value(c_bool, True)
self.UInputinject = UInput()
def initialize(self, environment):
self.env = environment
self.env['runtime']['inputManager'].setShortcutType('KEY')
@ -336,9 +337,9 @@ class driver(inputDriver):
self.env['runtime']['debug'].writeDebugOut('InputDriver evdev: grabing not possible: ' + str(e),debug.debugLevel.ERROR)
def ungrabDevice(self,fd):
if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'):
return
return
try:
self.gDevices[fd] = False
self.gDevices[fd] = False
self.iDevices[fd].ungrab()
self.env['runtime']['debug'].writeDebugOut('InputDriver evdev: ungrab device ('+ str(self.iDevices[fd].name) + ')',debug.debugLevel.INFO)
except:
@ -365,13 +366,13 @@ class driver(inputDriver):
try:
del(self.uDevices[fd])
except:
pass
pass
try:
del(self.gDevices[fd])
except:
pass
pass
self.updateMPiDevicesFD()
def hasIDevices(self):
if not self._initialized:
return False
@ -379,7 +380,16 @@ class driver(inputDriver):
return False
if len(self.iDevices) == 0:
return False
return True
return True
def sendKey(self, key, state):
if not self._initialized:
return
try:
self.UInputinject.write(e.EV_KEY, e.ecodes[key], state)
self.UInputinject.syn()
except:
pass
def removeAllDevices(self):
if not self.hasIDevices():
@ -389,5 +399,5 @@ class driver(inputDriver):
self.removeDevice(fd)
self.iDevices.clear()
self.uDevices.clear()
self.gDevices.clear()
self.gDevices.clear()
self.iDeviceNo = 0