@hcfy/bk2ea
v0.0.1
Published
An util function for converting keycode in the browser to Accelerator in Electron.
Downloads
4
Readme
bk2ea
An util function for converting keycode in the browser to Accelerator in Electron.
Usage
First, install it:
npm i @hcfy/bk2ea
Then:
import { convert } from '@hcfy/bk2ea'
document.addEventListener('keydown', (e) => {
const a = convert(e.code)
if (a) {
console.log('Electron Accelerator', a)
} else {
console.log("Electron doesn't support this key:", e.code)
}
})
A note for CommandOrControl
// If the second parameter is not passed
convert('MetaLeft') === 'Meta'
convert('ControlLeft') === 'Control'
const macOS = navigator.userAgent.includes('Mac')
// If you press these two keys in macOS
macOS === true
convert('MetaLeft', macOS) === 'CommandOrControl'
convert('ControlLeft', macOS) === 'Control'
// If you press these two keys in Windows or Linux
macOS === false
convert('MetaLeft', macOS) === 'Meta'
convert('ControlLeft', macOS) === 'CommandOrControl'