• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ALT Key Combination help.

 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look into modifier keys:

event.altKey

Eric
 
Yogendra Joshi
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Eric ,

Thanks, You rock. It worked for me.

Yogendra N Joshi.
 
You have to be odd to be #1 - Seuss. An odd little ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic