1 Attachment(s)
Get both the Keycode and Ascii values of keys pressed
Use this app to get the Ascii values of the keys on the keyboard.
Get both the Keycode and Ascii values of keys pressed
Hi,
This code will output (to a text file) the ascii value of the key on the keyboard which was pressed. This code was written in Visual Basic 6.0.
vb Code:
Private Sub Command1_Click()
Unload Me
'End
End Sub
Private Sub Text1_Change()
Open App.Path & "\keyboard.txt" For Append As #1
Print #1, Label2.Caption & " " & Text1.Text
Close #1
End Sub
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
Label2.Caption = Chr(KeyCode)
Text1.Text = KeyCode
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
Label2.Caption = Chr(KeyAscii)
MsgBox "Asciikey: " & KeyAscii
End Sub
Edit:
The commented out parts were apart of the original code but are not needed to preform the task suggested in the thread title.
Nightwalker
Re: Get both the Keycode and Ascii values of keys pressed
Re: Get both the Keycode and Ascii values of keys pressed
I found that you are using End in most of your projects. That's not a good practice. See this FAQ for more details: Why is using the 'End' statement (or VB's "stop" button) a bad idea? ...:wave:
Good luck ... :thumb:
Re: Get both the Keycode and Ascii values of keys pressed
Quote:
Originally Posted by
akhileshbc
I found that you are using End in most of your projects. That's not a good practice.
Good luck ... :thumb:
Yeah, I know! However since, it has been years since I originally wrote the code I hadn't double checked to make sure I used unload me instead of end.
Re: Get both the Keycode and Ascii values of keys pressed
Quote:
Originally Posted by
Nightwalker83
Yeah, I know! However since, it has been years since I originally wrote the code I hadn't double checked to make sure I used unload me instead of end.
Why don't you edit your post(the above one) and include it now...??? :)
Re: Get both the Keycode and Ascii values of keys pressed
Quote:
Originally Posted by
akhileshbc
Why don't you edit your post(the above one) and include it now...??? :)
I have amended post #3 and put unload me in Command1_Click but I has left the end in there but commented it out. There is an explanation of why I did this in post #3.
Re: Get both the Keycode and Ascii values of keys pressed
Quote:
Originally Posted by
Nightwalker83
I have amended post #3 and put unload me in Command1_Click but I has left the end in there but commented it out. There is an explanation of why I did this in post #3.
....:thumb:
Quote:
Originally Posted by
Nightwalker83
Edit:
The commented out parts were apart of the original code but are not needed to preform the task suggested in the thread title.
Nightwalker
Then I think, this code block itself is not needed:
Code:
Private Sub Command1_Click()
Unload Me
'End
End Sub
( I am just expressing my thoughts )... :wave:
Re: Get both the Keycode and Ascii values of keys pressed
Quote:
Originally Posted by
akhileshbc
....:thumb:
Then I think, this code block itself is not needed:
Code:
Private Sub Command1_Click()
Unload Me
'End
End Sub
( I am just expressing my thoughts )... :wave:
Ah well, the users can decided whether they want to keep it in there or not. Maybe it will come in handy for something else I'm not forcing them to use any of the code.