Debian Codegraph @

docs/src/markdown/extensions/keys.md

raw
1 ---
2 icon: lucide/keyboard
3 ---
4 [:octicons-file-code-24:][_keys]{: .source-link }
5
6 # Keys
7
8 ## Overview
9
10 Keys is an extension to make entering and styling keyboard key presses easier. Syntactically, Keys is built around the
11 `+` symbol. A key or combination of key presses is surrounded by `++` with each key press separated with a single `+`.
12
13 ```text title="Keys"
14 ++ctrl+alt+delete++
15 ```
16
17 /// html | div.result
18 ++ctrl+alt+delete++.
19 ///
20
21 The Keys extension can be included in Python Markdown by using the following:
22
23 ```py3
24 import markdown
25 md = markdown.Markdown(extensions=['pymdownx.keys'])
26 ```
27
28 /// tip | Special Characters Before/After Key
29 You might have noticed that in this page many keys show special Unicode symbols before (and sometimes after) a key's
30 text. The Keys extension only provides ASCII labels out of the box. Any special Unicode characters that are seen in
31 this document are provided by using additional CSS.
32
33 If desired, you can provide your own symbols by doing one of the following:
34
35 1. You can use CSS styling. The elements are created with classes that are derived from the main key code name (not
36 the aliases) so that you can target them to provide special styling. Check out [Formatting](#formatting) for more
37 info.
38
39 2. You can also override the label that is output for the key by provided your own text via the `key_map`
40 parameter. This would require no additional CSS. More info is provided [here](#extendingmodifying-key-map-index).
41 ///
42
43 ## Formatting
44
45 By default, Keys outputs keys in the form:
46
47 ```html
48 <span class="keys">
49 <kbd class="key-ctrl">Ctrl</kbd>
50 <span>+</span>
51 <kbd class="key-alt">Alt</kbd>
52 <span>+</span>
53 <kbd class="key-delete">Delete</kbd>
54 </span>
55 ```
56
57 Separator `span`s will be omitted if a separator is not provided via the [options](#options).
58
59 Notice the wrapper `span` has the class `keys` applied to it. This is so you can target it or the elements under it
60 with CSS. Each recognized key has its own special key class assigned to it in the form `key-<key name>`. These
61 individual key classes are great if you want to show a special modifier key symbol before the key text (which is done in
62 this documentation).
63
64 The wrapper `keys` class can be customized with options, and the individual key classes are generated from the
65 [key-map index](#key-map-index).
66
67 separator `span`s will be omitted if a separator is not provided via the [options](#options))
68
69
70 ## Custom Keys
71
72 If you would like to generate a key which isn't in the key index, you can extend the key map via a special
73 [option](#extendingmodifying-key-map-index). But if you don't need a key with a special class generated, or you need a
74 way to quickly enter a one time, arbitrary key, you can just insert it directly, instead of specifying the key's name,
75 by quoting the content displayed instead of a key name. You can also enter HTML entities if desired.
76
77 ```text title="Quoted Keys"
78 ++ctrl+alt+"My Special Key"++
79
80 ++cmd+alt+"&Uuml;"++
81 ```
82
83 /// html | div.result
84 ++ctrl+alt+"My Special Key"++
85
86 ++cmd+alt+"&Uuml;"++
87 ///
88
89 ## Strict `KBD` Output
90
91 According to HTML5 spec on [`kbd`](https://dev.w3.org/html5/spec-preview/the-kbd-element.html), a literal key input, is
92 represented by a `kbd` wrapped in another `kbd`:
93
94 ```html
95 <kbd class="keys">
96 <kbd class="key-ctrl">Ctrl</kbd>
97 <span>+</span>
98 <kbd class="key-alt">Alt</kbd>
99 <span>+</span>
100 <kbd class="key-delete">Delete</kbd>
101 </kbd>
102 ```
103
104 This is not how many people traditionally use `kbd`s for key inputs, but if you are a stickler for rules, you can enable
105 the `strict` option to use a more "proper" format.
106
107 ## Key-Map Index
108
109 By default, Keys provides a key-map index for English US keyboards. The key-map index is a dictionary that provides all
110 the supported key names along with their corresponding display text. There is also a separate alias dictionary which
111 maps some aliases to entries in the key-map index.
112
113 ## Extending/Modifying Key-Map Index
114
115 If you want to add additional keys, or override text of existing keys, you can feed in your keys via the `key_map`
116 option. The `key_map` parameter takes a simple dictionary with *key names* that are represented by lowercase
117 alphanumeric characters and hyphens (`-`). The values of the dictionary represent the text that is displayed for the key
118 in the HTML output.
119
120 So if you wanted to add a custom key, you could do this: `#!py3 {"custom": "Custom Key"}`. If you wanted to override
121 the output of the `option` key and change it from `Option` to `Opt`, you could do this: `#!py3 {"option": "Opt"}`.
122
123 ### Alphanumeric and Space Keys
124
125 Name | Display | Aliases
126 ------- | --------- | -------
127 `0` | ++0++ |
128 `1` | ++1++ |
129 `2` | ++2++ |
130 `3` | ++3++ |
131 `4` | ++4++ |
132 `5` | ++5++ |
133 `6` | ++6++ |
134 `7` | ++7++ |
135 `8` | ++8++ |
136 `9` | ++9++ |
137 `a` | ++a++ |
138 `b` | ++b++ |
139 `c` | ++c++ |
140 `d` | ++d++ |
141 `e` | ++e++ |
142 `f` | ++f++ |
143 `g` | ++g++ |
144 `h` | ++h++ |
145 `i` | ++i++ |
146 `j` | ++j++ |
147 `k` | ++k++ |
148 `l` | ++l++ |
149 `m` | ++m++ |
150 `n` | ++n++ |
151 `o` | ++o++ |
152 `p` | ++p++ |
153 `q` | ++q++ |
154 `r` | ++r++ |
155 `s` | ++s++ |
156 `t` | ++t++ |
157 `u` | ++u++ |
158 `v` | ++v++ |
159 `w` | ++w++ |
160 `x` | ++x++ |
161 `y` | ++y++ |
162 `z` | ++z++ |
163 `space` | ++space++ | `spc`
164
165 ### Punctuation Keys
166
167 Name | Display | Aliases
168 --------------- | ----------------- | -------
169 `backslash` | ++backslash++ |
170 `bar` | ++bar++ | `pipe`
171 `brace-left` | ++brace-left++ | `open-brace`
172 `brace-right` | ++brace-right++ | `close-bracket`
173 `bracket-left` | ++bracket-left++ | `open-bracket`
174 `bracket-right` | ++bracket-right++ | `close-bracket`
175 `colon` | ++colon++ |
176 `comma` | ++comma++ |
177 `double-quote` | ++double-quote++ | `dblquote`
178 `equal` | ++equal++ |
179 `exclam` | ++exclam++ | `exclamation`
180 `grave` | ++grave++ | `grave-accent`
181 `greater` | ++greater++ | `greater-than`, `gt`
182 `less` | ++less++ | `less-than`, `lt`
183 `minus` | ++minus++ | `hyphen`
184 `period` | ++period++ |
185 `plus` | ++plus++ |
186 `question` | ++question++ | `question-mark`
187 `semicolon` | ++semicolon++ |
188 `single-quote` | ++single-quote++ |
189 `slash` | ++slash++ |
190 `tilde` | ++tilde++ |
191 `underscore` | ++underscore++ |
192
193 ### Navigation Keys
194
195 Name | Display | Aliases
196 ------------- | --------------- | -------
197 `arrow-up` | ++arrow-up++ | `up`
198 `arrow-down` | ++arrow-down++ | `down`
199 `arrow-left` | ++arrow-left++ | `left`
200 `arrow-right` | ++arrow-right++ | `right`
201 `page-up` | ++page-up++ | `prior`, `page-up`, `pg-up`
202 `page-down` | ++page-down++ | `next`, `page-dn`, `pg-dn`
203 `home` | ++home++ |
204 `end` | ++end++ |
205 `tab` | ++tab++ | `tabulator`
206
207 ### Editing Keys
208
209 Name | Display | Aliases
210 ----------- | ------------- | -------
211 `backspace` | ++backspace++ | `back`, `bksp`
212 `delete` | ++delete++ | `del`
213 `insert` | ++insert++ | `ins`
214
215 ### Action Keys
216 Name | Display | Aliases
217 -------------- | -----------------| -------
218 `break` | ++break++ | `cancel`
219 `caps-lock` | ++caps-lock++ | `capital`, `cplk`
220 `clear` | ++clear++ | `clr`
221 `eject` | ++eject++ |
222 `enter` | ++enter++ | `return`
223 `escape` | ++escape++ | `esc`
224 `help` | ++help++ |
225 `print-screen` | ++print-screen++ | `prtsc`
226 `scroll-lock` | ++scroll-lock++ | `scroll`
227
228 ### Numeric Keypad Keys
229
230 Name | Display | Aliases
231 --------------- | ----------------- | -------
232 `num0` | ++num0++ |
233 `num1` | ++num1++ |
234 `num2` | ++num2++ |
235 `num3` | ++num3++ |
236 `num4` | ++num4++ |
237 `num5` | ++num5++ |
238 `num6` | ++num6++ |
239 `num7` | ++num7++ |
240 `num8` | ++num8++ |
241 `num9` | ++num9++ |
242 `num-asterisk` | ++num-asterisk++ | `multiply`
243 `num-clear` | ++num-clear++ |
244 `num-delete` | ++num-delete++ | `num-del`
245 `num-equal` | ++num-equal++ |
246 `num-lock` | ++num-lock++ | `numlk`, `numlock`
247 `num-minus` | ++num-minus++ | `subtract`
248 `num-plus` | ++num-plus++ | `add`
249 `num-separator` | ++num-separator++ | `decimal`, `separator`
250 `num-slash` | ++num-slash++ | `divide`
251 `num-enter` | ++num-enter++ |
252
253 ### Modifier keys
254
255 Name | Display | Aliases
256 --------------- | ----------------- | -------
257 `alt` | ++alt++ |
258 `left-alt` | ++left-alt++ | `lalt`
259 `right-alt` | ++right-alt++ | `ralt`
260 `alt-graph` | ++alt-graph++ | `altgr`
261 `command` | ++command++ | `cmd`
262 `left-command` | ++left-command++ | `lcommand`, `lcmd`, `left-cmd`
263 `right-command` | ++right-command++ | `rcommand`, `rcmd`, `right-cmd`
264 `control` | ++control++ | `ctrl`
265 `left-control` | ++left-control++ | `lcontrol`, `lctrl`, `left-ctrl`
266 `right-control` | ++right-control++ | `rcontrol`, `rctrl`, `right-ctrl`
267 `function` | ++function++ | `fn`
268 `meta` | ++meta++ |
269 `left-meta` | ++left-meta++ | `lmeta`
270 `right-meta` | ++right-meta++ | `rmeta`
271 `option` | ++option++ | `opt`
272 `left-option` | ++left-option++ | `loption`, `lopt`, `left-opt`
273 `right-option` | ++right-option++ | `roption`, `ropt`, `right-opt`
274 `shift` | ++shift++ |
275 `left-shift` | ++left-shift++ | `lshift`
276 `right-shift` | ++right-shift++ | `rshift`
277 `super` | ++super++ |
278 `left-super` | ++left-super++ | `lsuper`
279 `right-super` | ++right-super++ | `rsuper`
280 `windows` | ++windows++ | `win`
281 `left-windows` | ++left-windows++ | `lwindows`, `left-win`, `lwin`
282 `right-windows` | ++right-windows++ | `rwindows`, `right-win`, `rwin`
283
284 ### Function keys
285
286 Name | Display | Aliases
287 ----- | ------- | -------
288 `f1` | ++f1++ |
289 `f2` | ++f2++ |
290 `f3` | ++f3++ |
291 `f4` | ++f4++ |
292 `f5` | ++f5++ |
293 `f6` | ++f6++ |
294 `f7` | ++f7++ |
295 `f8` | ++f8++ |
296 `f9` | ++f9++ |
297 `f10` | ++f10++ |
298 `f11` | ++f11++ |
299 `f12` | ++f12++ |
300 `f13` | ++f13++ |
301 `f14` | ++f14++ |
302 `f15` | ++f15++ |
303 `f16` | ++f16++ |
304 `f17` | ++f17++ |
305 `f18` | ++f18++ |
306 `f19` | ++f19++ |
307 `f20` | ++f20++ |
308 `f21` | ++f21++ |
309 `f22` | ++f22++ |
310 `f23` | ++f23++ |
311 `f24` | ++f24++ |
312
313 ### Extra Keys
314
315 Name | Display | Aliases
316 ------------------- | --------------------- | -------
317 `backtab` | ++backtab++ | `bktab`
318 `browser-back` | ++browser-back++ |
319 `browser-favorites` | ++browser-favorites++ | `favorites`
320 `browser-forward` | ++browser-forward++ | `forward`
321 `browser-home` | ++browser-home++ |
322 `browser-refresh` | ++browser-refresh++ | `refresh`
323 `browser-search` | ++browser-search++ | `search`
324 `browser-stop` | ++browser-stop++ |
325 `copy` | ++copy++ |
326 `context-menu` | ++context-menu++ | `apps`, `menu`
327 `fingerprint` | ++fingerprint++ | `fingerprint`
328 `mail` | ++mail++ | `launch-mail`
329 `media` | ++media++ | `launch-media`
330 `media-next-track` | ++media-next-track++ | `next-track`
331 `media-pause` | ++media-pause++ | `pause`
332 `media-play` | ++media-play++ | `play`
333 `media-play-pause` | ++media-play-pause++ | `play-pause`
334 `media-prev-track` | ++media-prev-track++ | `prev-track`
335 `media-stop` | ++media-stop++ | `stop`
336 `power` | ++power++ |
337 `print` | ++print++ |
338 `reset` | ++reset++ |
339 `select` | ++select++ |
340 `sleep` | ++sleep++ |
341 `volume-down` | ++volume-down++ | `vol-down`
342 `volume-mute` | ++volume-mute++ | `mute`
343 `volume-up` | ++volume-up++ | `vol-up`
344 `zoom` | ++zoom++ |
345
346 ### Mouse
347
348 Name | Display | Aliases
349 --------------- | ----------------- | -------
350 `left-button` | ++left-button++ | `lbutton`
351 `middle-button` | ++middle-button++ | `mbutton`
352 `right-button` | ++right-button++ | `rbutton`
353 `x-button1` | ++x-button1++ | `xbutton1`
354 `x-button2` | ++x-button2++ | `xbutton2`
355
356 ## Options
357
358 Option | Type | Default | Description
359 ------------ | ------ | -------------- | -----------
360 `separator` | string | `#!py3 '+'` | Define a separator.
361 `strict` | bool | `#!py3 False` | Use strict HTML5 output for keyboard key input.
362 `class` | string | `#!py3 'keys'` | Defines a class(es) to apply to the HTML wrapper element.
363 `camel_case` | bool | `#!py3 False` | Allow the use of camel case for key names `PgUp` --> `pg-up`.
364 `key_map` | dict | `#!py3 {}` | Add additional keys to the key-map index or override output of existing outputs. See [Extending/Modifying Key-Map Index](#extendingmodifying-key-map-index) for more info.