KeyCode to ASCII code/character

R

Ronald Dodge

Is there a way to convert the KeyCode to ASCII code. Main reason for this,
I can then compare the code to the code I need more easily and still be able
to cancel out the keystroke by changing the KeyCode to '0', should it need
to be cancelled. I already have setup most of my general data validation
codes to be ran through the KeyDown Event. Once converted to the ASCII
code, I can use the Chr function to convert it to character, should I need
to do that.
 
E

Eric Isaacs

KeyPress event uses KeyAscii, KeyDown uses KeyCode.
Supposedly if you subtract 144 from KeyCode you should get
the ascii code, but I haven't tested that. Look into
using the KeyPress event instead of the event you're using.
 
D

Dan Artuso

HI,
This may get you started. It will work for any alpha key. You'll have to
figure out the relationship for the other keys:

If KeyCode <> 16 Then
If Shift = 1 Then
Debug.Print Chr(KeyCode) & KeyCode
Else
Debug.Print Chr(KeyCode + 32) & KeyCode + 32
End If
End If

The first If ......<> 16 is there because you get a KeyCode of 16 when
the shift key is pressed.
 

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

Similar Threads


Top