initial working input command chain
This commit is contained in:
parent
09320092bc
commit
75db6ac58f
@ -5,7 +5,7 @@ from core import runtime
|
||||
from core import screenData
|
||||
from core import generalInformation
|
||||
from core import commands
|
||||
from core import input
|
||||
from core import inputEvent
|
||||
|
||||
environment = {
|
||||
'screenData': screenData.screenData,
|
||||
@ -15,7 +15,7 @@ environment = {
|
||||
'commands': commands.commands,
|
||||
'commandInfo': commands.commandInfo,
|
||||
'commandBuffer': commands.commandBuffer,
|
||||
'input': input.input,
|
||||
'input': inputEvent.input,
|
||||
'soundIcons': {},
|
||||
'bindings': {},
|
||||
}
|
||||
|
@ -6,9 +6,9 @@ input = {
|
||||
'prevInput': [],
|
||||
'prevDeepestInput': [],
|
||||
'currEvent': None,
|
||||
'firstEvent': None,
|
||||
'shortcutRepeat': 0,
|
||||
'fenrirKey': ['82'],
|
||||
'eventBuffer': None,
|
||||
'shortcutRepeat': 1,
|
||||
'fenrirKey': ['KEY_KP0'],
|
||||
'keyForeward': False,
|
||||
'lastInputTime':time.time(),
|
||||
'oldNumLock': True,
|
||||
@ -20,6 +20,7 @@ input = {
|
||||
inputEvent = {
|
||||
'EventName': '',
|
||||
'EventValue': '',
|
||||
'EventTime': time.time(),
|
||||
'EventSec': 0,
|
||||
'EventUsec': 0,
|
||||
'EventState': 0,
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
import time
|
||||
from utils import debug
|
||||
from core import inputEvent
|
||||
|
||||
class inputManager():
|
||||
def __init__(self):
|
||||
@ -18,13 +19,30 @@ class inputManager():
|
||||
def proceedInputEvent(self, environment):
|
||||
timeout = True
|
||||
event = environment['runtime']['inputDriver'].getInput(environment)
|
||||
if event:
|
||||
mEvent = environment['runtime']['inputDriver'].mapEvent(environment, event)
|
||||
if mEvent and event:
|
||||
if mEvent['EventValue'] == 0:
|
||||
return True
|
||||
timeout = False
|
||||
environment['input']['firstEvent'] = event
|
||||
environment['input']['currEvent'] = event
|
||||
#if not
|
||||
#print(event)
|
||||
|
||||
if mEvent['EventState'] == 0:
|
||||
if self.isFenrirKey(environment, mEvent):
|
||||
environment['input']['currInput'].remove('KEY_FENRIR')
|
||||
else:
|
||||
environment['input']['currInput'].remove(mEvent['EventName'])
|
||||
environment['input']['currInput'] = sorted(environment['input']['currInput'])
|
||||
elif mEvent['EventState'] == 1:
|
||||
if self.isFenrirKey(environment, mEvent):
|
||||
environment['input']['currInput'].append('KEY_FENRIR')
|
||||
else:
|
||||
environment['input']['currInput'].append(mEvent['EventName'])
|
||||
environment['input']['currInput'] = sorted(environment['input']['currInput'])
|
||||
elif mEvent['EventState'] == 2:
|
||||
pass
|
||||
else:
|
||||
pass
|
||||
print(environment['input']['currInput'])
|
||||
environment['input']['lastInputTime'] = time.time()
|
||||
environment['input']['shortcutRepeat'] = 1
|
||||
return timeout
|
||||
|
||||
def grabDevices(self, environment):
|
||||
@ -55,14 +73,16 @@ class inputManager():
|
||||
shortcut = []
|
||||
shortcut.append(environment['input']['shortcutRepeat'])
|
||||
shortcut.append(sorted(environment['input']['prevInput']))
|
||||
return str(shortcut)
|
||||
|
||||
def getPrevShortcut(self, environment):
|
||||
def getCurrShortcut(self, environment):
|
||||
shortcut = []
|
||||
shortcut.append(environment['input']['shortcutRepeat'])
|
||||
shortcut.append(sorted(environment['input']['prevInput']))
|
||||
shortcut.append(sorted(environment['input']['currInput']))
|
||||
return str(shortcut)
|
||||
|
||||
def isFenrirKey(self,environment, event):
|
||||
return str(event.code) in environment['input']['fenrirKey']
|
||||
def isFenrirKey(self,environment, mEvent):
|
||||
return str(mEvent['EventName']) in environment['input']['fenrirKey']
|
||||
|
||||
def getCommandForShortcut(self, environment, shortcut):
|
||||
shortcut = shortcut.upper()
|
||||
|
@ -34,25 +34,28 @@ class fenrir():
|
||||
|
||||
def handleProcess(self):
|
||||
timeout = self.environment['runtime']['inputManager'].proceedInputEvent(self.environment)
|
||||
timeout = True
|
||||
try:
|
||||
self.environment['runtime']['screenManager'].update(self.environment)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
self.environment['runtime']['debug'].writeDebugOut(self.environment, str(e),debug.debugLevel.ERROR)
|
||||
if not (self.environment['input']['keyForeward'] or timeout):
|
||||
#currShortcut = self.environment['runtime']['inputManager'].getCurrShortcut(self.environment)
|
||||
shortcut = "[1, ['KEY_FENRIR', 'KEY_T']]"
|
||||
command = self.environment['runtime']['inputManager'].getCommandForShortcut(self.environment, shortcut)
|
||||
print(command)
|
||||
#self.environment['runtime']['commandManager'].queueCommand(self.environment, command)
|
||||
if not timeout:
|
||||
if not timeout:
|
||||
self.prepareCommand()
|
||||
self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onInput')
|
||||
self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onScreenChanged')
|
||||
if not self.environment['input']['keyForeward']:
|
||||
self.handleCommands()
|
||||
self.handleCommands()
|
||||
|
||||
def prepareCommand(self):
|
||||
if self.environment['input']['keyForeward']:
|
||||
return
|
||||
shortcut = self.environment['runtime']['inputManager'].getCurrShortcut(self.environment)
|
||||
command = self.environment['runtime']['inputManager'].getCommandForShortcut(self.environment, shortcut)
|
||||
print(command)
|
||||
self.environment['runtime']['commandManager'].queueCommand(self.environment, command)
|
||||
|
||||
def handleCommands(self):
|
||||
if self.environment['input']['keyForeward']:
|
||||
return
|
||||
if self.environment['runtime']['commandManager'].isCommandQueued(self.environment):
|
||||
self.environment['runtime']['commandManager'].executeCommand(self.environment, self.environment['commandInfo']['currCommand'], 'commands')
|
||||
|
||||
|
@ -2,8 +2,10 @@
|
||||
|
||||
import evdev
|
||||
from evdev import InputDevice, UInput
|
||||
from select import select
|
||||
import time
|
||||
from select import select
|
||||
|
||||
from core import inputEvent
|
||||
from utils import debug
|
||||
|
||||
class driver():
|
||||
@ -32,11 +34,20 @@ class driver():
|
||||
self.iDevices = map(evdev.InputDevice, (evdev.list_devices()))
|
||||
self.iDevices = {dev.fd: dev for dev in self.iDevices if 1 in dev.capabilities()}
|
||||
|
||||
def mapEvent(self, event):
|
||||
def mapEvent(self,environment, event):
|
||||
if not event:
|
||||
return None
|
||||
mEvent = inputEvent.inputEvent
|
||||
try:
|
||||
return evdev.ecodes.ecodes[keyID.upper()]
|
||||
except:
|
||||
return 0
|
||||
mEvent['EventName'] = evdev.ecodes.keys[event.code].upper()
|
||||
mEvent['EventValue'] = event.code
|
||||
mEvent['EventSec'] = event.sec
|
||||
mEvent['EventUsec'] = event.usec
|
||||
mEvent['EventState'] = event.value
|
||||
return mEvent
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return None
|
||||
|
||||
def grabDevices(self):
|
||||
for fd in self.iDevices:
|
||||
|
Loading…
Reference in New Issue
Block a user