Skip to content

Commit 703409e

Browse files
committed
update control keyboard tutorial
1 parent e22de4a commit 703409e

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

Diff for: general/keyboard-controller/control_keyboard.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,21 @@
1010
# check if a ctrl is pressed
1111
print(keyboard.is_pressed('ctrl'))
1212

13-
# press space
13+
# press and release space
1414
keyboard.send("space")
1515

16+
# multi-key, windows+d as example shows the desktop in Windows machines
17+
keyboard.send("windows+d")
18+
19+
# send ALT+F4 in the same time, and then send space,
20+
# (be carful, this will close any current open window)
21+
keyboard.send("alt+F4, space")
22+
23+
# press CTRL button
24+
keyboard.press("ctrl")
25+
# release the CTRL button
26+
keyboard.release("ctrl")
27+
1628
# sends artificial keyboard events to the OS
1729
# simulating the typing of a given text
1830
# setting 0.1 seconds to wait between keypresses to look fancy
@@ -22,6 +34,11 @@
2234
events = keyboard.record('esc')
2335
# play these events
2436
keyboard.play(events)
37+
# print all typed strings in the events
38+
print(list(keyboard.get_typed_strings(events)))
39+
40+
# log all pressed keys
41+
keyboard.on_release(lambda e: print(e.name))
2542

2643
# remove all keyboard hooks in use
2744
keyboard.unhook_all()

0 commit comments

Comments
 (0)