Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

keycode-js

Package Overview
Dependencies
Maintainers
2
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

keycode-js

A JavaScript package with Key Code constants

  • 3.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

KeyCode Constants

npm version deno Build Status Language grade: JavaScript npm downloads per week GitHub contributors PRs Welcome License: MIT

A minimal JavaScript package with key code constants.

Installation

# Using npm
$ npm install keycode-js --save

# Using yarn
$ yarn add keycode-js

# Using bower
$ bower install keycode-js --save

Usage

Import the package using require() or ES / TypeScript import statement:

// CommonJS
const KeyCode = require('keycode-js');

// ES2015+
import * as KeyCode from 'keycode-js';

// TypeScript
import * as KeyCode from 'keycode-js';

// Import individual constants
import { KEY_RETURN } from 'keycode-js';

Or, using <script> tag:

<script src="https://unpkg.com/keycode-js@3.1.0/dist/keycode.min.js"></script>

Finally:

window.addEventListener('keyup', function(e) {
  // You may do one of these checks.

  // Check the code value.
  if (e.code === KeyCode.CODE_RETURN) {
    console.log('It was the Return key.');
    return;
  }

  // OR, check the keyCode value.
  if (e.keyCode === KeyCode.KEY_RETURN) {
    console.log('It was the Return key.');
    return;
  }

  // OR, check the key value.
  if (e.key === KeyCode.VALUE_RETURN) {
    console.log('It was the Return key.');
    return;
  }

  console.log('It was any other key.');
});

Usage with Deno

// Import all constants
import * as KeyCode from 'https://deno.land/x/keycode@v3.1.0/mod.ts';

// Import individual constants
import { KEY_ENTER } from 'https://deno.land/x/keycode@v3.1.0/mod.ts';

console.assert(KeyCode.KEY_ENTER === KEY_ENTER);

Available Constants

1. Key event code constants

List of available constants that corresponds to the browser's KeyboardEvent.code attribute.

[Reference]

Example usage

window.addEventListener('keyup', function(e) {
  console.log('Enter Key:', (e.code === KeyCode.CODE_RETURN));
});

List

