470,591 Members | 2,302 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,591 developers. It's quick & easy.

is it possible to assign shortcut keys in javascript

for easy of use;

is it possible to assign Function keys or other keys as a shotcut.
For example, when user presses F2 it will click save button
automatically or vice versa.

are there ANY way of doing this?

thanks.

--
Hüseyin Ergün huseyin[at]su DOT sabanciuniv DOT edu
Sabanci University http://www.turquaz.com
Computer Science Student Tel:90-216-483 9000 / 4837
Jul 23 '05 #1
3 5118
H?seyin Erg?n wrote:

for easy of use;

is it possible to assign Function keys or other keys as a shotcut.
For example, when user presses F2 it will click save button
automatically or vice versa.

are there ANY way of doing this?

thanks.

--
Hüseyin Ergün huseyin[at]su DOT sabanciuniv DOT edu
Sabanci University http://www.turquaz.com
Computer Science Student Tel:90-216-483 9000 / 4837

You don't need javascript for that as long as you stick to ALT+key
combinations (so no functionkeys).
HTML provides you with the ACCESSKEY attribute just for the purpose,
though I'll admit that browser support isn't that good yet.
For more info :
http://www.cs.tut.fi/~jkorpela/forms/accesskey.html
http://www.alistapart.com/articles/accesskeys/

Grz, Juliette
Jul 23 '05 #2
Ron
H?seyin Erg?n wrote:
for easy of use;

is it possible to assign Function keys or other keys as a shotcut.
For example, when user presses F2 it will click save button
automatically or vice versa.

are there ANY way of doing this?

thanks.

--
Hüseyin Ergün huseyin[at]su DOT sabanciuniv DOT edu
Sabanci University http://www.turquaz.com
Computer Science Student Tel:90-216-483 9000 / 4837

First, you may want to take a look at accesskeys
<http://www.w3.org/TR/html401/interact/forms.html#adef-accesskey>. Next,
note that in many browsers, many keys have special meanings, and aside
from IE, other browsers won't allow you to cancel those events. You'll
want to create an event listener for the keypress event, which has been
standardized recently:

if(window.captureEvents) {
window.captureEvents(Event.KeyPress);
window.onkeypress = executeCode;
}
else if (window.attachEvent) {
window.attachEvent(onkeypress, executeCode);
}

function executeCode(evt) {
if(evt==null) {
evt = window.event;
} // IE doesn't pass the event object to the event listener.
var theKey = evt.keyCode;
switch(theKey) {
...
}
}

And so on. The key code differs a little between the browsers. In IE,
it's the Unicode code, while in Gecko-based, it's the list
http://lxr.mozilla.org/seamonkey/sou...OMKeyEvent.idl
..
Jul 23 '05 #3
Ron
Ron wrote:
..., which has been standardized recently: ...


Disregard this phrase, just realized DOM2 Events doesn't support
keypress events. o_O
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Maurice Mertens | last post: by
reply views Thread by Saper\(ek\) | last post: by
1 post views Thread by KaaN | last post: by
1 post views Thread by Emma Middlebrook | last post: by
2 posts views Thread by =?Utf-8?B?SXZvODY=?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.