implement synth
This commit is contained in:
parent
e2ecacfb2a
commit
b5c94a506d
@ -47,6 +47,9 @@ class inputDriver():
|
|||||||
def removeAllDevices(self):
|
def removeAllDevices(self):
|
||||||
if not self._initialized:
|
if not self._initialized:
|
||||||
return
|
return
|
||||||
|
def sendKey(self):
|
||||||
|
if not self._initialized:
|
||||||
|
return
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
if not self._initialized:
|
if not self._initialized:
|
||||||
return
|
return
|
||||||
|
@ -53,16 +53,32 @@ class inputManager():
|
|||||||
if self.env['input']['eventBuffer'] != []:
|
if self.env['input']['eventBuffer'] != []:
|
||||||
return
|
return
|
||||||
if not self.noKeyPressed():
|
if not self.noKeyPressed():
|
||||||
return
|
return
|
||||||
if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'):
|
if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'):
|
||||||
return
|
return
|
||||||
if self.env['runtime']['screenManager'].getCurrScreenIgnored():
|
if self.env['runtime']['screenManager'].getCurrScreenIgnored():
|
||||||
self.ungrabAllDevices()
|
self.ungrabAllDevices()
|
||||||
else:
|
else:
|
||||||
self.grabAllDevices()
|
self.grabAllDevices()
|
||||||
self.executeDeviceGrab = False
|
self.executeDeviceGrab = False
|
||||||
def sendKeys(self, keyMacro):
|
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):
|
def handleInputEvent(self, eventData):
|
||||||
#print(eventData)
|
#print(eventData)
|
||||||
if not eventData:
|
if not eventData:
|
||||||
@ -70,9 +86,9 @@ class inputManager():
|
|||||||
# a hang apears.. try to fix
|
# a hang apears.. try to fix
|
||||||
if self.env['input']['eventBuffer'] == []:
|
if self.env['input']['eventBuffer'] == []:
|
||||||
if self.env['input']['currInput'] != []:
|
if self.env['input']['currInput'] != []:
|
||||||
self.env['input']['currInput'] = []
|
self.env['input']['currInput'] = []
|
||||||
self.env['input']['shortcutRepeat'] = 1
|
self.env['input']['shortcutRepeat'] = 1
|
||||||
|
|
||||||
self.env['input']['prevInput'] = self.env['input']['currInput'].copy()
|
self.env['input']['prevInput'] = self.env['input']['currInput'].copy()
|
||||||
if eventData['EventState'] == 0:
|
if eventData['EventState'] == 0:
|
||||||
if eventData['EventName'] in self.env['input']['currInput']:
|
if eventData['EventName'] in self.env['input']['currInput']:
|
||||||
@ -81,7 +97,7 @@ class inputManager():
|
|||||||
self.env['input']['currInput'] = sorted(self.env['input']['currInput'])
|
self.env['input']['currInput'] = sorted(self.env['input']['currInput'])
|
||||||
elif len(self.env['input']['currInput']) == 0:
|
elif len(self.env['input']['currInput']) == 0:
|
||||||
self.env['input']['shortcutRepeat'] = 1
|
self.env['input']['shortcutRepeat'] = 1
|
||||||
self.lastInputTime = time.time()
|
self.lastInputTime = time.time()
|
||||||
elif eventData['EventState'] == 1:
|
elif eventData['EventState'] == 1:
|
||||||
if not eventData['EventName'] in self.env['input']['currInput']:
|
if not eventData['EventName'] in self.env['input']['currInput']:
|
||||||
self.env['input']['currInput'].append(eventData['EventName'])
|
self.env['input']['currInput'].append(eventData['EventName'])
|
||||||
@ -94,10 +110,10 @@ class inputManager():
|
|||||||
self.env['input']['shortcutRepeat'] += 1
|
self.env['input']['shortcutRepeat'] += 1
|
||||||
else:
|
else:
|
||||||
self.env['input']['shortcutRepeat'] = 1
|
self.env['input']['shortcutRepeat'] = 1
|
||||||
self.handleLedStates(eventData)
|
self.handleLedStates(eventData)
|
||||||
self.lastInputTime = time.time()
|
self.lastInputTime = time.time()
|
||||||
elif eventData['EventState'] == 2:
|
elif eventData['EventState'] == 2:
|
||||||
self.lastInputTime = time.time()
|
self.lastInputTime = time.time()
|
||||||
|
|
||||||
self.env['input']['oldNumLock'] = self.env['input']['newNumLock']
|
self.env['input']['oldNumLock'] = self.env['input']['newNumLock']
|
||||||
self.env['input']['newNumLock'] = self.env['runtime']['inputDriver'].getLedState()
|
self.env['input']['newNumLock'] = self.env['runtime']['inputDriver'].getLedState()
|
||||||
@ -109,7 +125,7 @@ class inputManager():
|
|||||||
if self.noKeyPressed():
|
if self.noKeyPressed():
|
||||||
self.env['input']['prevInput'] = []
|
self.env['input']['prevInput'] = []
|
||||||
self.handleDeviceGrab()
|
self.handleDeviceGrab()
|
||||||
|
|
||||||
def handleLedStates(self, mEvent):
|
def handleLedStates(self, mEvent):
|
||||||
try:
|
try:
|
||||||
if mEvent['EventName'] == 'KEY_NUMLOCK':
|
if mEvent['EventName'] == 'KEY_NUMLOCK':
|
||||||
@ -173,24 +189,24 @@ class inputManager():
|
|||||||
elif eventName == 'KEY_LEFTMETA':
|
elif eventName == 'KEY_LEFTMETA':
|
||||||
eventName = 'KEY_META'
|
eventName = 'KEY_META'
|
||||||
elif eventName == 'KEY_RIGHTMETA':
|
elif eventName == 'KEY_RIGHTMETA':
|
||||||
eventName = 'KEY_META'
|
eventName = 'KEY_META'
|
||||||
if self.isFenrirKey(eventName):
|
if self.isFenrirKey(eventName):
|
||||||
eventName = 'KEY_FENRIR'
|
eventName = 'KEY_FENRIR'
|
||||||
if self.isScriptKey(eventName):
|
if self.isScriptKey(eventName):
|
||||||
eventName = 'KEY_SCRIPT'
|
eventName = 'KEY_SCRIPT'
|
||||||
return eventName
|
return eventName
|
||||||
|
|
||||||
def clearEventBuffer(self):
|
def clearEventBuffer(self):
|
||||||
try:
|
try:
|
||||||
self.env['runtime']['inputDriver'].clearEventBuffer()
|
self.env['runtime']['inputDriver'].clearEventBuffer()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
pass
|
pass
|
||||||
def setLastDeepestInput(self, currentDeepestInput):
|
def setLastDeepestInput(self, currentDeepestInput):
|
||||||
self.lastDeepestInput = currentDeepestInput
|
self.lastDeepestInput = currentDeepestInput
|
||||||
def clearLastDeepInput(self):
|
def clearLastDeepInput(self):
|
||||||
self.lastDeepestInput = []
|
self.lastDeepestInput = []
|
||||||
def getLastInputTime(self):
|
def getLastInputTime(self):
|
||||||
return self.lastInputTime
|
return self.lastInputTime
|
||||||
def getLastDeepestInput(self):
|
def getLastDeepestInput(self):
|
||||||
return self.lastDeepestInput
|
return self.lastDeepestInput
|
||||||
def writeEventBuffer(self):
|
def writeEventBuffer(self):
|
||||||
@ -211,7 +227,7 @@ class inputManager():
|
|||||||
shortcut.append(self.env['input']['shortcutRepeat'])
|
shortcut.append(self.env['input']['shortcutRepeat'])
|
||||||
shortcut.append(self.getLastDeepestInput())
|
shortcut.append(self.getLastDeepestInput())
|
||||||
return str(shortcut)
|
return str(shortcut)
|
||||||
|
|
||||||
def getPrevShortcut(self):
|
def getPrevShortcut(self):
|
||||||
shortcut = []
|
shortcut = []
|
||||||
shortcut.append(self.env['input']['shortcutRepeat'])
|
shortcut.append(self.env['input']['shortcutRepeat'])
|
||||||
@ -223,7 +239,7 @@ class inputManager():
|
|||||||
shortcut.append(self.env['input']['shortcutRepeat'])
|
shortcut.append(self.env['input']['shortcutRepeat'])
|
||||||
if inputSequence:
|
if inputSequence:
|
||||||
shortcut.append(inputSequence)
|
shortcut.append(inputSequence)
|
||||||
else:
|
else:
|
||||||
shortcut.append(self.env['input']['currInput'])
|
shortcut.append(self.env['input']['currInput'])
|
||||||
if len(self.env['input']['prevInput']) < len(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)):
|
if self.env['input']['shortcutRepeat'] > 1 and not self.shortcutExists(str(shortcut)):
|
||||||
@ -231,20 +247,20 @@ class inputManager():
|
|||||||
self.env['input']['shortcutRepeat'] = 1
|
self.env['input']['shortcutRepeat'] = 1
|
||||||
shortcut.append(self.env['input']['shortcutRepeat'])
|
shortcut.append(self.env['input']['shortcutRepeat'])
|
||||||
shortcut.append(self.env['input']['currInput'])
|
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)
|
return str(shortcut)
|
||||||
|
|
||||||
def currKeyIsModifier(self):
|
def currKeyIsModifier(self):
|
||||||
if len(self.getLastDeepestInput()) != 1:
|
if len(self.getLastDeepestInput()) != 1:
|
||||||
return False
|
return False
|
||||||
return (self.env['input']['currInput'][0] =='KEY_FENRIR') or (self.env['input']['currInput'][0] == 'KEY_SCRIPT')
|
return (self.env['input']['currInput'][0] =='KEY_FENRIR') or (self.env['input']['currInput'][0] == 'KEY_SCRIPT')
|
||||||
|
|
||||||
def isFenrirKey(self, eventName):
|
def isFenrirKey(self, eventName):
|
||||||
return eventName in self.env['input']['fenrirKey']
|
return eventName in self.env['input']['fenrirKey']
|
||||||
|
|
||||||
def isScriptKey(self, eventName):
|
def isScriptKey(self, eventName):
|
||||||
return eventName in self.env['input']['scriptKey']
|
return eventName in self.env['input']['scriptKey']
|
||||||
|
|
||||||
def getCommandForShortcut(self, shortcut):
|
def getCommandForShortcut(self, shortcut):
|
||||||
if not self.shortcutExists(shortcut):
|
if not self.shortcutExists(shortcut):
|
||||||
return ''
|
return ''
|
||||||
@ -261,7 +277,7 @@ class inputManager():
|
|||||||
break
|
break
|
||||||
line = line.replace('\n','')
|
line = line.replace('\n','')
|
||||||
if line.replace(" ","") == '':
|
if line.replace(" ","") == '':
|
||||||
continue
|
continue
|
||||||
if line.replace(" ","").startswith("#"):
|
if line.replace(" ","").startswith("#"):
|
||||||
continue
|
continue
|
||||||
if line.count("=") != 1:
|
if line.count("=") != 1:
|
||||||
@ -289,12 +305,12 @@ class inputManager():
|
|||||||
shortcut.append(shortcutRepeat)
|
shortcut.append(shortcutRepeat)
|
||||||
shortcut.append(sorted(shortcutKeys))
|
shortcut.append(sorted(shortcutKeys))
|
||||||
if len(shortcutKeys) != 1 and not 'KEY_FENRIR' in 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)
|
self.env['runtime']['debug'].writeDebugOut("invalid shortcut (missing KEY_FENRIR): "+ str(shortcut) + ' command:' +commandName ,debug.debugLevel.ERROR)
|
||||||
continue
|
continue
|
||||||
self.env['runtime']['debug'].writeDebugOut("Shortcut: "+ str(shortcut) + ' command:' +commandName ,debug.debugLevel.INFO, onAnyLevel=True)
|
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()
|
kbConfig.close()
|
||||||
# fix bindings
|
# fix bindings
|
||||||
self.env['bindings'][str([1, ['KEY_F1', 'KEY_FENRIR']])] = 'TOGGLE_TUTORIAL_MODE'
|
self.env['bindings'][str([1, ['KEY_F1', 'KEY_FENRIR']])] = 'TOGGLE_TUTORIAL_MODE'
|
||||||
def isValidKey(self, key):
|
def isValidKey(self, key):
|
||||||
return key in inputData.keyNames
|
return key in inputData.keyNames
|
||||||
|
@ -10,7 +10,7 @@ _evdevAvailableError = ''
|
|||||||
_udevAvailableError = ''
|
_udevAvailableError = ''
|
||||||
try:
|
try:
|
||||||
import evdev
|
import evdev
|
||||||
from evdev import InputDevice, UInput
|
from evdev import InputDevice, UInput, ecodes as e
|
||||||
_evdevAvailable = True
|
_evdevAvailable = True
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -43,6 +43,7 @@ class driver(inputDriver):
|
|||||||
self.gDevices = {}
|
self.gDevices = {}
|
||||||
self.iDeviceNo = 0
|
self.iDeviceNo = 0
|
||||||
self.watchDog = Value(c_bool, True)
|
self.watchDog = Value(c_bool, True)
|
||||||
|
self.UInputinject = UInput()
|
||||||
def initialize(self, environment):
|
def initialize(self, environment):
|
||||||
self.env = environment
|
self.env = environment
|
||||||
self.env['runtime']['inputManager'].setShortcutType('KEY')
|
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)
|
self.env['runtime']['debug'].writeDebugOut('InputDriver evdev: grabing not possible: ' + str(e),debug.debugLevel.ERROR)
|
||||||
def ungrabDevice(self,fd):
|
def ungrabDevice(self,fd):
|
||||||
if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'):
|
if not self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'):
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
self.gDevices[fd] = False
|
self.gDevices[fd] = False
|
||||||
self.iDevices[fd].ungrab()
|
self.iDevices[fd].ungrab()
|
||||||
self.env['runtime']['debug'].writeDebugOut('InputDriver evdev: ungrab device ('+ str(self.iDevices[fd].name) + ')',debug.debugLevel.INFO)
|
self.env['runtime']['debug'].writeDebugOut('InputDriver evdev: ungrab device ('+ str(self.iDevices[fd].name) + ')',debug.debugLevel.INFO)
|
||||||
except:
|
except:
|
||||||
@ -365,13 +366,13 @@ class driver(inputDriver):
|
|||||||
try:
|
try:
|
||||||
del(self.uDevices[fd])
|
del(self.uDevices[fd])
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
del(self.gDevices[fd])
|
del(self.gDevices[fd])
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
self.updateMPiDevicesFD()
|
self.updateMPiDevicesFD()
|
||||||
|
|
||||||
def hasIDevices(self):
|
def hasIDevices(self):
|
||||||
if not self._initialized:
|
if not self._initialized:
|
||||||
return False
|
return False
|
||||||
@ -379,7 +380,16 @@ class driver(inputDriver):
|
|||||||
return False
|
return False
|
||||||
if len(self.iDevices) == 0:
|
if len(self.iDevices) == 0:
|
||||||
return False
|
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):
|
def removeAllDevices(self):
|
||||||
if not self.hasIDevices():
|
if not self.hasIDevices():
|
||||||
@ -389,5 +399,5 @@ class driver(inputDriver):
|
|||||||
self.removeDevice(fd)
|
self.removeDevice(fd)
|
||||||
self.iDevices.clear()
|
self.iDevices.clear()
|
||||||
self.uDevices.clear()
|
self.uDevices.clear()
|
||||||
self.gDevices.clear()
|
self.gDevices.clear()
|
||||||
self.iDeviceNo = 0
|
self.iDeviceNo = 0
|
||||||
|
Loading…
Reference in New Issue
Block a user