relay: send modifier codes

This commit is contained in:
Danny Robson 2019-02-23 13:51:35 +11:00
parent f5fe04735b
commit c100f78af6

View File

@ -165,14 +165,18 @@ scan_to_hid = {
}
LEFT_CTRL = 1 << 0
LEFT_SHIFT = 1 << 1
LEFT_ALT = 1 << 2
LEFT_GUI = 1 << 3
RIGHT_CTRL = 1 << 4
RIGHT_SHIFT = 1 << 5
RIGHT_ALT = 1 << 6
RIGHT_GUI = 1 << 7
modifiers = {
evdev.ecodes.KEY_LEFTCTRL: 1 << 0,
evdev.ecodes.KEY_LEFTSHIFT: 1 << 1,
evdev.ecodes.KEY_LEFTALT: 1 << 2,
evdev.ecodes.KEY_LEFTMETA: 1 << 3,
evdev.ecodes.KEY_RIGHTCTRL: 1 << 4,
evdev.ecodes.KEY_RIGHTSHIFT: 1 << 5,
evdev.ecodes.KEY_RIGHTALT: 1 << 6,
evdev.ecodes.KEY_RIGHTMETA: 1 << 7,
}
if __name__ == '__main__':
@ -196,26 +200,31 @@ if __name__ == '__main__':
data = evdev.categorize(event)
print("Got key", data.scancode)
code = scan_to_hid.get(data.scancode, None)
if code is None:
print("Ignoring unknown key")
continue
if data.keystate == data.key_down:
if len(keys_down) >= 6:
print("Ignoring key due to rollover")
modifier = modifiers.get(data.scancode, None)
if modifier:
if data.keystate == data.key_down:
modifier_state |= modifier
if data.keystate == data.key_up:
modifier_state &= ~modifier
else:
code = scan_to_hid.get(data.scancode, None)
if code is None:
print("Ignoring unknown key")
continue
print("Adding key")
keys_down.add(code)
if data.keystate == data.key_up:
print("Removing key")
keys_down.remove(code)
if data.keystate == data.key_down:
if len(keys_down) >= 6:
print("Ignoring key due to rollover")
continue
print("Adding key")
keys_down.add(code)
if data.keystate == data.key_up:
print("Removing key")
keys_down.remove(code)
# Build the packet
packet = [0] + [0] + [k for k in keys_down]
packet = [modifier_state, 0] + [k for k in keys_down]
packet += [0] * (8 - len(packet))
assert(len(packet) == 8)