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
    wac
    wac is offline
    Regular Coder wac's Avatar
    Join Date
    Sep 2002
    Location
    Cary, North Carolina, USA
    Posts
    359
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Does anyone do hot keys (accelerator keys)

    I don't know whether this is more appropriate here or in the HTML forum.
    We're trying to implement hot keys for our web applicatoin. Essentially, a key combination (ctrl, or alt + key) should trigger some action.

    I noticed the accesskey attribute and thought to use that, but that simply transfers focus to the element. I really dont want to put a keypress event handler to check every key stroke if I don't have to (The browser is already doing this so...)
    Wayne Christian

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by wac
    I really dont want to put a keypress event handler to check every key stroke if I don't have to (The browser is already doing this so...)
    i'm afraid you'll have to check keystrokes to do this. something along these very basic lines:

    PHP Code:
    document.body.onkeypress=function()
    {
        switch (
    window.event.keycode)
        {
            case 
    "13"window.stop(); break;
            ...
        }


  • #3
    JPM
    JPM is offline
    Regular Coder
    Join Date
    Mar 2004
    Location
    Norway
    Posts
    204
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here is a function I used from another post on the forum


    Code:
    function handleKeyPress(evt) 
    {  
         var nbr;  
          if(window.Event)  nbr=evt.which 
          else nbr = event.keyCode;
    
          if(nbr==39) {  moveX('div1','right') }; // when the user presses right 
          if(nbr==37) {  moveX('div1','left')  }; // when the user presses left   
          if(nbr==38) {  moveY('div1','up',true)    } //  when the uesr presses up 
          if(nbr==40) {  moveY('div1','down',true)  } //  when the user presses down 
    }
    
    
     document.onkeydown = handleKeyPress;


    For the different key codes check out this
    <JPM />

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Be very careful - almost every key combination you can think of already does something, and if you script for it the temptation is to cancel its default action, which can be an accessibility problem, even if you limit the scope (ie, only trap events that happen within specific elements)

    Definitely don't use accesskeys - don't attempt to modify their behavior with scripting.

    What I would suggest is that you limit the browsers which have access to this functionality - maybe IE and mozilla - then test a range of builds on different platforms to find key combinations that are mutually unused, and stick to them. I would also suggest adding key preferences to the application, so that users can re-assign the keys themselves.
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark


  •  

    Posting Permissions

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