Difference between revisions of "Keys (API)"

From ComputerCraft Wiki
Jump to: navigation, search
(New page)
 
(added a note about keys.end not working (requiring using keys['end']))
 
(4 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
The Keys API provides a table of numerical codes corresponding to keyboard keys, suitable for decoding [[Key (event)|key events]].
 
The Keys API provides a table of numerical codes corresponding to keyboard keys, suitable for decoding [[Key (event)|key events]].
  
<table style="width: 100%; border: solid 1px black; margin: 2px; border-spacing: 0px;">
 
<tr><td colspan="2" style="font-weight: bold; font-size: large; padding-bottom: .3em; border-bottom: solid #C9C9C9 1px; background: #D3FFC2; line-height:28px;">
 
[[File:Grid_disk.png|24px]]&nbsp;&nbsp;
 
keys (API)
 
</td></tr>
 
  
<tr><td style="width: 350px; background: #E0E0E0; padding: .4em; font-weight:bold;">Method Name</td><td style="background: #E0E0E0; padding: .4em; font-weight:bold;">Description</td></tr>
+
{{API table|Keys|image=Grid disk.png|2=
  
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[keys.getName]](code)</td>
+
{{API table/row
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Translates a numerical key code to a human-readable name.</td></tr>
+
|[[keys.getName]]({{Type|number}} code)|{{type|string}} keyName
 +
|Translates a numerical key code to a human-readable name.
 +
|odd}}
  
</table>
+
}}
  
 
Although this API contains only one method, it also contains a vast number of constants, one per key, containing the numerical key codes for those keys. As of ComputerCraft 1.52, the following constants are defined:
 
Although this API contains only one method, it also contains a vast number of constants, one per key, containing the numerical key codes for those keys. As of ComputerCraft 1.52, the following constants are defined:
Line 130: Line 127:
 
* insert
 
* insert
 
* delete
 
* delete
 +
 +
Note that when using the "end" key, you will have to write it as <code>keys['end']</code> instead of <code>keys.end</code>, as otherwise it will be detected as the Lua keyword <code>end</code> and cause a script error.
 +
  
 
[[Category:APIs]]
 
[[Category:APIs]]

Latest revision as of 13:26, 26 August 2015

The Keys API provides a table of numerical codes corresponding to keyboard keys, suitable for decoding key events.


Grid disk.png  Keys (API)
Function Return values Description
keys.getName(number code) string keyName Translates a numerical key code to a human-readable name.

Although this API contains only one method, it also contains a vast number of constants, one per key, containing the numerical key codes for those keys. As of ComputerCraft 1.52, the following constants are defined:

  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
  • z
  • one
  • two
  • three
  • four
  • five
  • six
  • seven
  • eight
  • nine
  • zero
  • minus
  • equals
  • backspace
  • tab
  • leftBracket
  • rightBracket
  • enter
  • leftCtrl
  • semiColon
  • apostrophe
  • grave
  • leftShift
  • backslash
  • comma
  • period
  • slash
  • rightShift
  • multiply
  • leftAlt
  • space
  • capsLock
  • f1
  • f2
  • f3
  • f4
  • f5
  • f6
  • f7
  • f8
  • f9
  • f10
  • numLock
  • scollLock
  • numPad7
  • numPad8
  • numPad9
  • numPadSubtract
  • numPad4
  • numPad5
  • numPad6
  • numPadAdd
  • numPad1
  • numPad2
  • numPad3
  • numPad0
  • numPadDecimal
  • f11
  • f12
  • f13
  • f14
  • f15
  • kana
  • convert
  • noconvert
  • yen
  • numPadEquals
  • cimcumflex
  • at
  • colon
  • underscore
  • kanji
  • stop
  • ax
  • numPadEnter
  • rightCtrl
  • numPadComma
  • numPadDivide
  • rightAlt
  • pause
  • home
  • up
  • pageUp
  • left
  • right
  • end
  • down
  • pageDown
  • insert
  • delete

Note that when using the "end" key, you will have to write it as keys['end'] instead of keys.end, as otherwise it will be detected as the Lua keyword end and cause a script error.