...

View Full Version : Capturing "Ctrl +s"



Yakisoba
05-24-2006, 12:42 PM
I have a form that I would like the user to be able to submit when Ctrl +S is pressed...

Right now everything works,and I can capture any single key(except Alt & Ctrl). Is it possible to capture the combination. Everything I try brings up the browser "Save As" box...I would like my own function to be triggered.

My form contains a javascript function that picks out certain keystrokes using a switch/case and the ascii code of the key.


function key(){
switch (e._e.keyCode){
case 37: //<- LEFT ARROW
somthing()
break;
case 38: //^ UP ARROW
somthingElse();
break;
case ???: //Ctrl +s
save()
....
....
....
}


Any suggestions?

Thanks.

Yakisoba

feras_wilson
05-24-2006, 02:08 PM
if(event.keyCode = "your key code" && event.keyCode ="your key code")
document.execComand("saveas")


That works. You must only give the keycode:thumbsup:

miranda
05-24-2006, 02:19 PM
I found a great piece of code at http://www.arraystudio.com/blog/item/64 scroll down to the piece of code by Jeff Gordon (DisableKeys.js)


This has worked great for me except preventing events in IE that are triggered onkeydown and not onkeypress I am having difficulties preventing the combination alt+left arrow from being used to go back 1 page in history.

mrhoo
05-24-2006, 05:00 PM
altKey,shiftKey and ctrlKey are not caught as keystrokes but are boolean modifiers of every event keystroke

in your switch case for s check for event.ctrlKey==true



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum