Module Keyboard :: Class Keyboard
[hide private]
[frames] | no frames]

Class Keyboard

source code

AccessEngine.AEInput.SystemInput --+
                                   |
                                  Keyboard

Basic keyboard input device.

Has a reference to the AEEventManager to register for system wide keyboard key press and key release events. Matches key presses against a collection of stored AEInput.Gestures representing key combinations that should be filtered before they can reach the window with the input focus. Observers of this device are notified about AEInput.Gestures when one or more press events are received followed by a release.

Instances of Keyboard impose some constraints on the filters that can be registered. A filter can contain at most one AEInput.Gesture and that AEInput.Gesture may have at most MAX_KEY_CHORD key codes and at least one. The filtered gesture may start with zero, one, or two modifiers registered via SystemInput.addModifier and must end with exactly one non-modifier.

The Keyboard device is robust against typomatic repeats and more than MAX_KEY_CHORD sustained presses. Typomatic repeats are ignored so that holding two modifier keys, holding a typomatic key, releasing one of the modifiers, and then releasing the typomatic key does not result in two notifications. Key presses beyond the maximum number are also ignored without affecting the current state.

Instance Methods [hide private]
 
init(self)
Initializes the empty filters dictionary and creates an empty AEInput.Gesture that will be used to buffer incoming keystrokes until the AEInput.Gesture definitely matches or does not match one of the held filters.
source code
 
close(self)
Informs the AccessEngine.AEEventManager that notifications about keyboard events are no longer of interest to this Keyboard device.
source code
list of string
getCapabilities(self)
Gets the list of capabilities provided by this device, namely 'keyboard.'
source code
 
addFilter(self, key_filter)
Adds a AEInput.GestureList to the collection of filters.
source code
 
removeFilter(self, key_filter)
Removes a AEInput.GestureList from the collection of filters.
source code
 
clearFilters(self)
Removes all filters by destroying the dictionary and recreating it.
source code
integer
getMaxActions(self)
Gets the maximum AEInput.Gesture chord length as defined by MAX_KEY_CHORD.
source code
string
getName(self)
Gets the name of this input device.
source code
 
resetState(self)
Resets the state of the Keyboard by clearing out the curr_gesture and returning to _stateInvalid.
source code
 
_debug(self, header, code, event, press) source code
boolean
_hasOneModifier(self, gesture)
Peeks in the given gestures to see if it contains at least one modifier.
source code
boolean
_hasOnlyModifiers(self, gesture)
Peeks in the given gesture to see if it contains only modifiers.
source code
 
_sendGesture(self, gesture, press)
Synthesizes key strokes for the key codes in the given AEInput.Gesture.
source code
 
_sendKey(self, hw_code, press)
Synthesizes a single key stroke.
source code
 
_consumeKey(self, event, press)
Consumes the given event as long as it is not a special key used by other system services for accessibility purposes such as shift for slow keys and sticky keys.
source code
 
_handleStateful(self, event, press)
Handles the use of stateful keys such as caps lock, num lock, and scroll lock as modifiers.
source code
callable
_statePossible(self, event, press)
Represents a state where the current key codes in curr_gesture and the next key press may lead to a match on one of the registered filters.
source code
callable
_stateInvalid(self, event, press)
Represents a state where the current key codes in curr_gesture and the next key event is not likely to match one of the registered filters.
source code
callable
_stateMatch(self, event, press)
Represents a state where the current key codes in curr_gesture matches one of the filters and the next event may determine if the key codes in curr_gesture are consumed forever or synthesized to be passed on to the OS.
source code
callable
_stateAfterMatch(self, event, press)
Represents a state where the the keys in curr_gesture just matched one of the filters and the next event was a release of one of the modifier keys instead of the non-modifier.
source code
 
_onKeyPressed(self, event)
Handles a key press event by acting on the hardware key code in event.hw_code.
source code
 
_onKeyReleased(self, event)
Handles a key release event by acting on the hardware key code in event.hw_code.
source code
 
