Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes HTML, CSS and JavaScript and the fly likes ALT Key Combination help. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "ALT Key Combination help." Watch "ALT Key Combination help." New topic
Author

ALT Key Combination help.

Yogendra Joshi
Ranch Hand

Joined: Apr 04, 2006
Posts: 213
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.


Meri Zindagi Hain Tab Tak.. Jab Tak Tera Sahara.... Har Taraf Tu Hi Tu Hain SAI Tera Hi Hain Nazara.....
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Look into modifier keys:

event.altKey

Eric
Yogendra Joshi
Ranch Hand

Joined: Apr 04, 2006
Posts: 213
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Apr 04, 2006
Posts: 213
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Apr 04, 2006
Posts: 213
Hey Eric ,

Thanks, You rock. It worked for me.

Yogendra N Joshi.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ALT Key Combination help.