Skip to content

Commit 1f8c5ad

Browse files
authored
Merge pull request #875 from edgar-bonet/kbd-rewrite
Rewrite keyboardModifiers.adoc
2 parents 651be59 + eba85e4 commit 1f8c5ad

File tree

1 file changed

+55
-30
lines changed

1 file changed

+55
-30
lines changed

Language/Functions/USB/Keyboard/keyboardModifiers.adoc

Lines changed: 55 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,57 +14,82 @@ title: Keyboard Modifiers and Special Keys
1414

1515
[float]
1616
=== 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).
1831
[%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:
2033

2134
[float]
2235
=== 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.
3037

3138
|===
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
4249
|===
4350

4451
[float]
4552
=== 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.
4754

48-
The following special keys have been defined:
55+
[float]
56+
==== Within the alphanumeric cluster
4957

5058
|===
5159
|Key |Hexadecimal value |Decimal value
5260

53-
|KEY_UP_ARROW |0xDA |218
54-
|KEY_DOWN_ARROW |0xD9 |217
55-
|KEY_LEFT_ARROW |0xD8 |216
56-
|KEY_RIGHT_ARROW |0xD7 |215
57-
|KEY_BACKSPACE |0xB2 |178
5861
|KEY_TAB |0xB3 |179
62+
|KEY_CAPS_LOCK |0xC1 |193
63+
|KEY_BACKSPACE |0xB2 |178
5964
|KEY_RETURN |0xB0 |176
60-
|KEY_ESC |0xB1 |177
65+
|===
66+
67+
[float]
68+
==== Navigation cluster
69+
70+
|===
71+
|Key |Hexadecimal value |Decimal value
72+
6173
|KEY_INSERT |0xD1 |209
6274
|KEY_DELETE |0xD4 |212
63-
|KEY_PAGE_UP |0xD3 |211
64-
|KEY_PAGE_DOWN |0xD6 |214
6575
|KEY_HOME |0xD2 |210
6676
|KEY_END |0xD5 |213
67-
|KEY_CAPS_LOCK |0xC1 |193
77+
|KEY_PAGE_UP |0xD3 |211
78+
|KEY_PAGE_DOWN |0xD6 |214
79+
|KEY_UP_ARROW |0xDA |218
80+
|KEY_DOWN_ARROW |0xD9 |217
81+
|KEY_LEFT_ARROW |0xD8 |216
82+
|KEY_RIGHT_ARROW |0xD7 |215
83+
|===
84+
85+
[float]
86+
==== Escape and function keys
87+
The library can simulate function keys up to F24.
88+
89+
|===
90+
|Key |Hexadecimal value |Decimal value
91+
92+
|KEY_ESC |0xB1 |177
6893
|KEY_F1 |0xC2 |194
6994
|KEY_F2 |0xC3 |195
7095
|KEY_F3 |0xC4 |196

0 commit comments

Comments
 (0)