make fenrir key configurable

This commit is contained in:
chrys 2016-08-11 23:16:44 +02:00
parent b4f01f76f0
commit 794abf26e3
11 changed files with 69 additions and 80 deletions

View File

@ -1,4 +1,3 @@
1-KEY_KP0=fenrirKey
#1-KEY_LEFTCTRL=shut_up #1-KEY_LEFTCTRL=shut_up
1-KEY_RIGHTCTRL=shut_up 1-KEY_RIGHTCTRL=shut_up
1-KEY_KP8=curr_line 1-KEY_KP8=curr_line

View File

@ -1,5 +1,3 @@
1-KEY_CAPSLOCK=fenrirKey
#1-KEY_LEFTCTRL=shut_up #1-KEY_LEFTCTRL=shut_up
1-KEY_RIGHTCTRL=shut_up 1-KEY_RIGHTCTRL=shut_up
1-KEY_I=curr_line 1-KEY_I=curr_line

View File

@ -1,21 +1,20 @@
1-KEY_KP0=fenrirKey
#1-KEY_LEFTCTRL=shut_up #1-KEY_LEFTCTRL=shut_up
1-KEY_KP0,1-KEY_RIGHTCTRL=shut_up 1-FENRIR,1-KEY_RIGHTCTRL=shut_up
1-KEY_KP0,1-KEY_KP8=curr_line 1-FENRIR,1-KEY_KP8=curr_line
1-KEY_KP0,1-KEY_KP7=prev_line 1-FENRIR,1-KEY_KP7=prev_line
1-KEY_KP0,1-KEY_KP9=next_line 1-FENRIR,1-KEY_KP9=next_line
1-KEY_KP0,1-KEY_KP5=curr_word 1-FENRIR,1-KEY_KP5=curr_word
1-KEY_KP0,1-KEY_KP4=prev_word 1-FENRIR,1-KEY_KP4=prev_word
1-KEY_KP0,1-KEY_KP6=next_word 1-FENRIR,1-KEY_KP6=next_word
1-KEY_KP0,1-KEY_KP2=curr_char 1-FENRIR,1-KEY_KP2=curr_char
1-KEY_KP0,1-KEY_KP1=prev_char 1-FENRIR,1-KEY_KP1=prev_char
1-KEY_KP0,1-KEY_KP3=next_char 1-FENRIR,1-KEY_KP3=next_char
1-KEY_KP0,1-KEY_KPDOT=exit_review 1-FENRIR,1-KEY_KPDOT=exit_review
#=curr_screen #=curr_screen
#=last_incomming #=last_incomming
1-KEY_KP0,1-KEY_F2=toggle_braille 1-FENRIR,1-KEY_F2=toggle_braille
1-KEY_KP0,1-KEY_F3=toggle_sound 1-FENRIR,1-KEY_F3=toggle_sound
1-KEY_KP0,1-KEY_F4=toggle_speech 1-FENRIR,1-KEY_F4=toggle_speech
#=toggle_output #=toggle_output
#=toggle_autoRead #=toggle_autoRead
#=quit_fenrir #=quit_fenrir

View File

@ -6,12 +6,12 @@ volume=1.0
[speech] [speech]
enabled=True enabled=True
driver=espeak driver=speechd
rate=0.75 rate=0.75
pitch=0.5 pitch=0.5
module=espeak module=espeak
voice=en-us voice=de
language=en-us language=de
volume=1.0 volume=1.0
autoReadIncomming=True autoReadIncomming=True
@ -27,8 +27,8 @@ screenUpdateDelay=0.4
device=all device=all
grabDevices=True grabDevices=True
ignoreShortcuts=False ignoreShortcuts=False
keyboardLayout=desktop keyboardLayout=test
charEcho=False charEcho=True
charDeleteEcho=True charDeleteEcho=True
wordEcho=True wordEcho=True
interruptOnKeyPress=False interruptOnKeyPress=False
@ -36,3 +36,4 @@ interruptOnKeyPress=False
[general] [general]
debugLevel=0 debugLevel=0
punctuationLevel=1 punctuationLevel=1
fenrirKeys=KEY_KP0

View File

@ -1,38 +0,0 @@
[sound]
enabled=True
driver=sox
theme=default
volume=1.0
[speech]
enabled=True
driver=speechd
rate=0.75
pitch=0.5
module=espeak
voice=de
language=de
volume=1.0
autoReadIncomming=True
[braille]
enabled=False
layout=en
[screen]
driver=linux
screenUpdateDelay=0.4
[keyboard]
device=all
grabDevices=True
ignoreShortcuts=False
keyboardLayout=test
charEcho=True
charDeleteEcho=True
wordEcho=True
interruptOnKeyPress=False
[general]
debugLevel=0
punctuationLevel=1

View File

@ -36,3 +36,4 @@ interruptOnKeyPress=False
[general] [general]
debugLevel=0 debugLevel=0
punctuationLevel=1 punctuationLevel=1
fenrirKeys=KEY_KP0

View File

@ -2,5 +2,4 @@
generalInformation = { generalInformation = {
'running': True, 'running': True,
'consumeKey': False,
} }

View File

@ -2,6 +2,9 @@
input = { input = {
'currShortcut': {}, 'currShortcut': {},
'currShortcutString': '' 'currShortcutString': '',
'consumeKey': False,
'fenrirKey': ['82'],
'keyForeward': False,
} }

View File

@ -19,25 +19,31 @@ class inputManager():
timeout = False timeout = False
for fd in r: for fd in r:
for event in self.iDevices[fd].read(): for event in self.iDevices[fd].read():
if event.code == 82: # a if self.isFenrirKey(environment, event): # a
environment['generalInformation']['consumeKey'] = True environment['input']['consumeKey'] = not environment['input']['keyForeward']
if not environment['generalInformation']['consumeKey']: if not environment['input']['consumeKey']:
self.uDevices[fd].write_event(event) self.uDevices[fd].write_event(event)
self.uDevices[fd].syn() self.uDevices[fd].syn()
time.sleep(0.01)
else: else:
keyString = ''
if self.isFenrirKey(environment, event):
keyString = 'FENRIR'
else:
keyString = str(event.code)
if event.type == evdev.ecodes.EV_KEY: if event.type == evdev.ecodes.EV_KEY:
if event.value != 0: if event.value != 0:
environment['input']['currShortcut'][str(event.code)] = 1 #event.value environment['input']['currShortcut'][keyString] = 1 #event.value
else: else:
try: try:
del(environment['input']['currShortcut'][str(event.code)]) del(environment['input']['currShortcut'][keyString])
except: except:
pass pass
except Exception as e: except Exception as e:
self.freeDevices() self.freeDevices()
time.sleep(0.01)
environment['input']['currShortcutString'] = self.getShortcutString(environment) environment['input']['currShortcutString'] = self.getShortcutString(environment)
environment['generalInformation']['consumeKey'] = environment['input']['currShortcut'] != {} environment['input']['consumeKey'] = environment['input']['currShortcut'] != {} and environment['input']['consumeKey']
environment['input']['keyForeward'] = environment['input']['keyForeward'] and environment['input']['currShortcut'] == {}
return environment, timeout return environment, timeout
def getShortcutString(self, environment): def getShortcutString(self, environment):
@ -45,10 +51,12 @@ class inputManager():
return '' return ''
currShortcutStringList = [] currShortcutStringList = []
for key in environment['input']['currShortcut']: for key in environment['input']['currShortcut']:
currShortcutStringList.append("%s-%s" % (environment['input']['currShortcut'][key], key)) currShortcutStringList.append("%s-%s" % (environment['input']['currShortcut'][key], key))
currShortcutStringList = sorted(currShortcutStringList) currShortcutStringList = sorted(currShortcutStringList)
return str(currShortcutStringList)[1:-1].replace(" ","").replace("'","") return str(currShortcutStringList)[1:-1].replace(" ","").replace("'","")
def isFenrirKey(self,environment, event):
return str(event.code) in environment['input']['fenrirKey']
def getDevices(self): def getDevices(self):
self.iDevices = map(evdev.InputDevice, (evdev.list_devices())) self.iDevices = map(evdev.InputDevice, (evdev.list_devices()))
self.iDevices = {dev.fd: dev for dev in self.iDevices if 1 in dev.capabilities()} self.iDevices = {dev.fd: dev for dev in self.iDevices if 1 in dev.capabilities()}
@ -57,7 +65,6 @@ class inputManager():
dev = self.iDevices[fd] dev = self.iDevices[fd]
cap = dev.capabilities() cap = dev.capabilities()
del cap[0] del cap[0]
print(dev.name)
self.uDevices[fd] = UInput( self.uDevices[fd] = UInput(
cap, cap,
dev.name, dev.name,

View File

@ -32,6 +32,7 @@ settings = {
'keyboardLayout': "desktop", 'keyboardLayout': "desktop",
'debugLevel': debug.debugLevel.DEACTIVE, 'debugLevel': debug.debugLevel.DEACTIVE,
'punctuationLevel': 1, 'punctuationLevel': 1,
'fenrirKeys':['82'],
}, },
'keyboard':{ 'keyboard':{
'device':"all", 'device':"all",

View File

@ -30,6 +30,7 @@ class settingsManager():
keys = sepLine[0].replace(" ","").split(',') keys = sepLine[0].replace(" ","").split(',')
currShortcut = [] currShortcut = []
validKeyString = True validKeyString = True
keyIdent = ''
for key in keys: for key in keys:
if len(key) < 3: if len(key) < 3:
validKeyString = False validKeyString = False
@ -41,24 +42,28 @@ class settingsManager():
validKeyString = False validKeyString = False
break break
if key[2:] != '': if key[2:] != '':
keyInt = self.getCodeForKeyID(key[2:]) if key[2:] == 'FENRIR':
keyIdent= 'FENRIR'
else:
keyInt = self.getCodeForKeyID(key[2:])
keyIdent = str(keyInt)
else: else:
validKeyString = False validKeyString = False
break break
if keyInt == 0: if keyIdent == '':
validKeyString = False validKeyString = False
break break
if not validKeyString: if not validKeyString:
break break
else: else:
currShortcut.append(key[0] + '-' + str(keyInt)) currShortcut.append(key[0] + '-' + keyIdent)
if validKeyString: if validKeyString:
keyString = '' keyString = ''
for k in sorted(currShortcut): for k in sorted(currShortcut):
if keyString != '': if keyString != '':
keyString += ',' keyString += ','
keyString += k keyString += k
environment['bindings'][keyString] = commandString environment['bindings'][keyString] = commandString
kbConfig.close() kbConfig.close()
return environment return environment
@ -165,7 +170,20 @@ class settingsManager():
spec.loader.exec_module(driver_mod) spec.loader.exec_module(driver_mod)
environment['runtime']['screenDriver'] = driver_mod.screen() environment['runtime']['screenDriver'] = driver_mod.screen()
return environment return environment
def setFenrirKeys(self, environment, keys):
keyList = keys.split(',')
for key in keyList:
keyID = self.keyIDasString( key)
if keyID != '':
if not keyID in environment['input']['fenrirKey']:
environment['input']['fenrirKey'].append(keyID)
return environment
def keyIDasString(self, key):
try:
KeyID = self.getCodeForKeyID(key)
return str(KeyID)
except:
return ''
def initFenrirConfig(self): def initFenrirConfig(self):
return self.reInitFenrirConfig(environment.environment) return self.reInitFenrirConfig(environment.environment)
@ -175,6 +193,7 @@ class settingsManager():
environment['runtime']['inputManager'] = inputManager.inputManager() environment['runtime']['inputManager'] = inputManager.inputManager()
environment['runtime']['outputManager'] = outputManager.outputManager() environment['runtime']['outputManager'] = outputManager.outputManager()
environment = environment['runtime']['settingsManager'].loadSettings(environment) environment = environment['runtime']['settingsManager'].loadSettings(environment)
environment = self.setFenrirKeys(environment, self.getSetting(environment, 'general','fenrirKeys'))
if not os.path.exists(self.getSetting(environment, 'keyboard','keyboardLayout')): if not os.path.exists(self.getSetting(environment, 'keyboard','keyboardLayout')):
if os.path.exists(settingsRoot + 'keyboard/' + self.getSetting(environment, 'keyboard','keyboardLayout')): if os.path.exists(settingsRoot + 'keyboard/' + self.getSetting(environment, 'keyboard','keyboardLayout')):
self.setSetting(environment, 'keyboard', 'keyboardLayout', settingsRoot + 'keyboard/' + self.getSetting(environment, 'keyboard','keyboardLayout')) self.setSetting(environment, 'keyboard', 'keyboardLayout', settingsRoot + 'keyboard/' + self.getSetting(environment, 'keyboard','keyboardLayout'))
@ -205,4 +224,4 @@ class settingsManager():
environment = environment['runtime']['settingsManager'].loadSoundDriver(environment,\ environment = environment['runtime']['settingsManager'].loadSoundDriver(environment,\
environment['runtime']['settingsManager'].getSetting(environment,'sound', 'driver')) environment['runtime']['settingsManager'].getSetting(environment,'sound', 'driver'))
return environment return environment