Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Feb 2005
    Location
    Tokyo, Japan
    Posts
    151
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Capturing "Ctrl +s"

    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.
    Code:
    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

  • #2
    Regular Coder feras_wilson's Avatar
    Join Date
    Jul 2005
    Location
    Sweden
    Posts
    129
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Post YES. you can

    Code:
    if(event.keyCode = "your key code" && event.keyCode ="your key code")
    document.execComand("saveas")
    That works. You must only give the keycode
    Exp:
    PHP
    .NET

  • #3
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,065
    Thanks
    4
    Thanked 8 Times in 8 Posts
    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.

  • #4
    Regular Coder
    Join Date
    Mar 2006
    Posts
    726
    Thanks
    35
    Thanked 132 Times in 123 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •