The code that I am using below works fine, except for the fact that it adds an ‘s’ if the cursor is left in an input field. How do I do a CTRL–S without having that pesky s being added?
window.onload = function() {
//-------------------------------------------------------------------->>
// CTRL-S FEATURE:
//-------------------------------------------------------------------->>
var isCtrl = false;
document.attachEvent('onkeyup', KeyUpHandler);
document.attachEvent('onkeydown', KeyDownHandler);
function KeyUpHandler() {
if (event.keyCode == 17) {
isCtrl = false;
}
}//end of function
function KeyDownHandler() {
if (event.keyCode == 17) { isCtrl = true }
if (event.keyCode == 83 && isCtrl == true) {
v8_update()
}
}//end of function
}//end of onload()
Much thanks and appreciation for all your help and support in advance,
Cheers
Jay
The
keydownhandler should prevent the default action from continuing — i.e. the character being inserted into the focused element. To accomplish this, use thepreventDefaultmethod of the event object:On can also return false to stop propagation AND prevent default, however, this may be detrimental to other events that are bound to the same element as your event — you may desire propagation, especially when attaching such an event to the document itself. If so, take out the false return.
Try it here: http://jsfiddle.net/LzezS/
Documentation