Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hot keys in browser based apps

Status
Not open for further replies.

XgrinderX

Programmer
Mar 27, 2001
225
US
Hello!

Is there a way to incorporate hot keys into browser based applications OTHER THAN the accesskey property of certain HTML tags?

I am talking about a user being able to hit like Ctrl-P to pop up a window or something similar. Is there a way to do this?

-Greg
 
There is but there are a some catches. For exmaple in netscape you can't over-ride the default hotkeys (CTRL+P would print in your question). However if you use an unassigned key like CTRL+T then that should be fine. Here is some code for this :

<script language = &quot;javascript&quot;>

function keyDown(e) {
var realkey, keycode;
if (document.all) {
keycode = event.keyCode
realkey = String.fromCharCode(event.keyCode)
ctrlPressed = event.ctrlKey;
} else {
keycode = e.which
realkey = String.fromCharCode(e.which + 96)
ctrlPressed = (e.modifiers == Event.CONTROL_MASK);
}

if (ctrlPressed ) {
switch (realkey) {
case 't' :
//PUT CODE HERE FOR CTRL+T
alert('Done');
}
}
}

document.onkeydown = keyDown
if (!document.all) document.captureEvents(Event.KEYDOWN)

</script>

Hope this helps,

Kev

{afro2]
 
Hey Kev, your emoticon in signature seems strange no ??? Water is not bad as long as it stays out human body ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top