Assume that i have two pages: Client page
Items page
in both pages i have an Add buttons, is it possible to create a shortcut keys like ctrl + A will click on the Add button and ctrl + B will be for submitting and ctrl + E for new Entity ?
A simple way to detect multiple keydowns to use as shortcuts:
let keysDown = {};
window.onkeydown = function(e) {
keysDown[e.key] = true;
if (keysDown["Control"] && keysDown["a"]) {
//do what you want when control and a is pressed for example
console.log("control + a");
}
else if( keysDown["Control"] && keysDown["b"] ){
console.log("control + b");
}
}
window.onkeyup = function(e) {
keysDown[e.key] = false;
}
Yes, this is definitely possible!
You can build the code yourself, but there is no point in reinventing the wheel, so try one of pre-build libraries. For example: https://craig.is/killing/mice
You can create custom shortcuts and bind them to javascript functions. These functions will than process the action.
Good luck!
Also see: How can I add a JavaScript keyboard shortcut to an existing JavaScript Function?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With