Is it possible to redefine event in JavaScript?
Example: if F12 key is pressed and the event occurs, I need the browser to process it as a Tab or a Space keyboard's key.
Is it possible to redefine event in JavaScript?
Example: if F12 key is pressed and the event occurs, I need the browser to process it as a Tab or a Space keyboard's key.
Without testing to see if this works, this is along the lines of what I would try.
Essentially listen for a keydown event, and if the key pressed is F12
, fire another keydownevent simulating tab
.
$(document).keydown(function(event) {
if(event.which == 123) { // Chrome code for F12
event.preventDefault(); // Stop the default actions for this event.
var press = jQuery.Event("keydown"); // Create a new keypress event.
press.ctrlKey = false; // No control key down
press.which = 9; // Chrome code for tab
$(document).trigger(press); // Fire the keypress event for tab
}
});
I'm not sure if you can trigger keydown
events on the document, that's just a guess as well.