|
|
|
@ -24,6 +24,9 @@
|
|
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
|
|
import evdev
|
|
|
|
|
|
|
|
|
|
from keymapper.logger import update_verbosity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -31,54 +34,9 @@ tmp = '/tmp/key-mapper-test'
|
|
|
|
|
uinput_write_history = []
|
|
|
|
|
pending_events = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_events():
|
|
|
|
|
"""Get all events written by the injector."""
|
|
|
|
|
return uinput_write_history
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def push_event(device, event):
|
|
|
|
|
"""Emit a fake event for a device.
|
|
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
|
----------
|
|
|
|
|
device : string
|
|
|
|
|
For example 'device 1'
|
|
|
|
|
event : Event
|
|
|
|
|
"""
|
|
|
|
|
if pending_events.get(device) is None:
|
|
|
|
|
pending_events[device] = []
|
|
|
|
|
pending_events[device].append(event)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Event:
|
|
|
|
|
"""Event to put into the injector for tests."""
|
|
|
|
|
def __init__(self, type, code, value):
|
|
|
|
|
"""
|
|
|
|
|
Paramaters
|
|
|
|
|
----------
|
|
|
|
|
type : int
|
|
|
|
|
one of evdev.ecodes.EV_*
|
|
|
|
|
code : int
|
|
|
|
|
keyboard event code as known to linux. E.g. 2 for the '1' button
|
|
|
|
|
value : int
|
|
|
|
|
1 for down, 0 for up, 2 for hold
|
|
|
|
|
"""
|
|
|
|
|
self.type = type
|
|
|
|
|
self.code = code
|
|
|
|
|
self.value = value
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def patch_paths():
|
|
|
|
|
from keymapper import paths
|
|
|
|
|
paths.CONFIG = '/tmp/key-mapper-test/'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def patch_evdev():
|
|
|
|
|
import evdev
|
|
|
|
|
# key-mapper is only interested in devices that have EV_KEY, add some
|
|
|
|
|
# random other stuff to test that they are ignored.
|
|
|
|
|
fixtures = {
|
|
|
|
|
# key-mapper is only interested in devices that have EV_KEY, add some
|
|
|
|
|
# random other stuff to test that they are ignored.
|
|
|
|
|
fixtures = {
|
|
|
|
|
# device 1
|
|
|
|
|
'/dev/input/event11': {
|
|
|
|
|
'capabilities': {evdev.ecodes.EV_KEY: [], evdev.ecodes.EV_ABS: []},
|
|
|
|
@ -122,8 +80,52 @@ def patch_evdev():
|
|
|
|
|
'phys': 'key-mapper/input1',
|
|
|
|
|
'name': 'key-mapper device 2'
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_events():
|
|
|
|
|
"""Get all events written by the injector."""
|
|
|
|
|
return uinput_write_history
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def push_event(device, event):
|
|
|
|
|
"""Emit a fake event for a device.
|
|
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
|
----------
|
|
|
|
|
device : string
|
|
|
|
|
For example 'device 1'
|
|
|
|
|
event : Event
|
|
|
|
|
"""
|
|
|
|
|
if pending_events.get(device) is None:
|
|
|
|
|
pending_events[device] = []
|
|
|
|
|
pending_events[device].append(event)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Event:
|
|
|
|
|
"""Event to put into the injector for tests."""
|
|
|
|
|
def __init__(self, type, code, value):
|
|
|
|
|
"""
|
|
|
|
|
Paramaters
|
|
|
|
|
----------
|
|
|
|
|
type : int
|
|
|
|
|
one of evdev.ecodes.EV_*
|
|
|
|
|
code : int
|
|
|
|
|
keyboard event code as known to linux. E.g. 2 for the '1' button
|
|
|
|
|
value : int
|
|
|
|
|
1 for down, 0 for up, 2 for hold
|
|
|
|
|
"""
|
|
|
|
|
self.type = type
|
|
|
|
|
self.code = code
|
|
|
|
|
self.value = value
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def patch_paths():
|
|
|
|
|
from keymapper import paths
|
|
|
|
|
paths.CONFIG = '/tmp/key-mapper-test/'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def patch_evdev():
|
|
|
|
|
def list_devices():
|
|
|
|
|
return fixtures.keys()
|
|
|
|
|
|
|
|
|
|