This template is designed to illustrate key and keystrokes on a keyboard. It can be used to show single keystrokes, combination keystrokes and a keystroke sequence.
Usage[]
To show combination keystrokes, place pluses between each key.
{{key|Alt+P}}
produces Alt+P{{key|Ctrl+Alt+Del}}
produces Ctrl+Alt+Del
Pluses on their own will be displayed as a key.
{{key|1|+|2}}
produces 1+2{{key|1+|+|+2}}
produces 1+++2
Supported Named/Symbol shortcuts[]
Arrow keys[]
- {{key|up}}
- ↑
- {{key|down}}
- ↓
- {{key|left}}
- ←
- {{key|right}}
- →
fr:Modèle:Touche ja:テンプレート:key ko:틀:key nl:Sjabloon:Key
local p = {}
p.keys = function( f )
local args = f
if f == mw.getCurrentFrame() then
args = f:getParent().args
end
local keys = {}
for _, key in ipairs( args ) do
key = mw.text.trim( key )
if key ~= '+' and key:find( '%+' ) then
local comboKeys = {}
for comboKey in mw.text.gsplit( key, '%s*%+%s*' ) do
table.insert( comboKeys, p.key( comboKey ) )
end
table.insert( keys, table.concat( comboKeys, '+' ) )
else
table.insert( keys, p.key( key ) )
end
end
return table.concat( keys )
end
p.key = function( key )
if not key then
return ''
end
local symbols = mw.loadData( 'Module:Keys/Symbols' )
local kbd = mw.html.create( 'kbd' )
kbd
:addClass( 'key' )
:addClass( 'nowrap' )
:wikitext( symbols[key:lower()] or key )
:css({
border = '1px solid #AAA',
padding = '0.1em 0.3em',
['font-family'] = 'inherit',
['font-size'] = '85%'
})
return tostring( kbd )
end
return p