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

@ -62,7 +62,23 @@ class inputManager():
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:

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')
@ -381,6 +382,15 @@ class driver(inputDriver):
return False
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():
return