Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ALT Key Combination help.

 
Yogendra Joshi
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ranchers ,

I have come across a situation where in i have a textbox with me and i want to use a combination of ALT + P as a shortcut to printout a customized receipt.

I wrote a sample javascript code which captures the keycode for ALT and i wanted to test if javascript is able to detect that i pressed ALT key , I succeeded in it. I made a small textbox and on its onKeyDown event , i gave a alert saying ALT is Pressed. This is half part , now i want to also include the P part in it , i mean ALT + P , if this combination is used i want to redirect the user to a page saying successfully forwarded.

Can you javascript freaks help me with this ?

Thanks in advance.
Yogendra N Joshi.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look into modifier keys:

event.altKey

Eric
 
Yogendra Joshi
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Eric ,

thanks for the response but i have already been able to get ALT keypress event trapped.. What i want is , how i can use the combination of ALT + P , how do i add this + P to ALT and then let the user go on the success page.

Please let me know..
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The modifier key can be detected with the other keys.

You do not look for the keyCode of 18

You are looing for the keyCode of 80 with the modifier key event.altKey

Eric
 
Yogendra Joshi
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you mean to say something like this :



I tried with the above code but i guess there is something wrong in the if block which i have coded , right now the flow goes to else with the above code.. Also using javascript how can i forward to a html page ? Please answer both my queries..

Thanks.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well you code is not cross browser friendly:



I only tested this on Firefox 1.5 on Linux, should be fine on IE.

Eric
 
Yogendra Joshi
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Eric ,

Thanks, You rock. It worked for me.

Yogendra N Joshi.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic