relay: send modifier codes
This commit is contained in:
parent
f5fe04735b
commit
c100f78af6
31
relay.py
31
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,8 +200,13 @@ 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:
|
||||||
|
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)
|
code = scan_to_hid.get(data.scancode, None)
|
||||||
if code is None:
|
if code is None:
|
||||||
print("Ignoring unknown key")
|
print("Ignoring unknown key")
|
||||||
@ -215,7 +224,7 @@ if __name__ == '__main__':
|
|||||||
keys_down.remove(code)
|
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