From 5ee9dca99eb40339ab228bf9e4eb035f8a7351ee Mon Sep 17 00:00:00 2001 From: chrys Date: Thu, 7 Jul 2016 21:40:10 +0200 Subject: [PATCH] initial key handling --- src/fenrir-package/core/environment.py | 4 +++- src/fenrir-package/core/inputManager.py | 21 ++++++++++++++++++--- src/fenrir-package/fenrir.py | 11 ++++++++++- src/fenrir-package/utils/debug.py | 1 + 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/fenrir-package/core/environment.py b/src/fenrir-package/core/environment.py index 3255b2c2..d53e9676 100644 --- a/src/fenrir-package/core/environment.py +++ b/src/fenrir-package/core/environment.py @@ -2,9 +2,10 @@ runtime = { 'running':True, +'debug':None, 'columns': 0, 'lines': 0, -'screenDriver': '/dev/vcsa', +'screenDriver': None, 'delta': '', 'oldCursor':{'x':0,'y':0}, 'oldContentBytes': b'', @@ -22,6 +23,7 @@ runtime = { 'screenDriver': None, 'soundDriverString': '', 'soundDriver': None, +'inputManager': None } settings = { diff --git a/src/fenrir-package/core/inputManager.py b/src/fenrir-package/core/inputManager.py index 0ba0ee13..8f4fb533 100644 --- a/src/fenrir-package/core/inputManager.py +++ b/src/fenrir-package/core/inputManager.py @@ -1,9 +1,24 @@ #!/bin/python +import evdev +from evdev import InputDevice +from select import select + class inputManager(): def __init__(self): - pass + self.devices = map(evdev.InputDevice, (evdev.list_devices())) + self.devices = {dev.fd: dev for dev in self.devices} + for dev in self.devices.values(): print(dev) - def getCommandQueue(self, runtime): - return[] + def getShortcutCommand(self, runtime, shortcuts): + if not shortcuts: + return '' + return '' + + def getKeyPressed(self, runtime): + r, w, x = select(self.devices, [], []) + for fd in r: + for event in self.devices[fd].read(): + if event.type == evdev.ecodes.EV_KEY: + print(evdev.categorize(event)) diff --git a/src/fenrir-package/fenrir.py b/src/fenrir-package/fenrir.py index be71f72a..97b43205 100755 --- a/src/fenrir-package/fenrir.py +++ b/src/fenrir-package/fenrir.py @@ -5,12 +5,16 @@ import os, sys +DEBUG = False + if not os.getcwd() in sys.path: sys.path.append(os.getcwd()) from core import environment +from core import inputManager from utils import debug + from speech import espeak as es from speech import speechd as sd from screen import linux as lx @@ -18,11 +22,15 @@ from screen import linux as lx class fenrir(): def __init__(self): self.runtime = environment.runtime + self.runtime['inputManager'] = inputManager.inputManager() + if DEBUG: + self.runtime['debug'] = debug.debug() self.settings = environment.settings self.bindings = {} self.autospeak = [] self.soundIcons = {} - + + # the following hard coded, in future we have a config loader self.runtime['speechDriverString'] = 'speechd' self.runtime['speechDriver'] = sd.speech() self.runtime['screenDriverString'] = 'linux' @@ -31,6 +39,7 @@ class fenrir(): def proceed(self): while(self.runtime['running']): self.runtime = self.runtime['screenDriver'].analyzeScreen(self.runtime) + self.runtime['inputManager'].getKeyPressed(self.runtime) def shutdown(self): pass diff --git a/src/fenrir-package/utils/debug.py b/src/fenrir-package/utils/debug.py index 116e37e6..31affea1 100644 --- a/src/fenrir-package/utils/debug.py +++ b/src/fenrir-package/utils/debug.py @@ -1,6 +1,7 @@ #!/usr/bin/python # Debugger module for the Fenrir screen reader. + ERROR = 0 WARNING = 1 INFO = 2