_onForegroundChange(self, event)
Resets the internal key state on a window:activate event.
source code
string
asString(self, gesture)
Gets a string representation of all of the key codes in the given AEInput.Gesture using the _keyCodeToKeyName function
source code
Class Variables [hide private]
  AEK_ESCAPE = 9
  AEK_QUESTION = 20
  AEK_F1 = 67
  AEK_F2 = 68
  AEK_F3 = 69
  AEK_F4 = 70
  AEK_F5 = 71
  AEK_F6 = 72
  AEK_F7 = 73
  AEK_F8 = 74
  AEK_F9 = 75
  AEK_F10 = 76
  AEK_F11 = 95
  AEK_F12 = 96
  AEK_PRINT_SCREEN = 111
  AEK_SCROLL_LOCK = 78
  AEK_PAUSE = 110
  AEK_TILDE = 49
  AEK_1 = 10
  AEK_2 = 11
  AEK_3 = 12
  AEK_4 = 13
  AEK_5 = 14
  AEK_6 = 15
  AEK_7 = 16
  AEK_8 = 17
  AEK_9 = 18
  AEK_0 = 19
  AEK_MINUS = 20
  AEK_EQUALS = 21
  AEK_BACK_SPACE = 22
  AEK_TAB = 23
  AEK_Q = 24
  AEK_W = 25
  AEK_E = 26
  AEK_R = 27
  AEK_T = 28
  AEK_Y = 29
  AEK_U = 30
  AEK_I = 31
  AEK_O = 32
  AEK_P = 33
  AEK_OPEN_BRACKET = 34
  AEK_CLOSE_BRACKET = 35
  AEK_BACK_SLASH = 51
  AEK_CAPS_LOCK = 66
  AEK_A = 38
  AEK_S = 39
  AEK_D = 40
  AEK_F = 41
  AEK_G = 42
  AEK_H = 43
  AEK_J = 44
  AEK_K = 45
  AEK_L = 46
  AEK_SEMICOLON = 47
  AEK_QUOTE = 48
  AEK_ENTER = 36
  AEK_SHIFT_L = 50
  AEK_Z = 52
  AEK_X = 53
  AEK_C = 54
  AEK_V = 55
  AEK_B = 56
  AEK_N = 57
  AEK_M = 58
  AEK_COMMA = 59
  AEK_PERIOD = 60
  AEK_SLASH = 61
  AEK_SHIFT_R = 62
  AEK_CONTROL_L = 37
  AEK_ALT_L = 64
  AEK_SPACE = 65
  AEK_ALT_R = 113
  AEK_MENU = 117
  AEK_CONTROL_R = 109
  AEK_LEFT = 100
  AEK_RIGHT = 102
  AEK_UP = 98
  AEK_DOWN = 104
  AEK_PAGE_DOWN = 105
  AEK_PAGE_UP = 99
  AEK_DELETE = 107
  AEK_INSERT = 106
  AEK_HOME = 97
  AEK_END = 103
  AEK_NUM_LOCK = 77
  AEK_DIVIDE = 112
  AEK_MULTIPLY = 63
  AEK_ADD = 86
  AEK_SUBTRACT = 82
  AEK_DECIMAL = 91
  AEK_NUMPAD0 = 90
  AEK_NUMPAD1 = 87
  AEK_NUMPAD2 = 88
  AEK_NUMPAD3 = 89
  AEK_NUMPAD4 = 83
  AEK_NUMPAD5 = 84
  AEK_NUMPAD6 = 85
  AEK_NUMPAD7 = 79
  AEK_NUMPAD8 = 80
  AEK_NUMPAD9 = 81
  AEK_NUMPAD_ENTER = 108
  AEK_THINKPAD_FN = 227
  AEK_THINKPAD_BACK = 234
  AEK_THINKPAD_FORWARD = 233
