New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More

keycode-js

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

keycode-js

A JavaScript package with Key Code constants

2.0.3
Version published
Weekly downloads
41K
-0.59%
Maintainers
2
Weekly downloads
 
Created

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@2.0.3/dist/keycode.min.js"></script>

Finally:

window.addEventListener('keyup', function(e) {
  if (e.keyCode === KeyCode.KEY_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@v2.0.3/mod.ts';

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

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

Available Constants

For more information click here.

Key NameConstantValue
CancelKEY_CANCEL3
HelpKEY_HELP6
BackspaceKEY_BACK_SPACE8
TabKEY_TAB9
ClearKEY_CLEAR12
ReturnKEY_RETURN13
EnterKEY_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
SemicolonKEY_SEMICOLON59
EqualsKEY_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 ⌘KEY_LEFT_CMD91
Right ⌘KEY_RIGHT_CMD93
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
SeparatorKEY_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
CommaKEY_COMMA188
PeriodKEY_PERIOD190
SlashKEY_SLASH191
Back QuoteKEY_BACK_QUOTE192
Open BracketKEY_OPEN_BRACKET219
Back SlashKEY_BACK_SLASH220
Close BracketKEY_CLOSE_BRACKET221
QuoteKEY_QUOTE222
MetaKEY_META224

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.

FAQs

Package last updated on 02 Sep 2019

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