Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

keyboard codes 1

Status
Not open for further replies.

ktighe

Programmer
May 25, 2001
45
US
Does anyone know where I can get a list of all the keyboard codes? I want to use the keybd_event function to simulate key pressing. Also, could someone *briefly* explain what the code is? I mean, is it a decimal number or hex, etc?

I'm very new to vb, and I just downloaded a little piece of code that mimizes all the windows by simulating keyboard entries (win key + m). I'd like to play around with this a bit, so any input would be greatly appreciated.

Kevin
 
Look in the VB help files under SendKeys.

There two types of codes associated with keyboard events: keycodes and ascii codes. They are not the same, because every key on the keyboard has a keycode, but not every key has an ascii code.

Create a form in VB, set its KeyPreview property to True, and run this code:

Private Sub Form1_KeyDown(KeyCode As Integer, Shift As Integer)
Debug.Print "KeyCode = "; KeyCode; ", Shift = "; Shift
End Sub

Private Sub Form_KeyPress(KeyAscii As Integer)
Debug.Print "KeyAscii = "; KeyAscii
End Sub

Then hit some keys on your keyboard. Each key's respective keycode and ascii code will be displayed in the Immediate window, where you can cut and paste them into a text file for future reference. Note that many keys (Delete, Insert for example) do not have ascii codes and the keypress event is not fired when you press those keys.
 
Thanks! That's exactly what I needed.

Kevin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top