Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/atom/keyboard-layout
Node module to read and observe the current keyboard layout
https://github.com/atom/keyboard-layout
Last synced: about 2 months ago
JSON representation
Node module to read and observe the current keyboard layout
- Host: GitHub
- URL: https://github.com/atom/keyboard-layout
- Owner: atom
- License: mit
- Archived: true
- Created: 2014-09-22T21:20:54.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2022-10-11T23:06:27.000Z (almost 2 years ago)
- Last Synced: 2024-07-11T15:28:42.829Z (2 months ago)
- Language: C++
- Homepage:
- Size: 133 KB
- Stars: 61
- Watchers: 14
- Forks: 47
- Open Issues: 23
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
##### Atom and all repositories under Atom will be archived on December 15, 2022. Learn more in our [official announcement](https://github.blog/2022-06-08-sunsetting-atom/)
# keyboard-layout
[![CI](https://github.com/atom/keyboard-layout/actions/workflows/ci.yml/badge.svg)](https://github.com/atom/keyboard-layout/actions/workflows/ci.yml)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.```js
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.```js
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()`:```js
const KeyboardLayout = require('keyboard-layout')
KeyboardLayout.getCurrentKeymap()['KeyS']
/*
On a US layout, this returns:
{
unmodified: 's',
withShift: 'S',
withAltGraph: 'ß',
withShiftAltGraph: 'Í'
}
*/
```