is it possible to assign shortcut keys in javascript

H

H?seyin Erg?n

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.
 
J

Juliette

H?seyin Erg?n said:
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.


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
 
R

Ron

H?seyin Erg?n said:
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.
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/source/dom/public/idl/events/nsIDOMKeyEvent.idl
..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top