Key NameConstantValue
(Undefined)CODE_UNIDENTIFIED"Unidentified"
EscapeCODE_ESCAPE"Escape"
Dash / MinusCODE_MINUS
CODE_DASH
"Minus"
EqualsCODE_EQUALS"Equal"
BackspaceCODE_BACK_SPACE"Backspace"
TabCODE_TAB"Tab"
ReturnCODE_ENTER
CODE_RETURN
"Enter"
Shift (Left)CODE_SHIFT_LEFT"ShiftLeft"
Shift (Right)CODE_SHIFT_RIGHT"ShiftRight"
Control (Left)CODE_CONTROL_LEFT"ControlLeft"
Control (Right)CODE_CONTROL_RIGHT"ControlRight"
Alt (Left)CODE_ALT_LEFT"AltLeft"
Alt (Right)CODE_ALT_RIGHT"AltRight"
PauseCODE_PAUSE"Pause"
Caps LockCODE_CAPS_LOCK"CapsLock"
SpaceCODE_SPACE"Space"
Page UpCODE_PAGE_UP"PageUp"
Page DownCODE_PAGE_DOWN"PageDown"
EndCODE_END"End"
HomeCODE_HOME"Home"
LeftCODE_LEFT"ArrowLeft"
UpCODE_UP"ArrowUp"
RightCODE_RIGHT"ArrowRight"
DownCODE_DOWN"ArrowDown"
Print ScreenCODE_PRINTSCREEN"PrintScreen"
InsertCODE_INSERT"Insert"
DeleteCODE_DELETE"Delete"
0CODE_0"Digit0"
1CODE_1"Digit1"
2CODE_2"Digit2"
3CODE_3"Digit3"
4CODE_4"Digit4"
5CODE_5"Digit5"
6CODE_6"Digit6"
7CODE_7"Digit7"
8CODE_8"Digit8"
9CODE_9"Digit9"
ACODE_A"KeyA"
BCODE_B"KeyB"
CCODE_C"KeyC"
DCODE_D"KeyD"
ECODE_E"KeyE"
FCODE_F"KeyF"
GCODE_G"KeyG"
HCODE_H"KeyH"
ICODE_I"KeyI"
JCODE_J"KeyJ"
KCODE_K"KeyK"
LCODE_L"KeyL"
MCODE_M"KeyM"
NCODE_N"KeyN"
OCODE_O"KeyO"
PCODE_P"KeyP"
QCODE_Q"KeyQ"
RCODE_R"KeyR"
SCODE_S"KeyS"
TCODE_T"KeyT"
UCODE_U"KeyU"
VCODE_V"KeyV"
WCODE_W"KeyW"
XCODE_X"KeyX"
YCODE_Y"KeyY"
ZCODE_Z"KeyZ"
Cmd ⌘ / Window (Left)CODE_META_LEFT"MetaLeft"
Cmd ⌘ / Window (Left)CODE_OS_LEFT"OSLeft"
Cmd ⌘ / Window (Right)CODE_META_RIGHT"MetaRight"
Cmd ⌘ / Window (Right)CODE_OS_RIGHT"OSRight"
Context MenuCODE_CONTEXT_MENU"ContextMenu"
Numpad 0CODE_NUMPAD0"Numpad0"
Numpad 1CODE_NUMPAD1"Numpad1"
Numpad 2CODE_NUMPAD2"Numpad2"
Numpad 3CODE_NUMPAD3"Numpad3"
Numpad 4CODE_NUMPAD4"Numpad4"
Numpad 5CODE_NUMPAD5"Numpad5"
Numpad 6CODE_NUMPAD6"Numpad6"
Numpad 7CODE_NUMPAD7"Numpad7"
Numpad 8CODE_NUMPAD8"Numpad8"
Numpad 9CODE_NUMPAD9"Numpad9"
MultiplyCODE_NUMPAD_MULTIPLY"NumpadMultiply"
AddCODE_NUMPAD_ADD"NumpadAdd"
SubtractCODE_NUMPAD_SUBTRACT"NumpadSubtract"
DecimalCODE_NUMPAD_DECIMAL"NumpadDecimal"
DivideCODE_NUMPAD_DIVIDE"NumpadDivide"
Numpad EnterCODE_NUMPAD_ENTER"NumpadEnter"
F1CODE_F1"F1"
F2CODE_F2"F2"
F3CODE_F3"F3"
F4CODE_F4"F4"
F5CODE_F5"F5"
F6CODE_F6"F6"
F7CODE_F7"F7"
F8CODE_F8"F8"
F9CODE_F9"F9"
F10CODE_F10"F10"
F11CODE_F11"F11"
F12CODE_F12"F12"
F13CODE_F13"F13"
F14CODE_F14"F14"
F15CODE_F15"F15"
F16CODE_F16"F16"
F17CODE_F17"F17"
F18CODE_F18"F18"
F19CODE_F19"F19"
F20CODE_F20"F20"
F21CODE_F21"F21"
F22CODE_F22"F22"
F23CODE_F23"F23"
F24CODE_F24"F24"
Num LockCODE_NUM_LOCK"NumLock"
Scroll LockCODE_SCROLL_LOCK"ScrollLock"
SemicolonCODE_SEMICOLON"Semicolon"
CommaCODE_COMMA"Comma"
PeriodCODE_PERIOD"Period"
SlashCODE_SLASH"Slash"
Back QuoteCODE_BACK_QUOTE"Backquote"
Open BracketCODE_OPEN_BRACKET"BracketLeft"
Back SlashCODE_BACK_SLASH"Backslash"
Close BracketCODE_CLOSE_BRACKET"BracketRight"
QuoteCODE_QUOTE"Quote"

2. Key code constants (numeric)

List of available numeric constants that corresponds to the browser's KeyboardEvent.keyCode attribute.

[Reference]

Example usage

window.addEventListener('keyup', function(e) {
  console.log('Enter Key:', (e.keyCode === KeyCode.KEY_RETURN));
});

List

