announce toggle of Numlock, Capslock and Scrolllock

This commit is contained in:
chrys 2016-10-22 20:27:58 +02:00
parent 1747b9b752
commit 5e70179b8c
3 changed files with 68 additions and 39 deletions

View File

@ -10,17 +10,17 @@ from core import inputEvent
class inputManager(): class inputManager():
def __init__(self): def __init__(self):
pass self.setLedState = True
def initialize(self, environment): def initialize(self, environment):
self.env = environment self.env = environment
self.env['runtime']['settingsManager'].loadDriver(\ self.env['runtime']['settingsManager'].loadDriver(\
self.env['runtime']['settingsManager'].getSetting('keyboard', 'driver'), 'inputDriver') self.env['runtime']['settingsManager'].getSetting('keyboard', 'driver'), 'inputDriver')
# init LEDs with current state # init LEDs with current state
self.env['input']['newNumLock'] = self.env['runtime']['inputDriver'].getNumlock() self.env['input']['newNumLock'] = self.env['runtime']['inputDriver'].getLedState()
self.env['input']['oldNumLock'] = self.env['input']['newNumLock'] self.env['input']['oldNumLock'] = self.env['input']['newNumLock']
self.env['input']['newCapsLock'] = self.env['runtime']['inputDriver'].getCapslock() self.env['input']['newCapsLock'] = self.env['runtime']['inputDriver'].getLedState(1)
self.env['input']['oldCapsLock'] = self.env['input']['newCapsLock'] self.env['input']['oldCapsLock'] = self.env['input']['newCapsLock']
self.env['input']['newScrollLock'] = self.env['runtime']['inputDriver'].getScrollLock() self.env['input']['newScrollLock'] = self.env['runtime']['inputDriver'].getLedState(2)
self.env['input']['oldScrollLock'] = self.env['input']['newScrollLock'] self.env['input']['oldScrollLock'] = self.env['input']['newScrollLock']
self.grabDevices() self.grabDevices()
@ -43,6 +43,7 @@ class inputManager():
if len(self.env['input']['currInput']) == 0: if len(self.env['input']['currInput']) == 0:
self.env['input']['prevDeepestInput'] = [] self.env['input']['prevDeepestInput'] = []
self.env['input']['shortcutRepeat'] = 1 self.env['input']['shortcutRepeat'] = 1
self.handleLedStates(mEvent)
self.env['input']['lastInputTime'] = time.time() self.env['input']['lastInputTime'] = time.time()
elif mEvent['EventState'] == 1: elif mEvent['EventState'] == 1:
if not mEvent['EventName'] in self.env['input']['currInput']: if not mEvent['EventName'] in self.env['input']['currInput']:
@ -56,22 +57,55 @@ 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(mEvent)
self.env['input']['lastInputTime'] = time.time() self.env['input']['lastInputTime'] = time.time()
elif mEvent['EventState'] == 2: elif mEvent['EventState'] == 2:
pass self.env['input']['lastInputTime'] = time.time()
else: else:
pass pass
self.env['input']['oldNumLock'] = self.env['input']['newNumLock'] self.env['input']['oldNumLock'] = self.env['input']['newNumLock']
self.env['input']['newNumLock'] = self.env['runtime']['inputDriver'].getNumlock() self.env['input']['newNumLock'] = self.env['runtime']['inputDriver'].getLedState()
self.env['input']['oldCapsLock'] = self.env['input']['newCapsLock'] self.env['input']['oldCapsLock'] = self.env['input']['newCapsLock']
self.env['input']['newCapsLock'] = self.env['runtime']['inputDriver'].getCapslock() self.env['input']['newCapsLock'] = self.env['runtime']['inputDriver'].getLedState(1)
self.env['input']['oldScrollLock'] = self.env['input']['newScrollLock'] self.env['input']['oldScrollLock'] = self.env['input']['newScrollLock']
self.env['input']['newScrollLock'] = self.env['runtime']['inputDriver'].getScrollLock() self.env['input']['newScrollLock'] = self.env['runtime']['inputDriver'].getLedState(2)
self.env['runtime']['debug'].writeDebugOut("currInput " + str(self.env['input']['currInput'] ) ,debug.debugLevel.INFO) self.env['runtime']['debug'].writeDebugOut("currInput " + str(self.env['input']['currInput'] ) ,debug.debugLevel.INFO)
if self.noKeyPressed(): if self.noKeyPressed():
self.env['input']['prevInput'] = [] self.env['input']['prevInput'] = []
self.setLedState = True
return eventReceived return eventReceived
def handleLedStates(self, mEvent):
if not self.setLedState:
return
if mEvent['EventName'] == 'KEY_NUMLOCK':
if mEvent['EventState'] == 1 and not self.env['input']['newNumLock'] == 1:
self.env['runtime']['inputDriver'].toggleLedState()
self.setLedState = False
return
if mEvent['EventState'] == 0 and not self.env['input']['newNumLock'] == 0:
self.env['runtime']['inputDriver'].toggleLedState()
self.setLedState = False
return
if mEvent['EventName'] == 'KEY_CAPSLOCK':
if mEvent['EventState'] == 1 and not self.env['input']['newCapsLock'] == 1:
self.env['runtime']['inputDriver'].toggleLedState(1)
self.setLedState = False
return
if mEvent['EventState'] == 0 and not self.env['input']['newCapsLock'] == 0:
self.env['runtime']['inputDriver'].toggleLedState(1)
self.setLedState = False
return
if mEvent['EventName'] == 'KEY_SCROLLLOCK':
if mEvent['EventState'] == 1 and not self.env['input']['newScrollLock'] == 1:
self.env['runtime']['inputDriver'].toggleLedState(2)
self.setLedState = False
return
if mEvent['EventState'] == 0 and not self.env['input']['newScrollLock'] == 0:
self.env['runtime']['inputDriver'].toggleLedState(2)
self.setLedState = False
return
def grabDevices(self): def grabDevices(self):
if self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'): if self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'):
self.env['runtime']['inputDriver'].grabDevices() self.env['runtime']['inputDriver'].grabDevices()

