Module:Keypress

-- -- This template is based heavily on Wikipedia's Template:Key_press and Template:Key_press/core -- Invoked by Template:Keypress --

local p = {}

function p.key_press( frame ) local parameters = frame:getParent.args local chain = parameters['chain'] or '+' local key_presses = mw.html.create(''):done key_presses:node(p._core(parameters[1] or '')) for i = 2, 10, 1 do		local key = parameters[i] if key then key_presses:wikitext(chain) key_presses:node(p._core(key)) end end return tostring(key_presses) end

-- Returns mw.html kbd function p._core( pKey ) local key = string.lower(pKey) local kbd = mw.html.create('kbd') :addClass('keypress-diagram') :done local function unicode( symbol ) return mw.html.create('span'):addClass('unicode'):wikitext(symbol):done end -- http://stackoverflow.com/a/20285006/1411473 local function firstLettersToUpper(str) return string.gsub(' '..str, '%W%l', string.upper):sub(2) end if    key == 'caps lock'				then kbd:node(unicode('⇪')):wikitext(' Caps Lock') elseif key == 'shift'					then kbd:node(unicode('⇧')):wikitext(' Shift') elseif key == 'enter'					then kbd:node(unicode('↵')):wikitext(' Enter') elseif key == 'cmd' or key == 'command'	then kbd:node(unicode('⌘')):wikitext(' '..firstLettersToUpper(key)) elseif key == 'opt' or key == 'option'	then kbd:node(unicode('⌥')):wikitext(' '..firstLettersToUpper(key)) elseif key == 'tab'						then kbd:wikitext('Tab '):node(unicode('↹')) elseif key == 'backspace'				then kbd:wikitext('← Backspace') elseif key == 'win'						then kbd:node(unicode('⊞')):wikitext(' Win') elseif key == 'menu'					then kbd:node(unicode('≣')):wikitext(' Menu') elseif key == 'up'						then kbd:wikitext('↑') elseif key == 'down'					then kbd:wikitext('↓') elseif key == 'left'					then kbd:wikitext('←') elseif key == 'right'					then kbd:wikitext('→') elseif key == '*' or key == 'asterisk'	then kbd:wikitext('*') elseif key == '#' or key == 'hash'		then kbd:wikitext('#') elseif key == ':' or key == 'colon'		then kbd:wikitext(':') elseif key == 'pipe'					then kbd:wikitext('|') elseif key == ';' or key == 'semicolon'	then kbd:wikitext(';') elseif key == 'equals'					then kbd:wikitext('=') else									    kbd:wikitext(firstLettersToUpper(key)) end return kbd; end

return p