Key NameConstantValue
CancelKEY_CANCEL3
HelpKEY_HELP6
BackspaceKEY_BACK_SPACE8
TabKEY_TAB9
ClearKEY_CLEAR12
ReturnKEY_RETURN13
Enter (Firefox)KEY_FIREFOX_ENTER14
ShiftKEY_SHIFT16
ControlKEY_CONTROL17
AltKEY_ALT18
PauseKEY_PAUSE19
Caps LockKEY_CAPS_LOCK20
EscapeKEY_ESCAPE27
SpaceKEY_SPACE32
Page upKEY_PAGE_UP33
Page downKEY_PAGE_DOWN34
EndKEY_END35
HomeKEY_HOME36
LeftKEY_LEFT37
UpKEY_UP38
RightKEY_RIGHT39
DownKEY_DOWN40
Print ScreenKEY_PRINTSCREEN44
InsertKEY_INSERT45
DeleteKEY_DELETE46
0KEY_048
1KEY_149
2KEY_250
3KEY_351
4KEY_452
5KEY_553
6KEY_654
7KEY_755
8KEY_856
9KEY_957
Semicolon (Firefox)KEY_FIREFOX_SEMICOLON59
Equals (Firefox)KEY_FIREFOX_EQUALS61
AKEY_A65
BKEY_B66
CKEY_C67
DKEY_D68
EKEY_E69
FKEY_F70
GKEY_G71
HKEY_H72
IKEY_I73
JKEY_J74
KKEY_K75
LKEY_L76
MKEY_M77
NKEY_N78
OKEY_O79
PKEY_P80
QKEY_Q81
RKEY_R82
SKEY_S83
TKEY_T84
UKEY_U85
VKEY_V86
WKEY_W87
XKEY_X88
YKEY_Y89
ZKEY_Z90
Left ⌘ / WindowKEY_LEFT_CMD91
Right ⌘ / WindowKEY_RIGHT_CMD92
Context MenuKEY_CONTEXT_MENU93
Numpad 0KEY_NUMPAD096
Numpad 1KEY_NUMPAD197
Numpad 2KEY_NUMPAD298
Numpad 3KEY_NUMPAD399
Numpad 4KEY_NUMPAD4100
Numpad 5KEY_NUMPAD5101
Numpad 6KEY_NUMPAD6102
Numpad 7KEY_NUMPAD7103
Numpad 8KEY_NUMPAD8104
Numpad 9KEY_NUMPAD9105
MultiplyKEY_MULTIPLY106
AddKEY_ADD107
Separator (Firefox)KEY_FIREFOX_SEPARATOR108
SubtractKEY_SUBTRACT109
DecimalKEY_DECIMAL110
DivideKEY_DIVIDE111
F1KEY_F1112
F2KEY_F2113
F3KEY_F3114
F4KEY_F4115
F5KEY_F5116
F6KEY_F6117
F7KEY_F7118
F8KEY_F8119
F9KEY_F9120
F10KEY_F10121
F11KEY_F11122
F12KEY_F12123
F13KEY_F13124
F14KEY_F14125
F15KEY_F15126
F16KEY_F16127
F17KEY_F17128
F18KEY_F18129
F19KEY_F19130
F20KEY_F20131
F21KEY_F21132
F22KEY_F22133
F23KEY_F23134
F24KEY_F24135
Num LockKEY_NUM_LOCK144
Scroll LockKEY_SCROLL_LOCK145
SemicolonKEY_SEMICOLON186
EqualsKEY_EQUALS187
CommaKEY_COMMA188
DashKEY_DASH189
PeriodKEY_PERIOD190
SlashKEY_SLASH191
Back QuoteKEY_BACK_QUOTE192
Open BracketKEY_OPEN_BRACKET219
Back SlashKEY_BACK_SLASH220
Close BracketKEY_CLOSE_BRACKET221
QuoteKEY_QUOTE222
Meta (Firefox)KEY_FIREFOX_META224

3. Key value constants

List of available constants that corresponds to the browser's KeyboardEvent.key attribute.

Example usage

window.addEventListener('keyup', function(e) {
  console.log('Enter Key:', (e.key === KeyCode.VALUE_RETURN));
});

List