View File

@ -35,15 +35,16 @@ class driver():
for fd in r: for fd in r:
event = self.iDevices[fd].read_one() event = self.iDevices[fd].read_one()
while(event): while(event):
if not event:
return None
self.env['input']['eventBuffer'].append( [self.iDevices[fd], self.uDevices[fd], event]) self.env['input']['eventBuffer'].append( [self.iDevices[fd], self.uDevices[fd], event])
if event.code != 0: if event.type == evdev.events.EV_KEY:
currMapEvent = self.env['runtime']['inputDriver'].mapEvent(event) if event.code != 0:
if not currMapEvent: currMapEvent = self.env['runtime']['inputDriver'].mapEvent(event)
return currMapEvent if not currMapEvent:
if currMapEvent['EventState'] in [0,1,2]: return currMapEvent
return currMapEvent if currMapEvent['EventState'] in [0,1,2]:
return currMapEvent
event = self.iDevices[fd].read_one() event = self.iDevices[fd].read_one()
return None return None
@ -97,33 +98,24 @@ class driver():
except Exception as e: except Exception as e:
return None return None
def getNumlock(self): def getLedState(self, led = 0):
if self.ledDevices == {}: # 0 = Numlock
return True # 1 = Capslock
if self.ledDevices == None: # 2 = Rollen
return True
for fd, dev in self.ledDevices.items():
return 0 in dev.leds()
return True
def getCapslock(self):
if self.ledDevices == {}: if self.ledDevices == {}:
return False return False
if self.ledDevices == None: if self.ledDevices == None:
return False return False
for fd, dev in self.ledDevices.items(): for fd, dev in self.ledDevices.items():
return 1 in dev.leds() return led in dev.leds()
return False return False
def toggleLedState(self, led = 0):
def getScrollLock(self): ledState = self.getLedState(led)
if self.ledDevices == {}: for i in self.ledDevices:
return False if ledState == 1:
if self.ledDevices == None: self.ledDevices[i].set_led(led , 0)
return False else:
for fd, dev in self.ledDevices.items(): self.ledDevices[i].set_led(led , 1)
return 2 in dev.leds()
return False
def grabDevices(self): def grabDevices(self):
# leve the old code until the new one is better tested # leve the old code until the new one is better tested
# for fd in self.iDevices: # for fd in self.iDevices:

View File

@ -7,6 +7,9 @@ import time
devices = map(evdev.InputDevice, (evdev.list_devices())) devices = map(evdev.InputDevice, (evdev.list_devices()))
devices = {dev.fd: dev for dev in devices} devices = {dev.fd: dev for dev in devices}
for fd in devices:
for i in devices[fd].capabilities(True):
print(devices[fd].fn,devices[fd].name,i)
while True: while True:
r, w, x = select(devices, [], []) r, w, x = select(devices, [], [])
if r != []: if r != []: