954,559 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Alt+some key in KeyPress event

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

yuleball
Newbie Poster
14 posts since Dec 2008
Reputation Points: 10
Solved Threads: 0
 

use sendkeys or API Function.

Jx_Man
Nearly a Senior Poster
3,329 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444
 

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:

richtext1.text = richtext1.text & chrw(keycode)

or am I missing what you need?

Comatose
Taboo Programmer
Team Colleague
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
 

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?

option explicit
private bALT_Down as boolean
private lKeyCode as long

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
 if keycode = 18 and shift = 4 then 
  bALT_Down = true
 else
  if bALT_Down = true then getKey(KeyCode)
 end if
end sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
 if keycode = 18 then bALT_Down = false
 call GetKeyCode
end sub

private sub getKey(keyCode as long)
 if keycode >= 96 and keycode <= 105 then
  lKeyCode = lKeyCode * 10
  lKeyCode = lKeyCode + keyCode - 96
 end if
end sub

private sub GetKeyCode()
 targetcontrol.text = targetcontrol.text + chrw(lKeyCode)
end sub
kain_mcbride
Light Poster
25 posts since Nov 2008
Reputation Points: 22
Solved Threads: 3
 

@kain_mcbride
thnx a lot. my problem has een solved

yuleball
Newbie Poster
14 posts since Dec 2008
Reputation Points: 10
Solved Threads: 0
 

Very good. You can mark the thread as solved now.

Comatose
Taboo Programmer
Team Colleague
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You