You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Language/Functions/USB/Keyboard/keyboardModifiers.adoc
+55-30Lines changed: 55 additions & 30 deletions
Original file line number
Diff line number
Diff line change
@@ -14,57 +14,82 @@ title: Keyboard Modifiers and Special Keys
14
14
15
15
[float]
16
16
=== Description
17
-
The `Keyboard.write()` and `Keyboard.press()` and `Keyboard.release()` commands don’t work with every possible ASCII character, only those that correspond to a key on the keyboard. For example, backspace works, but many of the other non-printable characters produce unpredictable results. For capital letters (and other keys), what’s sent is shift plus the character (i.e. the equivalent of pressing both of those keys on the keyboard).
17
+
When given a printable ASCII character as an argument, the functions `Keyboard.write()`, `Keyboard.press()` and `Keyboard.release()` simulate actuations on the corresponding keys. These functions can also handle ASCII characters that require pressing a key in combination with Shift or, on international keyboards, AltGr. For example:
18
+
[source,arduino]
19
+
----
20
+
Keyboard.write('a'); // press and release the 'A' key
21
+
Keyboard.write('A'); // press Shift and 'A', then release both
22
+
----
23
+
A typical keyboard, however, has many keys that do not match a printable ASCII character. In order to simulate those keys, the library provides a set of macros that can be passed as arguments to `Keyboard.write()`, `Keyboard.press()` and `Keyboard.release()`. For example, the key combination Shift+F2 can be generated by:
24
+
[source,arduino]
25
+
----
26
+
Keyboard.press(KEY_LEFT_SHIFT); // press and hold Shift
27
+
Keyboard.press(KEY_F2); // press and hold F2
28
+
Keyboard.releaseAll(); // release both
29
+
----
30
+
Note that, in order to press multiple keys simultaneously, one has to use link:../keyboardpress[`Keyboard.press()`] rather than link:../keyboardwrite[`Keyboard.write()`], as the latter just “hits” the keys (it presses and immediately releases them).
18
31
[%hardbreaks]
19
-
For more on ASCII values and the characters or functions they represent, see http://www.asciitable.com/[asciitable.com]
32
+
The available macros are listed below:
20
33
21
34
[float]
22
35
=== Keyboard modifiers
23
-
A modifier key is a special key on a computer keyboard that modifies the normal action of another key when the two are pressed in combination.
24
-
[%hardbreaks]
25
-
For multiple key presses use link:../keyboardpress[Keyboard.press]()
26
-
[%hardbreaks]
27
-
The definitions of the modifier keys are listed below:
28
-
[%hardbreaks]
29
-
36
+
These keys are meant to modify the normal action of another key when the two are pressed in combination.
30
37
31
38
|===
32
-
|Key |Hexadecimal value |Decimal value
33
-
34
-
|KEY_LEFT_CTRL |0x80 |128
35
-
|KEY_LEFT_SHIFT |0x81 |129
36
-
|KEY_LEFT_ALT |0x82 |130
37
-
|KEY_LEFT_GUI |0x83 |131
38
-
|KEY_RIGHT_CTRL |0x84 |132
39
-
|KEY_RIGHT_SHIFT |0x85 |133
40
-
|KEY_RIGHT_ALT |0x86 |134
41
-
|KEY_RIGHT_GUI |0x87 |135
39
+
|Key |Hexadecimal value |Decimal value |Notes
40
+
41
+
|KEY_LEFT_CTRL |0x80 |128 |
42
+
|KEY_LEFT_SHIFT |0x81 |129 |
43
+
|KEY_LEFT_ALT |0x82 |130 |Option (⌥) on Mac
44
+
|KEY_LEFT_GUI |0x83 |131 |OS logo, Command (⌘) on Mac
45
+
|KEY_RIGHT_CTRL |0x84 |132 |
46
+
|KEY_RIGHT_SHIFT |0x85 |133 |
47
+
|KEY_RIGHT_ALT |0x86 |134 |also AltGr, Option (⌥) on Mac
48
+
|KEY_RIGHT_GUI |0x87 |135 |OS logo, Command (⌘) on Mac
42
49
|===
43
50
44
51
[float]
45
52
=== Special keys
46
-
These are four keys within the alphanumeric cluster of a keyboard (Tab, Caps Lock, Backspace and Return) as well as all keys from outside that cluster (Escape, function keys, Home, End, arrow keys...).
53
+
These are all the keys that do not match a printable ASCII character and are not modifiers.
0 commit comments