Skip to content

Instantly share code, notes, and snippets.

@sergiovilar sergiovilar/init.js
Created Oct 2, 2017

Embed
What would you like to do?
Translate DVORAK hotkeys to QWERTY in Atom
atom.keymaps.addKeystrokeResolver(({keystroke, event}) => {
var qKeys = "q w e r t y u i o p [ ] a s d f g h j k l ; ' z x c v b n m , . /".split(' ')
, dvorakKeys = "' , . p y f g c r l / = a o e u i d h t n s - ; q j k x b m w v z".split(' ')
, key = keystroke
, replaced = [];
if(event.type == 'keydown' && event.metaKey && event.key !== 'Meta' && keystroke.startsWith('cmd-')) {
for(var i in dvorakKeys) {
if(
key.indexOf('-' + dvorakKeys[i]) > -1 &&
replaced.indexOf(dvorakKeys[i]) == -1 &&
(key.endsWith('-' + dvorakKeys[i]) || key.indexOf('-'+dvorakKeys[i]+'-') > -1)
) {
key = key.replace('-' + dvorakKeys[i], '-' + qKeys[i]);
replaced.push(qKeys[i]);
}
}
if(keystroke !== key) console.log(keystroke + ' translated to ' + key);
return key;
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.