Socket
Socket
Sign inDemoInstall

os-keycode

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    os-keycode

A simple library to map keycodes to names.


Version published
Weekly downloads
1
Maintainers
1
Install size
13.0 kB
Created
Weekly downloads
 

Readme

Source

NpmVersion

OS Keycode

This simple library maps keycodes to names. It supports Linux, madOS and Windows keycodes. The lib is intended to be used in Node.js environments. If you need something for the browser, you may take a look at keycode.

Keycode Table

The keycodes used are from here. The following table is just a copy of the linked page. The keycodes are based on US Extended Layout.

KeyMacWindowsLinuxNotes
rbKeyUp12626103
rbKeyDown12528108
rbKeyLeft12325105
rbKeyRight12427106
rbKeyBackspace117814
rbKeyEnter76*28
rbKeyHome11536102
rbKeyEnd11935107
rbKeyPageDown12134109
rbKeyPageUp11633104
rbKeyReturn3613*
rbKeyDelete5146111
rbKeyTab48915
rbKeySpacebar492057
rbKeyShift5610*
rbKeyShiftRight60**Added by author
rbKeyControl5911*
rbKeyMenu5818139The Alt key
rbKeyPrintScreen*42210
rbKeyEscape53271
rbKeyCapsLock572058
rbKeyHelp11447138
rbKeyF112211259
rbKeyF212011360
rbKeyF39911461
rbKeyF411811562
rbKeyF59611663
rbKeyF69711764
rbKeyF79811865
rbKeyF810011966
rbKeyF910112067
rbKeyF1010912168
rbKeyF1110312287
rbKeyF1211112388
rbKeyMacFn63**
rbKeyMacOption58**
rbKeyMacCommand55**
rbKeyMacOptionRight61**Added by author
rbKeyMacCommandRight54**Added by author
rbKeyWinLeftWindow*91*On "Natural" keyboards
rbKeyWinRightWindow*92*On "Natural" keyboards
rbKeyWinApplication11093*On "Natural" keyboards
rbKeyQ128116
rbKeyW138717
rbKeyE146918
rbKeyR158219
rbKeyT178420
rbKeyY168921
rbKeyU328522
rbKeyI347323
rbKeyO317924
rbKeyP358025
rbKeyA*6530
rbKeyS18331
rbKeyD26832
rbKeyF37033
rbKeyG57134
rbKeyH47235
rbKeyJ387436
rbKeyK407537
rbKeyL377638
rbKeyZ69044
rbKeyX78845
rbKeyC86746
rbKeyV98647
rbKeyB116648
rbKeyN457849
rbKeyM467750
rbKey0294811
rbKey118492
rbKey219503
rbKey320514
rbKey421525
rbKey523536
rbKey622547
rbKey726558
rbKey828569
rbKey9255710
rbKeyPeriod4719052
rbKeyComma4318851
rbKeySlash4419153The key with /? generally next to right shift key.
rbKeyNum0829682On numeric keypad or with NumLock
rbKeyNum1839779On numeric keypad or with NumLock
rbKeyNum2849880On numeric keypad or with NumLock
rbKeyNum3859981On numeric keypad or with NumLock
rbKeyNum48610075On numeric keypad or with NumLock
rbKeyNum58710176On numeric keypad or with NumLock
rbKeyNum68810277On numeric keypad or with NumLock
rbKeyNum78910371On numeric keypad or with NumLock
rbKeyNum89110472On numeric keypad or with NumLock
rbKeyNum99210573On numeric keypad or with NumLock
rbKeyMultiply6710655On numeric keypad or with NumLock
rbKeyAdd6910778On numeric keypad or with NumLock
rbKeySubtract7810974On numeric keypad or with NumLock
rbKeyDivide7511198On numeric keypad or with NumLock
rbKeyDecimal6511083On numeric keypad or with NumLock
rbKeyNumEqual81*117On numeric keypad or with NumLock

Usage

The lib has been tested together with iohook for the key code translation. Take a look at example/index.js for more information.

Keyname

Translates a keycode to its keyname:

const keyname = require('os-keycode').keyname; // Platform is determined automatically

// Assume we are on macOS:
console.log(keyname(12)); // { code: 12, key: 'q', keys: [ 'q' ] }
console.log(keyname(59)); // { code: 59, key: 'control', keys: [ 'control' ] }

// Currently the lib does not remove invalid keys (e.g. Win-Key on macOS), so you get a list of possible keys.
console.log(keyname(0)); //  {"keys":["printScreen","winLeftWindow","winRightWindow","a"],"code":"*"}
Result type

The result of keyname has always the following properties:

const keycodeResult = {
  code: 12, // the keycode 
  key: 'q', // the pressed key name, but only if there's no ambiguous key
  keys: [ 'q' ] // an array with the pressed key(s), always present
}

Keycode

Translate a keyname to its keycode:

const keycode = require('os-keycode').keycode; // Platform is determined automatically

// Assume we are on macOS:
console.log(keycode('q')); // 12
console.log(keyname('control')); // 59

Keywords

FAQs

Last updated on 17 Aug 2018

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc