From: Satchmo on
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
From: Henning on

"Satchmo" <don.tspa.m(a)dontdo.spam.not> skrev i meddelandet
news:i3o0se$b94$1(a)news.eternal-september.org...
> 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)?

To distinguish it from the '+' key in the alpha part of the keyboard.
Wich has:
Unshifted = +
Shifted = ?
AltGr = \ AltGr is the same as Ctrl+Alt

>
> 2. Why does GetKeyNameText() return "Sys Req" instead of "Print Scrn" (the
> actual label of the key)?

There are dual labels on my swedish keyboard: 'Print Scrn' / 'SysRq'

>
> 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

/Henning


From: Satchmo on
Henning wrote:
> Satchmo wrote:
>>
>> 1. Why does GetKeyNameText() return "Num +" instead of "+" (the actual
>> label of the key)?
>
> To distinguish it from the '+' key in the alpha part of the keyboard.
> Wich has:
> Unshifted = +
> Shifted = ?
> AltGr = \ AltGr is the same as Ctrl+Alt
>

OK, but that key has a *unique* label "+" which may differ in other
languages I guess. How do I retrieve the actual localized label instead
of just hard-coding "+" into the program?

>> 2. Why does GetKeyNameText() return "Sys Req" instead of "Print Scrn" (the
>> actual label of the key)?
>
> There are dual labels on my swedish keyboard: 'Print Scrn' / 'SysRq'

My English keyboard also has that key as dual-labeled. How do I capture
the "Print Scrn" text of that key?

Just curious, I just switched from my English input locale to Swedish
(LCID &H041D) using the APIs MapVirtualKeyEx() and LoadKeyboardLayout()
and I got the following outputs (verbatim by letter/case):

Virtual Key English Swedish
--------------------------------
vbKeyControl Ctrl CTRL
vbKeyShift Shift SKIFT
vbKeyMenu Alt ALT
vbKeySnapshot Sys Req Sys Req
vbKeyBack Backspace BACKSTEG
vbKeyReturn Enter RETUR

Just curious, can you confirm these are the labels on your Swedish
keyboard's keys?
From: Henning on

"Satchmo" <don.tspa.m(a)dontdo.spam.not> skrev i meddelandet
news:i3opf5$vke$1(a)news.eternal-september.org...
> Henning wrote:
>> Satchmo wrote:
>>>
>>> 1. Why does GetKeyNameText() return "Num +" instead of "+" (the actual
>>> label of the key)?
>>
>> To distinguish it from the '+' key in the alpha part of the keyboard.
>> Wich has:
>> Unshifted = +
>> Shifted = ?
>> AltGr = \ AltGr is the same as Ctrl+Alt
>>
>
> OK, but that key has a *unique* label "+" which may differ in other
> languages I guess. How do I retrieve the actual localized label instead of
> just hard-coding "+" into the program?
>
>>> 2. Why does GetKeyNameText() return "Sys Req" instead of "Print Scrn"
>>> (the
>>> actual label of the key)?
>>
>> There are dual labels on my swedish keyboard: 'Print Scrn' / 'SysRq'
>
> My English keyboard also has that key as dual-labeled. How do I capture
> the "Print Scrn" text of that key?
>
> Just curious, I just switched from my English input locale to Swedish
> (LCID &H041D) using the APIs MapVirtualKeyEx() and LoadKeyboardLayout()
> and I got the following outputs (verbatim by letter/case):
>
> Virtual Key English Swedish
> --------------------------------
> vbKeyControl Ctrl CTRL is Ctrl
> vbKeyShift Shift SKIFT is a bold Up-arrow
> vbKeyMenu Alt ALT is Alt
> vbKeySnapshot Sys Req Sys Req is SysRq
> vbKeyBack Backspace BACKSTEG is a backarrow
> vbKeyReturn Enter RETUR is Enter

All labels on my Logitech kb are in english.
Caps Lock, Insert, Delete, Home and so on.
The only diff is the swedish letters ��� ��� and possibly the shifted
AlpaNumeric keys.
@ is AltGr+2, $ is AltGr+4, { is AltGr+7, [ is AltGr+8......

>
> Just curious, can you confirm these are the labels on your Swedish
> keyboard's keys?

/Henning


From: Nobody on
You can see Keyboard Layout for all countries by visiting this page:

Windows Keyboard Layouts:
http://msdn.microsoft.com/en-us/goglobal/bb964651.aspx

Unfortunately they only include the main keyboard part, not navigation keys,
or numeric keypads.

Other links:

Go Global Developer Center:
http://msdn.microsoft.com/en-us/goglobal/default.aspx



 |  Next  |  Last
Pages: 1 2
Prev: Class Access
Next: Copy a Folder