943,685 Members | Top Members by Rank

Ad:
Jan 1st, 2009
0

Alt+some key in KeyPress event

Expand Post »
hi, i am using rtb. I want to print a specific character when user presses Alt+some key by using chrW() method. I want to detect in KeyPress() event of rtb when user presses Alt+Key. How can i do that? I know i can detect (Alt+x) like combinations in Key_Down event of rtb and then i have used KeyCode = (decimal value of character to be printed). but its not working
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
yuleball is offline Offline
14 posts
since Dec 2008
Jan 1st, 2009
0

Re: Alt+some key in KeyPress event

use sendkeys or API Function.
Reputation Points: 1182
Solved Threads: 392
Posting Sensei
Jx_Man is offline Offline
3,138 posts
since Nov 2007
Jan 1st, 2009
0

Re: Alt+some key in KeyPress event

It already works using the number pad (ie: alt + 251 or whatever), but to do it how you want, you must subclass the form (which is kind of ugly), can't you just on keyup or keydown do something like this:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. richtext1.text = richtext1.text & chrw(keycode)
or am I missing what you need?
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Jan 13th, 2009
0

Re: Alt+some key in KeyPress event

Unfortunately, alt isn't a standard key... so you're pretty much going to have to use the key up and key down events if you want full detection of what they're doing...

is key down - alt is keycode 18 shift 4, key up - just keycode 18 since it's no longer pressed...

numbers on the numeric keypad are listed as 96 through 105 (0 through 9) as opposed to 48 through 57 at the top of the keyboard.

you could do it this way, but it could probably be written better... (4:50 am, im tired)

also though i don't see why you wouldn't just let the user type stuff in with the alt keys / numeric keypad on their own? i'd think it would double type if you both convert their input and make them type it in..? ie: alt 097 would produce 'a' normally, but coding control for it as well would produce 'aa', no?

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. option explicit
  2. private bALT_Down as boolean
  3. private lKeyCode as long
  4.  
  5. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  6. if keycode = 18 and shift = 4 then
  7. bALT_Down = true
  8. else
  9. if bALT_Down = true then getKey(KeyCode)
  10. end if
  11. end sub
  12.  
  13. Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
  14. if keycode = 18 then bALT_Down = false
  15. call GetKeyCode
  16. end sub
  17.  
  18. private sub getKey(keyCode as long)
  19. if keycode >= 96 and keycode <= 105 then
  20. lKeyCode = lKeyCode * 10
  21. lKeyCode = lKeyCode + keyCode - 96
  22. end if
  23. end sub
  24.  
  25. private sub GetKeyCode()
  26. targetcontrol.text = targetcontrol.text + chrw(lKeyCode)
  27. end sub
Reputation Points: 22
Solved Threads: 3
Light Poster
kain_mcbride is offline Offline
25 posts
since Nov 2008
Jan 23rd, 2009
0

Re: Alt+some key in KeyPress event

@kain_mcbride
thnx a lot. my problem has een solved
Reputation Points: 10
Solved Threads: 0
Newbie Poster
yuleball is offline Offline
14 posts
since Dec 2008
Jan 23rd, 2009
0

Re: Alt+some key in KeyPress event

Very good. You can mark the thread as solved now.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Saving to another table
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: hi





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC