website is under construction
Lumen

Keyboard

The keyboard module provides methods for retrieving input from the keyboard.

Detecting Key Presses

You can check if a key is currently pressed (and held down) using the isDown method. This method takes a single argument, which is the key to check specified as a string.

function update() {
  if (keyboard.isDown('w')) {
    // Move the player up
  }

  if (keyboard.isDown('a')) {
    // Move the player left
  }

  if (keyboard.isDown('s')) {
    // Move the player down
  }

  if (keyboard.isDown('d')) {
    // Move the player right
  }
}

To check if a key was pressed this frame, use the wasPressed method. This method takes a single argument, which is the key to check specified as a string.

function update() {
  if (keyboard.wasPressed('i')) {
    // Open the inventory
  }
}

The difference between isDown and wasPressed is that isDown will return true as long as the key is held down, while wasPressed will only return true once per key press.

Detecting Key Releases

You can check if a key is currently released (and not held down) using the isUp method. This method takes a single argument, which is the key to check specified as a string.

function update() {
  if (keyboard.isUp('space')) {
    // Space bar is not pressed
  }
}

To check if a key was released this frame, use the wasReleased method. This method takes a single argument, which is the key to check specified as a string.

function update() {
  if (keyboard.wasReleased('space')) {
    // Space bar was released this frame
  }
}

Similar to isDown and wasPressed, the difference between isUp and wasReleased is that isUp will return true as long as the key is not held down, while wasReleased will only return true once per key release.

Key Codes

The following table lists the key codes for each key on the keyboard.

Key CodeKeyScan CodeUnicode
3Cancelcancel
8Backspacebackspace
9Tabtab
12Clearclear
13Enterenter
16Shiftshiftleft
16Shiftshiftright
17Controlcontrolleft
17Controlcontrolright
18Altaltleft
18Altaltright
19Pausepause
20Caps Lockcapslock
27Escapeescape
32Spacespace
33Page Uppageup
34Page Downpagedown
35Endend
36Homehome
37Left Arrowleft
38Up Arrowup
39Right Arrowright
40Down Arrowdown
42Print Screenprintscreen
45Insertinsert
46Deletedelete
48000
49111
50222
51333
52444
53555
54666
55777
56888
57999
65AaA
66BbB
67CcC
68DdD
69EeE
70FfF
71GgG
72HhH
73IiI
74JjJ
75KkK
76LlL
77MmM
78NnN
79OoO
80PpP
81QqQ
82RrR
83SsS
84TtT
85UuU
86VvV
87WwW
88XxX
89YyY
90ZzZ
91Left Metametaleft
91Right Metametaright
96Numpad 0numpad00
97Numpad 1numpad11
98Numpad 2numpad22
99Numpad 3numpad33
100Numpad 4numpad44
101Numpad 5numpad55
102Numpad 6numpad66
103Numpad 7numpad77
104Numpad 8numpad88
105Numpad 9numpad99
106Numpad *numpadmultiply*
107Numpad +numpadadd+
109Numpad -numpadsubtract-
110Numpad .numpaddecimal.
111Numpad /numpaddivide/
112F1f1F1
113F2f2F2
114F3f3F3
115F4f4F4
116F5f5F5
117F6f6F6
118F7f7F7
119F8f8F8
120F9f9F9
121F10f10F10
122F11f11F11
123F12f12F12
144Num Locknumlock
145Scroll Lockscrolllock
160^^^
161!!!