Hi!
Is any way to convert a key code to the ascii numbers? I saw a API function, but I no longer have it.
------------------
Thanks,
John, 14 years old
Printable View
Hi!
Is any way to convert a key code to the ascii numbers? I saw a API function, but I no longer have it.
------------------
Thanks,
John, 14 years old
John,
Please see the following examples and reference the help files:
This example converts text entered into a TextBox control to uppercase. To try this example, paste the code into the Declarations section of a form that contains a TextBox, and then press F5 and enter something into the TextBox.
Private Sub Text1_KeyPress (KeyAscii As Integer)
Char = Chr(KeyAscii)
KeyAscii = Asc(UCase(Char))
End Sub
and the example:
debug.print asc("m")
109
debug.print chr(109)
m
Hope that's what you're looking for,
Michael
Here's a couple of Functions I've written to Convert between ASCII and KeyCodes, Either way:
Usage: ASCII = GetAscII(KeyCode, [Shift])Code:Private Declare Function VkKeyScan Lib "user32" Alias "VkKeyScanA" (ByVal cChar As Byte) As Integer
Private Declare Function ToAscii Lib "user32" (ByVal uVirtKey As Long, ByVal uScanCode As Long, lpbKeyState As Byte, lpwTransKey As Long, ByVal fuState As Long) As Long
Function GetKeyCode(ByVal AscII As Long) As Long
GetKeyCode = Val("&H" & Right$(Hex$(VkKeyScan(AscII)), 2))
End Function
Function GetAscII(ByVal KeyCode As Long, Optional ByVal Shift As Boolean = False) As Long
Dim sKeys(255) As Byte
Dim lAscII As Long
sKeys(KeyCode) = 1
sKeys(16) = Abs(Shift) * 128
Call ToAscii(KeyCode, 0&, sKeys(0), lAscII, 0&)
GetAscII = lAscII
End Function
Usage: KeyCode = GetKeyCode(ASCII)
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]