PDA

Click to See Complete Forum and Search --> : Key Codes -> ASCII?


Jhd.Honza
Jan 26th, 2000, 08:38 PM
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

MichaelVB
Jan 26th, 2000, 09:08 PM
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

Aaron Young
Jan 26th, 2000, 09:52 PM
Here's a couple of Functions I've written to Convert between ASCII and KeyCodes, Either way:
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: ASCII = GetAscII(KeyCode, [Shift])
Usage: KeyCode = GetKeyCode(ASCII)


------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
ajyoung@pressenter.com