Template:Key press

From Appropedia


Template documentation[edit source]

This is the {{key press}} template.

You can use it to illustrate keystrokes.


{{Key press|A}} produces A

If there is an article about the key on Wikipedia you can interwikilink the key's name like any other wiki text. Like this:

{{Key press|[[Wikipedia:Alt key|Alt]]}} produces Alt

To illustrate keystroke combinations, just use extra parameters:

{{Key press|[[Wikipedia:Alt key|Alt]]|P}} produces Alt+P
{{Key press|[[Wikipedia:Ctrl|Ctrl]]|Alt|Del}} produces Ctrl+Alt+Del

Key symbols[edit source]

Some key names have a fitting unicode character. This template automatically adds such "icons" to the following key names:

{{Key press|Shift}} produces Shift
{{Key press|Enter}} produces Enter
{{Key press|Cmd}} produces Cmd
{{Key press|Opt}} produces Opt
{{Key press|Tab}} produces Tab
{{Key press|Backspace}} produces ← Backspace
{{Key press|Eject}} produces ​ Eject
{{Key press|Page Up}} produces PgUp
{{Key press|Page Down}} produces PgDn
{{Key press|Up}} produces
{{Key press|Down}} produces
{{Key press|Left}} produces
{{Key press|Right}} produces

We have no characters for the Windows key and menu key. And we perhaps can't add the "real" icons for them for copyright reasons. So we usually show them the following way:

{{Key press|Win}} or {{Key press|Win key}} produces Win or Win key
{{Key press|Menu}} produces Menu

Technical details[edit source]

When you feed several key names to this template, it adds a "+" with no spaces around. This means it won't line wrap. But when you show key combinations for instance in a table then that might cause too wide items. Then instead manually build the key combination with spaces around the "+" so it can line wrap. Like this:

{{Key press|Ctrl}} + {{Key press|Alt}} + {{Key press|Del}} produces Ctrl + Alt + Del

This template currently handles up to 5 key name parameters. If it gets too many key name parameters it reports the page into Category:Key press template parameter needs fixing. This means we can easily find those pages and fix them, or we can discover if we need to make this template take more parameters.

This template calls {{key press/core}}, which holds the code that otherwise would be repeated several times in {{key press}}, thus simplifying the code.

See also[edit source]