cheatcode-js
This library provides a simple interface for checking cheat codes in keyboard inputs.
Usage
JavaScript
const cheatCode = new CheatCode()
document.addEventListener('keyup', event => {
if (cheatCode.checkKeyboardEvent(event)) {
alert('cheater');
}
}
Angular
cheatCode = new CheatCode();
@HostListener('document:keyup', ['$event'])
onKeyup(event: KeyboardEvent) {
if (this.cheatcode.checkKeyboardEvent(event)) {
alert('cheater');
}
}
Configuration
The CheatCode constructor takes 2 optional parameters.
The first is an array of strings which represent a cheat code.
The second is a configuration object.
The only configuration option at this time is requireModifier
which can be a string for a modifier key, if the cheatcode should only trigger when the modifier key is pressed while entering the combination