relay: send modifier codes
This commit is contained in:
parent
f5fe04735b
commit
c100f78af6
57
relay.py
57
relay.py
@ -165,14 +165,18 @@ scan_to_hid = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
LEFT_CTRL = 1 << 0
|
modifiers = {
|
||||||
LEFT_SHIFT = 1 << 1
|
evdev.ecodes.KEY_LEFTCTRL: 1 << 0,
|
||||||
LEFT_ALT = 1 << 2
|
evdev.ecodes.KEY_LEFTSHIFT: 1 << 1,
|
||||||
LEFT_GUI = 1 << 3
|
evdev.ecodes.KEY_LEFTALT: 1 << 2,
|
||||||
RIGHT_CTRL = 1 << 4
|
evdev.ecodes.KEY_LEFTMETA: 1 << 3,
|
||||||
RIGHT_SHIFT = 1 << 5
|
|
||||||
RIGHT_ALT = 1 << 6
|
evdev.ecodes.KEY_RIGHTCTRL: 1 << 4,
|
||||||
RIGHT_GUI = 1 << 7
|
evdev.ecodes.KEY_RIGHTSHIFT: 1 << 5,
|
||||||
|
evdev.ecodes.KEY_RIGHTALT: 1 << 6,
|
||||||
|
evdev.ecodes.KEY_RIGHTMETA: 1 << 7,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
@ -196,26 +200,31 @@ if __name__ == '__main__':
|
|||||||
data = evdev.categorize(event)
|
data = evdev.categorize(event)
|
||||||
print("Got key", data.scancode)
|
print("Got key", data.scancode)
|
||||||
|
|
||||||
|
modifier = modifiers.get(data.scancode, None)
|
||||||
|
if modifier:
|
||||||
code = scan_to_hid.get(data.scancode, None)
|
if data.keystate == data.key_down:
|
||||||
if code is None:
|
modifier_state |= modifier
|
||||||
print("Ignoring unknown key")
|
if data.keystate == data.key_up:
|
||||||
continue
|
modifier_state &= ~modifier
|
||||||
|
else:
|
||||||
if data.keystate == data.key_down:
|
code = scan_to_hid.get(data.scancode, None)
|
||||||
if len(keys_down) >= 6:
|
if code is None:
|
||||||
print("Ignoring key due to rollover")
|
print("Ignoring unknown key")
|
||||||
continue
|
continue
|
||||||
print("Adding key")
|
|
||||||
keys_down.add(code)
|
|
||||||
|
|
||||||
if data.keystate == data.key_up:
|
if data.keystate == data.key_down:
|
||||||
print("Removing key")
|
if len(keys_down) >= 6:
|
||||||
keys_down.remove(code)
|
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
|
# 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))
|
packet += [0] * (8 - len(packet))
|
||||||
|
|
||||||
assert(len(packet) == 8)
|
assert(len(packet) == 8)
|
||||||
|
Loading…
Reference in New Issue
Block a user