Scratch for Java

KeyCode

Contains virtual key code constants for keyboard input handling. These constants represent various keys on a keyboard including:

  • Standard character keys (letters, numbers, symbols)
  • Function keys (F1-F24)
  • Navigation keys (arrows, home, end, etc.)
  • Modifier keys (shift, ctrl, alt, etc.)
  • Numpad keys
  • Special keys for international keyboards
  • Media and system control keys

The key codes are defined as integer constants and follow common virtual key code standards used in various platforms. Many of these codes align with ASCII values for basic characters, while others use platform-specific ranges for special keys.

This class includes support for:

  • Standard US QWERTY keyboard layout
  • European keyboard specific keys
  • Asian keyboard specific keys (Japanese, Korean, etc.)
  • Sun keyboard specific functions
  • Microsoft Windows specific keys

The constants in this class are intended to be used for keyboard event handling and key mapping operations.

Use can use these constants to identify which key was pressed or released in keyboard events.

For example:

public void whenKeyPressed(int keyCode) {
  if (keyCode == KeyCode.VK_ENTER) {
    // Handle enter key press
  }
}
if (this.isKeyPressed(KeyCode.VK_SPACE)) {
  // Handle space key being pressed
}

Static Fields

Name Type Description
VK_ENTER int Constant for the enter key
VK_BACK_SPACE int Constant for the backspace key
VK_TAB int Constant for the tab key
VK_CANCEL int Constant for the cancel key
VK_CLEAR int Constant for the clear key
VK_SHIFT int Constant for the shift key
VK_CONTROL int Constant for the control key
VK_ALT int Constant for the alt key
VK_PAUSE int Constant for the pause key
VK_CAPS_LOCK int Constant for the caps lock key
VK_ESCAPE int Constant for the escape key
VK_SPACE int Constant for the space key
VK_PAGE_UP int Constant for the page up key
VK_PAGE_DOWN int Constant for the page down key
VK_END int Constant for the end key
VK_HOME int Constant for the home key
VK_LEFT int Constant for the non-numpad <b>left</b> arrow key.
VK_UP int Constant for the non-numpad <b>up</b> arrow key.
VK_RIGHT int Constant for the non-numpad <b>right</b> arrow key.
VK_DOWN int Constant for the non-numpad <b>down</b> arrow key.
VK_COMMA int Constant for the comma key, ","
VK_MINUS int Constant for the minus key, "-"
VK_PERIOD int Constant for the period key, "."
VK_SLASH int Constant for the forward slash key, "/"
VK_0 int VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39)
VK_1 int Constant for the key, "1"
VK_2 int Constant for the key, "2"
VK_3 int Constant for the key, "3"
VK_4 int Constant for the key, "4"
VK_5 int Constant for the key, "5"
VK_6 int Constant for the key, "6"
VK_7 int Constant for the key, "7"
VK_8 int Constant for the key, "8"
VK_9 int Constant for the key, "9"
VK_SEMICOLON int Constant for the semicolon key, ";"
VK_EQUALS int Constant for the equals key, "="
VK_A int Constant for the key, "A"
VK_B int Constant for the key, "B"
VK_C int Constant for the key, "C"
VK_D int Constant for the key, "D"
VK_E int Constant for the key, "E"
VK_F int Constant for the key, "F"
VK_G int Constant for the key, "G"
VK_H int Constant for the key, "H"
VK_I int Constant for the key, "I"
VK_J int Constant for the key, "J"
VK_K int Constant for the key, "K"
VK_L int Constant for the key, "L"
VK_M int Constant for the key, "M"
VK_N int Constant for the key, "N"
VK_O int Constant for the key, "O"
VK_P int Constant for the key, "P"
VK_Q int Constant for the key, "Q"
VK_R int Constant for the key, "R"
VK_S int Constant for the key, "S"
VK_T int Constant for the key, "T"
VK_U int Constant for the key, "U"
VK_V int Constant for the key, "V"
VK_W int Constant for the key, "W"
VK_X int Constant for the key, "X"
VK_Y int Constant for the key, "Y"
VK_Z int Constant for the key, "Z"
VK_OPEN_BRACKET int Constant for the open bracket key, "["
VK_BACK_SLASH int Constant for the back slash key, "&quot;
VK_CLOSE_BRACKET int Constant for the close bracket key, "]"
VK_NUMPAD0 int Constant for the number pad <b>0</b> key.
VK_NUMPAD1 int Constant for the Numpad 1 key.
VK_NUMPAD2 int Constant for the Numpad 2 key.
VK_NUMPAD3 int Constant for the Numpad 3 key.
VK_NUMPAD4 int Constant for the Numpad 4 key.
VK_NUMPAD5 int Constant for the Numpad 5 key.
VK_NUMPAD6 int Constant for the Numpad 6 key.
VK_NUMPAD7 int Constant for the Numpad 7 key.
VK_NUMPAD8 int Constant for the Numpad 8 key.
VK_NUMPAD9 int Constant for the Numpad 9 key.
VK_MULTIPLY int Constant for the multiply key.
VK_ADD int Constant for the add key.
VK_SUBTRACT int Constant for the subtract key
VK_DECIMAL int Constant for the decimal key
VK_DIVIDE int Constant for the divide key
VK_DELETE int Constant for the delete key.
VK_NUM_LOCK int Constant for the number lock key.
VK_SCROLL_LOCK int Constant for the scroll lock key.
VK_F1 int Constant for the F1 function key.
VK_F2 int Constant for the F2 function key.
VK_F3 int Constant for the F3 function key.
VK_F4 int Constant for the F4 function key.
VK_F5 int Constant for the F5 function key.
VK_F6 int Constant for the F6 function key.
VK_F7 int Constant for the F7 function key.
VK_F8 int Constant for the F8 function key.
VK_F9 int Constant for the F9 function key.
VK_F10 int Constant for the F10 function key.
VK_F11 int Constant for the F11 function key.
VK_F12 int Constant for the F12 function key.
VK_F13 int Constant for the F13 function key.
VK_F14 int Constant for the F14 function key.
VK_F15 int Constant for the F15 function key.
VK_F16 int Constant for the F16 function key.
VK_F17 int Constant for the F17 function key.
VK_F18 int Constant for the F18 function key.
VK_F19 int Constant for the F19 function key.
VK_F20 int Constant for the F20 function key.
VK_F21 int Constant for the F21 function key.
VK_F22 int Constant for the F22 function key.
VK_F23 int Constant for the F23 function key.
VK_F24 int Constant for the F24 function key.
VK_PRINTSCREEN int
VK_INSERT int
VK_HELP int
VK_META int
VK_BACK_QUOTE int
VK_QUOTE int
VK_KP_UP int Constant for the numeric keypad <b>up</b> arrow key.
VK_KP_DOWN int Constant for the numeric keypad <b>down</b> arrow key.
VK_KP_LEFT int Constant for the numeric keypad <b>left</b> arrow key.
VK_KP_RIGHT int Constant for the numeric keypad <b>right</b> arrow key.
VK_DEAD_GRAVE int
VK_DEAD_ACUTE int
VK_DEAD_CIRCUMFLEX int
VK_DEAD_TILDE int
VK_DEAD_MACRON int
VK_DEAD_BREVE int
VK_DEAD_ABOVEDOT int
VK_DEAD_DIAERESIS int
VK_DEAD_ABOVERING int
VK_DEAD_DOUBLEACUTE int
VK_DEAD_CARON int
VK_DEAD_CEDILLA int
VK_DEAD_OGONEK int
VK_DEAD_IOTA int
VK_DEAD_VOICED_SOUND int
VK_DEAD_SEMIVOICED_SOUND int
VK_AMPERSAND int
VK_ASTERISK int
VK_QUOTEDBL int
VK_LESS int
VK_GREATER int
VK_BRACELEFT int
VK_BRACERIGHT int
VK_AT int Constant for the "@" key.
VK_COLON int Constant for the ":" key.
VK_CIRCUMFLEX int Constant for the "^" key.
VK_DOLLAR int Constant for the "$" key.
VK_EURO_SIGN int Constant for the Euro currency sign key.
VK_EXCLAMATION_MARK int Constant for the "!" key.
VK_INVERTED_EXCLAMATION_MARK int Constant for the inverted exclamation mark key.
VK_LEFT_PARENTHESIS int Constant for the "(" key.
VK_NUMBER_SIGN int Constant for the "#" key.
VK_PLUS int Constant for the "+" key.
VK_RIGHT_PARENTHESIS int Constant for the ")" key.
VK_UNDERSCORE int Constant for the "_" key.
VK_WINDOWS int Constant for the Microsoft Windows "Windows" key. It is used for both the left and right version of the key.
VK_CONTEXT_MENU int Constant for the Microsoft Windows Context Menu key.
VK_FINAL int
VK_CONVERT int Constant for the Convert function key.
VK_NONCONVERT int Constant for the Don't Convert function key.
VK_ACCEPT int Constant for the Accept or Commit function key.
VK_MODECHANGE int
VK_KANA int
VK_KANJI int
VK_ALPHANUMERIC int Constant for the Alphanumeric function key.
VK_KATAKANA int Constant for the Katakana function key.
VK_HIRAGANA int Constant for the Hiragana function key.
VK_FULL_WIDTH int Constant for the Full-Width Characters function key.
VK_HALF_WIDTH int Constant for the Half-Width Characters function key.
VK_ROMAN_CHARACTERS int Constant for the Roman Characters function key.
VK_ALL_CANDIDATES int Constant for the All Candidates function key.
VK_PREVIOUS_CANDIDATE int Constant for the Previous Candidate function key.
VK_CODE_INPUT int Constant for the Code Input function key.
VK_JAPANESE_KATAKANA int Constant for the Japanese-Katakana function key. This key switches to a Japanese input method and selects its Katakana input mode.
VK_JAPANESE_HIRAGANA int Constant for the Japanese-Hiragana function key. This key switches to a Japanese input method and selects its Hiragana input mode.
VK_JAPANESE_ROMAN int Constant for the Japanese-Roman function key. This key switches to a Japanese input method and selects its Roman-Direct input mode.
VK_KANA_LOCK int Constant for the locking Kana function key. This key locks the keyboard into a Kana layout.
VK_INPUT_METHOD_ON_OFF int Constant for the input method on/off key.
VK_CUT int
VK_COPY int
VK_PASTE int
VK_UNDO int
VK_AGAIN int
VK_FIND int
VK_PROPS int
VK_STOP int
VK_COMPOSE int Constant for the Compose function key.
VK_ALT_GRAPH int Constant for the AltGraph function key.
VK_BEGIN int Constant for the Begin key.
KeyCode