Satchmo
2010-08-09 04:40:42 UTC
Hi all! I'm trying to make my little app "international-aware" and I'm
using the GetKeyNameText() function to retrieve the name of a key. The
function works good in getting the key names based on the current
keyboard layout. The reason I'm doing this is because users of my app
will be able to access the settings to customize the program's hotkeys,
so I would like to display these in the user's language.
For example, the following key name retrieval work:
GetKeyText(vbKeyControl ) -> "Ctrl"
GetKeyText(vbKeyShift ) -> "Shift"
GetKeyText(vbKeyMenu ) -> "Alt"
However, the following don't:
GetKeyText(vbKeyAdd ) -> "Num +"
GetKeyText(vbKeySnapshot) -> "Sys Req"
Questions:
1. Why does GetKeyNameText() return "Num +" instead of "+" (the actual
label of the key)?
2. Why does GetKeyNameText() return "Sys Req" instead of "Print Scrn"
(the actual label of the key)?
Below the code I'm using, thanks in advance for any help! -Satchmo
--
Private Declare Function GetKeyNameText Lib "user32" Alias
"GetKeyNameTextA" (ByVal lParam As Long, ByVal lpBuffer As String, ByVal
nSize As Long) As Long
Private Declare Function MapVirtualKey Lib "user32" Alias
"MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long
Public Function GetKeyText(KeyCode As VBRUN.KeyCodeConstants) As String
Const MAXBUFFERSIZE As Long = 256
Dim buf As String
Dim chars As Long
Dim ScanCode As Long
ScanCode = MapVirtualKey(KeyCode, 0)
buf = Space$(MAXBUFFERSIZE)
chars = GetKeyNameText((ScanCode * 2^16), buf, MAXBUFFERSIZE - 1)
GetKeyText = Left(buf, chars)
End Function
using the GetKeyNameText() function to retrieve the name of a key. The
function works good in getting the key names based on the current
keyboard layout. The reason I'm doing this is because users of my app
will be able to access the settings to customize the program's hotkeys,
so I would like to display these in the user's language.
For example, the following key name retrieval work:
GetKeyText(vbKeyControl ) -> "Ctrl"
GetKeyText(vbKeyShift ) -> "Shift"
GetKeyText(vbKeyMenu ) -> "Alt"
However, the following don't:
GetKeyText(vbKeyAdd ) -> "Num +"
GetKeyText(vbKeySnapshot) -> "Sys Req"
Questions:
1. Why does GetKeyNameText() return "Num +" instead of "+" (the actual
label of the key)?
2. Why does GetKeyNameText() return "Sys Req" instead of "Print Scrn"
(the actual label of the key)?
Below the code I'm using, thanks in advance for any help! -Satchmo
--
Private Declare Function GetKeyNameText Lib "user32" Alias
"GetKeyNameTextA" (ByVal lParam As Long, ByVal lpBuffer As String, ByVal
nSize As Long) As Long
Private Declare Function MapVirtualKey Lib "user32" Alias
"MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long
Public Function GetKeyText(KeyCode As VBRUN.KeyCodeConstants) As String
Const MAXBUFFERSIZE As Long = 256
Dim buf As String
Dim chars As Long
Dim ScanCode As Long
ScanCode = MapVirtualKey(KeyCode, 0)
buf = Space$(MAXBUFFERSIZE)
chars = GetKeyNameText((ScanCode * 2^16), buf, MAXBUFFERSIZE - 1)
GetKeyText = Left(buf, chars)
End Function