2016-07-07 13:43:31 -04:00
|
|
|
#!/bin/python
|
2016-09-19 16:15:58 -04:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# Fenrir TTY screen reader
|
|
|
|
# By Chrys, Storm Dragon, and contributers.
|
2016-07-07 13:43:31 -04:00
|
|
|
|
2016-08-11 08:37:46 -04:00
|
|
|
import time
|
2016-09-19 16:15:58 -04:00
|
|
|
from core import debug
|
2016-09-17 17:38:40 -04:00
|
|
|
from core import inputEvent
|
2016-07-07 15:40:10 -04:00
|
|
|
|
2016-07-07 13:43:31 -04:00
|
|
|
class inputManager():
|
|
|
|
def __init__(self):
|
2016-09-02 15:37:36 -04:00
|
|
|
pass
|
|
|
|
def initialize(self, environment):
|
2016-09-21 17:17:54 -04:00
|
|
|
self.env = environment
|
|
|
|
self.env['runtime']['settingsManager'].loadDriver(\
|
|
|
|
self.env['runtime']['settingsManager'].getSetting('keyboard', 'driver'), 'inputDriver')
|
2016-09-18 07:13:58 -04:00
|
|
|
# init LEDs with current state
|
2016-09-21 17:17:54 -04:00
|
|
|
self.env['input']['newNumLock'] = self.env['runtime']['inputDriver'].getNumlock()
|
|
|
|
self.env['input']['oldNumLock'] = self.env['input']['newNumLock']
|
|
|
|
self.env['input']['newCapsLock'] = self.env['runtime']['inputDriver'].getCapslock()
|
|
|
|
self.env['input']['oldCapsLock'] = self.env['input']['newCapsLock']
|
|
|
|
self.env['input']['newScrollLock'] = self.env['runtime']['inputDriver'].getScrollLock()
|
|
|
|
self.env['input']['oldScrollLock'] = self.env['input']['newScrollLock']
|
|
|
|
self.grabDevices()
|
2016-09-16 19:04:03 -04:00
|
|
|
|
2016-09-21 17:17:54 -04:00
|
|
|
def shutdown(self):
|
|
|
|
self.env['runtime']['inputManager'].releaseDevices()
|
|
|
|
self.env['runtime']['settingsManager'].shutdownDriver('inputDriver')
|
2016-09-21 12:07:28 -04:00
|
|
|
|
2016-09-21 17:17:54 -04:00
|
|
|
def getInputEvent(self):
|
2016-09-21 12:07:28 -04:00
|
|
|
eventReceived = False
|
2016-09-21 17:17:54 -04:00
|
|
|
mEvent = self.env['runtime']['inputDriver'].getInputEvent()
|
2016-09-18 09:13:24 -04:00
|
|
|
if mEvent:
|
2016-09-21 17:17:54 -04:00
|
|
|
mEvent['EventName'] = self.convertEventName(mEvent['EventName'])
|
2016-09-17 17:38:40 -04:00
|
|
|
if mEvent['EventValue'] == 0:
|
2016-09-21 04:00:45 -04:00
|
|
|
return False
|
|
|
|
eventReceived = True
|
2016-09-17 17:38:40 -04:00
|
|
|
if mEvent['EventState'] == 0:
|
2016-09-21 17:17:54 -04:00
|
|
|
if mEvent['EventName'] in self.env['input']['currInput']:
|
|
|
|
self.env['input']['currInput'].remove(mEvent['EventName'])
|
|
|
|
self.env['input']['currInput'] = sorted(self.env['input']['currInput'])
|
2016-09-17 17:38:40 -04:00
|
|
|
elif mEvent['EventState'] == 1:
|
2016-09-21 17:17:54 -04:00
|
|
|
if not mEvent['EventName'] in self.env['input']['currInput']:
|
|
|
|
self.env['input']['currInput'].append(mEvent['EventName'])
|
|
|
|
self.env['input']['currInput'] = sorted(self.env['input']['currInput'])
|
2016-09-17 17:38:40 -04:00
|
|
|
elif mEvent['EventState'] == 2:
|
|
|
|
pass
|
|
|
|
else:
|
2016-09-17 21:22:54 -04:00
|
|
|
pass
|
2016-09-21 17:17:54 -04:00
|
|
|
self.env['input']['oldNumLock'] = self.env['input']['newNumLock']
|
|
|
|
self.env['input']['newNumLock'] = self.env['runtime']['inputDriver'].getNumlock()
|
|
|
|
self.env['input']['oldCapsLock'] = self.env['input']['newCapsLock']
|
|
|
|
self.env['input']['newCapsLock'] = self.env['runtime']['inputDriver'].getCapslock()
|
|
|
|
self.env['input']['oldScrollLock'] = self.env['input']['newScrollLock']
|
|
|
|
self.env['input']['newScrollLock'] = self.env['runtime']['inputDriver'].getScrollLock()
|
|
|
|
self.env['input']['lastInputTime'] = time.time()
|
|
|
|
self.env['input']['shortcutRepeat'] = 1
|
2016-09-21 04:00:45 -04:00
|
|
|
return eventReceived
|
2016-09-12 17:29:16 -04:00
|
|
|
|
2016-09-21 17:17:54 -04:00
|
|
|
def grabDevices(self):
|
|
|
|
if self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'):
|
|
|
|
self.env['runtime']['inputDriver'].grabDevices()
|
2016-09-02 15:37:36 -04:00
|
|
|
|
2016-09-21 17:17:54 -04:00
|
|
|
def releaseDevices(self):
|
|
|
|
self.env['runtime']['inputDriver'].releaseDevices()
|
2016-09-21 03:56:59 -04:00
|
|
|
|
2016-09-21 17:17:54 -04:00
|
|
|
def convertEventName(self, eventName):
|
2016-09-21 12:07:28 -04:00
|
|
|
if not eventName:
|
|
|
|
return ''
|
2016-09-21 03:56:59 -04:00
|
|
|
if eventName == 'KEY_LEFTCTRL':
|
|
|
|
eventName == 'KEY_CTRL'
|
|
|
|
elif eventName == 'KEY_RIGHTCTRL':
|
|
|
|
eventName = 'KEY_CTRL'
|
|
|
|
elif eventName == 'KEY_LEFTSHIFT':
|
|
|
|
eventName = 'KEY_SHIFT'
|
|
|
|
elif eventName == 'KEY_RIGHTSHIFT':
|
|
|
|
eventName = 'KEY_SHIFT'
|
|
|
|
elif eventName == 'KEY_LEFTALT':
|
|
|
|
eventName = 'KEY_ALT'
|
|
|
|
elif eventName == 'KEY_RIGHTALT':
|
|
|
|
eventName = 'KEY_ALT'
|
2016-09-21 17:17:54 -04:00
|
|
|
if self.isFenrirKey(eventName):
|
2016-09-21 12:07:28 -04:00
|
|
|
eventName = 'KEY_FENRIR'
|
|
|
|
return eventName
|
|
|
|
|
2016-09-21 17:17:54 -04:00
|
|
|
def isConsumeInput(self):
|
|
|
|
return self.env['runtime']['commandManager'].isCommandQueued() and \
|
|
|
|
not self.env['input']['keyForeward']
|
2016-09-21 12:07:28 -04:00
|
|
|
#and
|
2016-09-21 17:17:54 -04:00
|
|
|
# not (self.env['input']['keyForeward'] or \
|
|
|
|
# self.env['runtime']['settingsManager'].getSettingAsBool(, 'keyboard', 'grabDevices'))
|
2016-09-18 09:13:24 -04:00
|
|
|
|
2016-09-21 17:17:54 -04:00
|
|
|
def clearEventBuffer(self):
|
|
|
|
self.env['runtime']['inputDriver'].clearEventBuffer()
|
2016-09-02 15:37:36 -04:00
|
|
|
|
2016-09-21 17:17:54 -04:00
|
|
|
def writeEventBuffer(self):
|
2016-08-31 07:27:04 -04:00
|
|
|
try:
|
2016-09-21 17:17:54 -04:00
|
|
|
self.env['runtime']['inputDriver'].writeEventBuffer()
|
2016-09-02 12:08:44 -04:00
|
|
|
except Exception as e:
|
2016-09-18 09:13:24 -04:00
|
|
|
print(e)
|
2016-09-21 17:17:54 -04:00
|
|
|
self.env['runtime']['debug'].writeDebugOut("Error while writeUInput",debug.debugLevel.ERROR)
|
|
|
|
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
|
2016-09-21 12:07:28 -04:00
|
|
|
|
2016-09-21 17:17:54 -04:00
|
|
|
def isFenrirKeyPressed(self):
|
|
|
|
return 'KEY_FENRIR' in self.env['input']['currInput']
|
2016-09-12 17:29:16 -04:00
|
|
|
|
2016-09-21 17:17:54 -04:00
|
|
|
def noKeyPressed(self):
|
|
|
|
return self.env['input']['currInput'] == []
|
|
|
|
|
|
|
|
def getPrevDeepestInput(self):
|
2016-09-16 19:59:38 -04:00
|
|
|
shortcut = []
|
2016-09-21 17:17:54 -04:00
|
|
|
shortcut.append(self.env['input']['shortcutRepeat'])
|
|
|
|
shortcut.append(sorted(self.env['input']['prevDeepestInput']))
|
2016-09-16 19:59:38 -04:00
|
|
|
|
2016-09-21 17:17:54 -04:00
|
|
|
def getPrevShortcut(self):
|
2016-09-16 19:59:38 -04:00
|
|
|
shortcut = []
|
2016-09-21 17:17:54 -04:00
|
|
|
shortcut.append(self.env['input']['shortcutRepeat'])
|
|
|
|
shortcut.append(sorted(self.env['input']['prevInput']))
|
2016-09-17 17:38:40 -04:00
|
|
|
return str(shortcut)
|
2016-09-16 19:59:38 -04:00
|
|
|
|
2016-09-21 17:17:54 -04:00
|
|
|
def getCurrShortcut(self):
|
2016-09-16 19:59:38 -04:00
|
|
|
shortcut = []
|
2016-09-21 17:17:54 -04:00
|
|
|
shortcut.append(self.env['input']['shortcutRepeat'])
|
|
|
|
shortcut.append(sorted(self.env['input']['currInput']))
|
2016-09-17 17:38:40 -04:00
|
|
|
return str(shortcut)
|
2016-09-02 15:37:36 -04:00
|
|
|
|
2016-09-21 17:17:54 -04:00
|
|
|
def isFenrirKey(self, eventName):
|
|
|
|
return eventName in self.env['input']['fenrirKey']
|
2016-09-16 19:04:03 -04:00
|
|
|
|
2016-09-21 17:17:54 -04:00
|
|
|
def getCommandForShortcut(self, shortcut):
|
2016-09-16 19:04:03 -04:00
|
|
|
shortcut = shortcut.upper()
|
2016-09-21 17:17:54 -04:00
|
|
|
if not self.shortcutExists(shortcut):
|
2016-09-16 19:04:03 -04:00
|
|
|
return ''
|
2016-09-21 17:17:54 -04:00
|
|
|
return self.env['bindings'][shortcut].upper()
|
2016-09-16 19:04:03 -04:00
|
|
|
|
2016-09-21 17:17:54 -04:00
|
|
|
def shortcutExists(self, shortcut):
|
|
|
|
return( str(shortcut).upper() in self.env['bindings'])
|