Distinguish between '<' and '.' with KeyUp?

R

robotman

I'm trying to capture key presses in a text control on a form and need
to use KeyUp event (vs. Keypress) so I can capture the arrow keys.

It doesn't appear that KeyUp distinguishes between '<' and ',' (since
they are both the same key on the keyboard).

Am I missing something? Is there some event that captures arrow keys
AND would distinguish between '<' and ','?

Thanks.

John
 
V

Vasant Nanavati

Maybe I'm missing something (I'm a bit rusty), but this works for me in
Excel XP:

Private Sub TextBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
Select Case KeyCode
Case 37
MsgBox "Left"
Case 38
MsgBox "Up"
Case 39
MsgBox "Right"
Case 40
MsgBox "Down"
Case 188
If Shift = 0 Then
MsgBox "Comma"
Else
MsgBox "Less than"
End If
Case Else
End Select
End Sub

_________________________________________________________________________
 
R

robotman

One piece of information that I didn't mention is that the characters
are actually coming from a piece of equipment through a keyboard wedge
so there aren't any physical keys being pressed.

I was assuming that the KeyUp wouldn't intrepet the "Shift" correctly
(since it wasn't actually being pressed), but your code does work. I
guess the event looks first at the ASCII it has received and then
assigns the SHIFT value and assigns the keycode based on the ASCII.

It's interesting that when it receives a "<" from the instrument, it
triggers the event twice... once for the ',' and then again for the
virtual shift release.

Thanks for your help.

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top