Instance Variables [hide private]
list of integer ACC_KEYS
Key codes for keys that should never be consumed because they activate accessibility features such as slow keys or sticky keys
list of AEInput.Gesture EATEN_GESTURES
List of gestures commonly eaten by a party higher than this device in the AT-SPI event chain (e.g.
list of integer LOCK_KEYS
Key codes for keys that can be locked in a particular state, namely AEK_CAPS_LOCK, AEK_SCROLL_LOCK, and AEK_NUM_LOCK.
pyatspi.Registry acc_reg
Reference to the pyatspi.Registry
AEInput.Gesture curr_gesture
Actions seen so far that might form a filtered AEInput.Gesture
dictionary keyed by AEInput.Gestures filters
Registered AEInput.GestureList filters keyed by the one and only one AEInput.Gesture allowed in each filter
boolean last_press
Was the last event a press (True) or release (False)?
callable state
Current state method for the key event handling state machine
list synth_press
Ordered list of synthesized key presses that have been sent for processing and should be ignored when detected
list synth_release
Ordered list of synthesized key releases that have been sent for processing and should be ignored when detected
Method Details [hide private]

init(self)

source code 
Initializes the empty filters dictionary and creates an empty AEInput.Gesture that will be used to buffer incoming keystrokes until the AEInput.Gesture definitely matches or does not match one of the held filters. Registers for key press and release events via pyatspi. Sets the filtering mode to handled by default. Also registers for window activate events to account for missing keys caused by system wide hotkey presses.

close(self)

source code 
Informs the AccessEngine.AEEventManager that notifications about keyboard events are no longer of interest to this Keyboard device. Sets the filtering mode to none for good measure. Removes the request for focus events also.

getCapabilities(self)

source code 
Gets the list of capabilities provided by this device, namely 'keyboard.'
Returns: list of string
'keyboard' as the only capability of this device.

addFilter(self, key_filter)

source code 

Adds a AEInput.GestureList to the collection of filters. The fire AEInput.Gesture in the AEInput.GestureList will be used when the mode is set to filter handled to prevent keys consumed by SUE from reaching the foreground application.

The Keyboard input device only supports one AEInput.Gesture per filter, not a sequence of AEInput.Gestures, and only one non-modifier key code per AEInput.Gesture chord. Any AEInput.GestureList breaking these rules will cause this method to raise a ValueError.
Parameters:
Raises:
  • ValueError - When the given AEInput.GestureList does not conform to the rules set forth above

removeFilter(self, key_filter)

source code 
Removes a AEInput.GestureList from the collection of filters.
Parameters:
Raises:

getMaxActions(self)

source code 
Gets the maximum AEInput.Gesture chord length as defined by MAX_KEY_CHORD.
Returns: integer
Maximum AEInput.Gesture chord length

getName(self)

source code 
Gets the name of this input device.
Returns: string
Localized device name

_hasOneModifier(self, gesture)

source code 
Peeks in the given gestures to see if it contains at least one modifier.
Parameters:
Returns: boolean
Does the gesture contain at least one modifier?

_hasOnlyModifiers(self, gesture)

source code 
Peeks in the given gesture to see if it contains only modifiers.
Parameters:
Returns: boolean
Does the gesture contain at least one non-modifier?

_sendGesture(self, gesture, press)

source code 
Synthesizes key strokes for the key codes in the given AEInput.Gesture. The presses are noted in synth_press and synth_release so that they can be ignored when they are seen in _onKeyPressed or _onKeyReleased to avoid duplicate processing.
Parameters:
  • press (boolean) - Synthesize key presses (True) or releases (False)?
  • gesture (AEInput.Gesture) - Gesture containing key codes to be pressed

_sendKey(self, hw_code, press)

source code 
Synthesizes a single key stroke. The presses are noted in synth_press and synth_release so that they can be ignored when they are seen in _onKeyPressed or _onKeyReleased to avoid duplicate processing.
Parameters:
  • hw_code (integer) - Keycode of the key to generate
  • press (boolean) - Synthesize key press (True) or releas (False)?

_consumeKey(self, event, press)

source code 
Consumes the given event as long as it is not a special key used by other system services for accessibility purposes such as shift for slow keys and sticky keys.
Parameters:
  • event (pyatspi.event.DeviceEvent) - Keyboard event
  • press (boolean) - Press or release event?

_handleStateful(self, event, press)

source code 
Handles the use of stateful keys such as caps lock, num lock, and scroll lock as modifiers. When a lock key is pressed, this method immediately sets it back to its former state. When a lock key is released, this method allows the change to pass but only if all of the conditions are met:
  • The lock key was the only key in the curr_gesture since it was last empty.
  • The lock key is not a gesture itself.
  • The lock key is currently the only key in the curr_gesture.
Parameters:
  • event (pyatspi.event.DeviceEvent) - Keyboard event
  • press (boolean) - Was the event a press (True) or release (False)?

_statePossible(self, event, press)

source code 

Represents a state where the current key codes in curr_gesture and the next key press may lead to a match on one of the registered filters. The actions in this state are as follows.

If the event is a press or release of one of the registered SystemInput.modifiers, the key is consumed and we remain in this state.

If the event is a press of a non-modifier and the curr_gesture matches one of the registered filters, we consume the key and transition to _stateMatch.

If the event is anything else, we synthesize all keys in the curr_gesture, consume the current event, and transition to _stateInvalid.
Parameters:
  • event (pyatspi.event.DeviceEvent) - Keyboard event
  • press (boolean) - Was the event a press (True) or release (False)?
Returns: callable
Method representing the next state

_stateInvalid(self, event, press)

source code 

Represents a state where the current key codes in curr_gesture and the next key event is not likely to match one of the registered filters. The actions in this state are as follows.

If the event is a press resulting in the curr_gesture having only SystemInput.modifiers in it, we consume the press and transition to _statePossible.

If the event is a press resulting in the curr_gesture exactly matching one of the registered filters, we consume the press transition to _stateMatch.

If the event is anything else, we allow the event to pass and stay in this state.
Parameters:
  • event (pyatspi.event.DeviceEvent) - Keyboard event
  • press (boolean) - Was the event a press (True) or release (False)?
Returns: callable
Method representing the next state

_stateMatch(self, event, press)

source code 

Represents a state where the current key codes in curr_gesture matches one of the filters and the next event may determine if the key codes in curr_gesture are consumed forever or synthesized to be passed on to the OS. The actions in this state are as follows.

If the event is a press and curr_gesture matches one of the filters, we stay in this state. (This case is needed to handle repeating, typomatic presses of non-modifier keys.)

If the event is a press and curr_gesture no longer matches one of the filters, we synthesize key presses for all keys in curr_gesture, consume the current press, and transition to _stateInvalid.

If the event is a release of one of the SystemInput.modifiers, we consume the release and move to _stateAfterMatch.

If the event is anything else (i.e. a non-modifier release), we consume the key and transition to _statePossible.
Parameters:
  • event (pyatspi.event.DeviceEvent) - Keyboard event
  • press (boolean) - Was the event a press (True) or release (False)?
Returns: callable
Method representing the next state

_stateAfterMatch(self, event, press)

source code 

Represents a state where the the keys in curr_gesture just matched one of the filters and the next event was a release of one of the modifier keys instead of the non-modifier. This state is needed to avoid typomatic repeat presses of the still held non-modifier key. The actions in this state are as follows.

If the event is a release of a non-modifier and the curr_gesture is now empty, we consume the release and move to _stateInvalid.

If the event is a release of one of the non-modifiers and the curr_gesture still contains key strokes (e.g. SystemInput.modifiers), we consume the release and move to _statePossible.
Parameters:
  • event (pyatspi.event.DeviceEvent) - Keyboard event
  • press (boolean) - Was the event a press (True) or release (False)?
Returns: callable
Method representing the next state

_onKeyPressed(self, event)

source code 
Handles a key press event by acting on the hardware key code in event.hw_code. If the key code is at the top of the synth_press list, then the press is ignored since it was synthesized and that code is removed from the list. Otherwise, an attempt is made to add the key code to the curr_gesture. If the current gesture is full, the press is ignored and the method returns immediately. If not, the event is dispatched to the current state method (one of _statePossible, _stateInvalid, _stateMatch). The return value of the state method is set as the next state and the last_press flag is set to True.
Parameters:
  • event (pyatspi.event.DeviceEvent) - Keyboard key press event

_onKeyReleased(self, event)

source code 
Handles a key release event by acting on the hardware key code in event.hw_code. If the key code is at the top of the synth_release list, then the release is ignored since it was synthesized and that code is removed from the list. Otherwise, the last_press flag is checked to see if it is True indicating the last event was a key press. If so, the curr_gesture is copied into a new AEInput.Gesture and sent to any listeners via the AEInput.SystemInput._notifyInputListeners method. Next an attempt is made to remove the key code from the curr_gesture. If the key code does not exist, the release is ignored and the method returns immediately. If not, the event is dispatched to the current state method (one of _statePossible, _stateInvalid, _stateMatch). The return value of the state method is set as the next state and the last_press flag is set to False.
Parameters:
  • event (pyatspi.event.DeviceEvent) - Keyboard key release event

_onForegroundChange(self, event)

source code 
Resets the internal key state on a window:activate event. This is needed to resolve the problem of system wide hotkey releases going missing.
Parameters:
  • event (pyatspi.event.DeviceEvent) - Keyboard key release event

asString(self, gesture)

source code 
Gets a string representation of all of the key codes in the given AEInput.Gesture using the _keyCodeToKeyName function
Parameters:
Returns: string
String representation of the provided AEInput.Gesture

Instance Variable Details [hide private]

EATEN_GESTURES

List of gestures commonly eaten by a party higher than this device in the AT-SPI event chain (e.g. the window manager). This device should not synthesize these gestures when detected.
Type:
list of AEInput.Gesture

LOCK_KEYS

Key codes for keys that can be locked in a particular state, namely AEK_CAPS_LOCK, AEK_SCROLL_LOCK, and AEK_NUM_LOCK. These are constant.
Type:
list of integer