Key NameConstantValue
CancelVALUE_CANCEL"Cancel"
HelpVALUE_HELP"Help"
BackspaceVALUE_BACK_SPACE"Backspace"
TabVALUE_TAB"Tab"
ClearVALUE_CLEAR"Clear"
ReturnVALUE_ENTER
VALUE_RETURN
"Enter"
ShiftVALUE_SHIFT"Shift"
ControlVALUE_CONTROL"Control"
AltVALUE_ALT"Alt"
PauseVALUE_PAUSE"Pause"
Caps LockVALUE_CAPS_LOCK"CapsLock"
EscapeVALUE_ESCAPE"Escape"
SpaceVALUE_SPACE" "
Page upVALUE_PAGE_UP"PageUp"
Page downVALUE_PAGE_DOWN"PageDown"
EndVALUE_END"End"
HomeVALUE_HOME"Home"
LeftVALUE_LEFT"ArrowLeft"
UpVALUE_UP"ArrowUp"
RightVALUE_RIGHT"ArrowRight"
DownVALUE_DOWN"ArrowDown"
Print ScreenVALUE_PRINTSCREEN"PrintScreen"
InsertVALUE_INSERT"Insert"
DeleteVALUE_DELETE"Delete"
0VALUE_0"0"
1VALUE_1"1"
2VALUE_2"2"
3VALUE_3"3"
4VALUE_4"4"
5VALUE_5"5"
6VALUE_6"6"
7VALUE_7"7"
8VALUE_8"8"
9VALUE_9"9"
AVALUE_A"a"
BVALUE_B"b"
CVALUE_C"c"
DVALUE_D"d"
EVALUE_E"e"
FVALUE_F"f"
GVALUE_G"g"
HVALUE_H"h"
IVALUE_I"i"
JVALUE_J"j"
KVALUE_K"k"
LVALUE_L"l"
MVALUE_M"m"
NVALUE_N"n"
OVALUE_O"o"
PVALUE_P"p"
QVALUE_Q"q"
RVALUE_R"r"
SVALUE_S"s"
TVALUE_T"t"
UVALUE_U"u"
VVALUE_V"v"
WVALUE_W"w"
XVALUE_X"x"
YVALUE_Y"y"
ZVALUE_Z"z"
Cmd ⌘ / WindowVALUE_META
VALUE_LEFT_CMD
VALUE_RIGHT_CMD
"Meta"
Context MenuVALUE_CONTEXT_MENU"ContextMenu"
Numpad 0VALUE_NUMPAD0"0"
Numpad 1VALUE_NUMPAD1"1"
Numpad 2VALUE_NUMPAD2"2"
Numpad 3VALUE_NUMPAD3"3"
Numpad 4VALUE_NUMPAD4"4"
Numpad 5VALUE_NUMPAD5"5"
Numpad 6VALUE_NUMPAD6"6"
Numpad 7VALUE_NUMPAD7"7"
Numpad 8VALUE_NUMPAD8"8"
Numpad 9VALUE_NUMPAD9"9"
MultiplyVALUE_MULTIPLY"*"
AddVALUE_ADD"+"
SubtractVALUE_SUBTRACT"-"
DecimalVALUE_DECIMAL"."
DivideVALUE_DIVIDE"/"
F1VALUE_F1"F1"
F2VALUE_F2"F2"
F3VALUE_F3"F3"
F4VALUE_F4"F4"
F5VALUE_F5"F5"
F6VALUE_F6"F6"
F7VALUE_F7"F7"
F8VALUE_F8"F8"
F9VALUE_F9"F9"
F10VALUE_F10"F10"
F11VALUE_F11"F11"
F12VALUE_F12"F12"
F13VALUE_F13"F13"
F14VALUE_F14"F14"
F15VALUE_F15"F15"
F16VALUE_F16"F16"
F17VALUE_F17"F17"
F18VALUE_F18"F18"
F19VALUE_F19"F19"
F20VALUE_F20"F20"
F21VALUE_F21"F21"
F22VALUE_F22"F22"
F23VALUE_F23"F23"
F24VALUE_F24"F24"
Num LockVALUE_NUM_LOCK"NumLock"
Scroll LockVALUE_SCROLL_LOCK"ScrollLock"
SemicolonVALUE_SEMICOLON";"
EqualsVALUE_EQUALS"="
CommaVALUE_COMMA","
DashVALUE_DASH"-"
PeriodVALUE_PERIOD"."
SlashVALUE_SLASH"/"
Back QuoteVALUE_BACK_QUOTE"`"
Open BracketVALUE_OPEN_BRACKET"("
Back SlashVALUE_BACK_SLASH"\"
Close BracketVALUE_CLOSE_BRACKET")"
QuoteVALUE_QUOTE"'"

Contributing

All kinds of contributions are welcome. Please feel free to propose PRs, report issues and suggestions to improve.

Changelog

Check the CHANGELOG for full release history.

Maintainers

License

This package is licensed under the MIT License.

Keywords

FAQs

Package last updated on 14 Jun 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc