KeyCode to ASCII code/character

  • Thread starter Thread starter Ronald Dodge
  • Start date Start date
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.
 
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.
 
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.
 
Back
Top