...

View Full Version : Does anyone do hot keys (accelerator keys)



wac
08-12-2004, 02:49 PM
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...)

jbot
08-12-2004, 04:27 PM
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:


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

JPM
08-12-2004, 05:49 PM
Here is a function I used from another post on the forum



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 (http://cross-browser.com/x/examples/arrowkeys.html)

brothercake
08-13-2004, 02:25 AM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum