forked from tuomasjjrasanen/python-uinput
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeyboard.py
executable file
·31 lines (27 loc) · 1.13 KB
/
keyboard.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import time
import uinput
def main():
events = (
uinput.KEY_E,
uinput.KEY_H,
uinput.KEY_L,
uinput.KEY_O,
)
with uinput.Device(events) as device:
time.sleep(1) # This is required here only for demonstration
# purposes. Without this, the underlying machinery might
# not have time to assign a proper handler for our device
# before the execution of this script reaches the end and
# the device is destroyed. At least this seems to be the
# case with X11 and its generic event device
# handlers. Without this magical sleep, "hello" might not
# get printed because this example exits before X11 gets
# its handlers ready for processing events from this
# device.
device.emit_click(uinput.KEY_H)
device.emit_click(uinput.KEY_E)
device.emit_click(uinput.KEY_L)
device.emit_click(uinput.KEY_L)
device.emit_click(uinput.KEY_O)
if __name__ == "__main__":
main()