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

Recommended Answers

All 5 Replies

use sendkeys or API Function.

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?

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
thnx a lot. my problem has een solved

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.