Created
February 13, 2018 07:17
-
-
Save Saren-Arterius/604c92208e882381ed7b2c771423777a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Dog Square Custom Keymap | |
// @version 0.1 | |
// @description Custom keymap | |
// @author Saren | |
// @match https://tobychui.github.io/Dog-Square/ | |
// @grant none | |
// @run-at document-start | |
// ==/UserScript== | |
// ,./kl;iop890 | |
let map = { | |
'188': 96, | |
'190': 96, | |
'191': 110, | |
'75': 97, | |
'76': 98, | |
'186': 99, | |
'73': 100, | |
'79': 101, | |
'80': 102, | |
'56': 103, | |
'57': 104, | |
'48': 105, | |
}; | |
let orig = EventTarget.prototype.addEventListener; | |
EventTarget.prototype.addEventListener = function (...args) { | |
if (args[0] !== 'keydown') { | |
orig(...args); | |
return; | |
} | |
let oFn = args[1]; | |
args[1] = function (e) { | |
let newCode = map[e.which.toString()]; | |
console.log('Pressed', e); | |
if (newCode) { | |
Object.defineProperty(e, 'which', { | |
value: newCode, | |
writable: false | |
}); | |
} | |
oFn(e); | |
}; | |
orig(...args); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment