|
-
Jan 26th, 2000, 09:38 PM
#1
Thread Starter
Hyperactive Member
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
-
Jan 26th, 2000, 10:08 PM
#2
New Member
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
-
Jan 26th, 2000, 10:52 PM
#3
Here's a couple of Functions I've written to Convert between ASCII and KeyCodes, Either way:
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: ASCII = GetAscII(KeyCode, [Shift])
Usage: KeyCode = GetKeyCode(ASCII)
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|