|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Reading keyboard's key names (Internalization)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
Show quote
Hide quote
"Satchmo" <don.tspa.m@dontdo.spam.not> skrev i meddelandet To distinguish it from the '+' key in the alpha part of the keyboard.news:i3o0se$b94$1@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)? Wich has: Unshifted = + Shifted = ? AltGr = \ AltGr is the same as Ctrl+Alt > There are dual labels on my swedish keyboard: 'Print Scrn' / 'SysRq'> 2. Why does GetKeyNameText() return "Sys Req" instead of "Print Scrn" (the > actual label of the key)? Show quoteHide quote > /Henning> 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 wrote:
> Satchmo wrote: OK, but that key has a *unique* label "+" which may differ in other >> >> 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 > 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 My English keyboard also has that key as dual-labeled. How do I capture >> actual label of the key)? > > There are dual labels on my swedish keyboard: 'Print Scrn' / 'SysRq' 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?
Show quote
Hide quote
"Satchmo" <don.tspa.m@dontdo.spam.not> skrev i meddelandet All labels on my Logitech kb are in english.news:i3opf5$vke$1@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 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...... > /Henning> Just curious, can you confirm these are the labels on your Swedish > keyboard's keys? Henning wrote:
Show quoteHide quote > Satchmo wrote: OK, the function GetKeyNameText() is not accurate or useful then. It was >> 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...... wonderful to think I could use this function to get the name of the key (wasn't that the idea (Microsoft's)? That function should be removed from the API! Any thoughts? Anyways, I'll just use resource files and put in the name of the function keys in English for all languages (CTL, ALT, PRINT SCR, ENTER, +, etc). Any objections anyone? 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
ini in app.pth works for xp, best practice for Vista/W7?
Class Access compile error Only udts defined in public object modules can be coerced ... Make a Backup Old VB Project doesn't work with New Office or Windows 7 Instantiation Reconnection issue between Winsock Server(VB6) and TCP Client (VB.NET) Error 32765 Cleanup remnants RegClean Revisited |
|||||||||||||||||||||||