Skip to content

Node module to read and observe the current keyboard layout

License

Notifications You must be signed in to change notification settings

stack-inc/keyboard-layout

This branch is 1 commit ahead of, 1 commit behind atom/keyboard-layout:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

92e1bd0 · Mar 22, 2022
Jun 16, 2021
Sep 13, 2016
May 16, 2019
Oct 17, 2016
Jun 16, 2021
May 9, 2019
Sep 22, 2014
Feb 18, 2015
Sep 22, 2014
Jun 16, 2021
Mar 22, 2022
Oct 14, 2020
Oct 14, 2020

Repository files navigation

keyboard-layout

CI

Read and observe the current keyboard layout.

To get the current keyboard layout, call getCurrentKeyboardLayout. It returns the string identifier of the current layout based on the value returned by the operating system.

const KeyboardLayout = require('keyboard-layout')
KeyboardLayout.getCurrentKeyboardLayout() // => "com.apple.keylayout.Dvorak"

If you want to watch for layout changes, use onDidChangeCurrentKeyboardLayout or observeCurrentKeyboardLayout. They work the same, except observeCurrentKeyboardLayout invokes the given callback immediately with the current layout value and then again next time it changes, whereas onDidChangeCurrentKeyboardLayout only invokes the callback on the next change.

const KeyboardLayout = require('keyboard-layout')
subscription = KeyboardLayout.observeCurrentKeyboardLayout((layout) => console.log(layout))
subscription.dispose() // to unsubscribe later

To return characters for various modifier states based on a DOM 3 KeyboardEvent.code value and the current system keyboard layout, use getCurrentKeymap():

const KeyboardLayout = require('keyboard-layout')
KeyboardLayout.getCurrentKeymap()['KeyS']
/*
On a US layout, this returns:
{
  unmodified: 's',
  withShift: 'S',
  withAltGraph: 'ß',
  withShiftAltGraph: 'Í'
}
*/

About

Node module to read and observe the current keyboard layout

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 48.1%
  • Objective-C++ 26.3%
  • JavaScript 18.5%
  • Python 7.1%