Reading keyboard's key names (Internalization)

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
0
Satchmo
8/9/2010 4:40:42 AM
vb.general.discussion 1016 articles. 0 followers. Follow

5 Replies
1850 Views

Similar Articles

[PageSpeed] 57

"Satchmo" <don.tspa.m@dontdo.spam.not> skrev i meddelandet 
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)?

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


0
Henning
8/9/2010 10:36:21 AM
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?
0
Satchmo
8/9/2010 11:40:15 AM
"Satchmo" <don.tspa.m@dontdo.spam.not> skrev i meddelandet 
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

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


0
Henning
8/9/2010 12:19:19 PM
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



0
Nobody
8/9/2010 1:24:12 PM
Henning wrote:
> Satchmo wrote:
>> 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......

OK, the function GetKeyNameText() is not accurate or useful then. It was 
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?
0
Satchmo
8/13/2010 4:09:48 AM
Reply:

Similar Artilces:

Reading .wks file
Greetings...according to the Excel "help" file, as well as the file extension listing, I *should* be able to read an *.wks file, but Excel insists that it cannot. I am pretty sure the file was created in Microsoft Works. Is there a converter somewhere that I can download/install? Cheers - S2 Excel can read Works 2.0, not later. You have to save them in Works as excel files or Works 2.0 or get a commercial converter. -- Regards, Peo Sjoblom "Skip Stocks" <anonymous@discussions.microsoft.com> wrote in message news:AFC110E0-641D-4D87-9464-B930CC41CF02@microsoft....

File won't open as read only
I have a file that is in use, but another person opens it and it doeasn't display the "file is in use" message. Is there a setting or fix? Hi have you shared this file? -- Regards Frank Kabel Frankfurt, Germany John wrote: > I have a file that is in use, but another person opens it > and it doeasn't display the "file is in use" message. Is > there a setting or fix? The file is on a network share. The share has all the appropriate permissions. >-----Original Message----- >Hi >have you shared this file? > >-- >Regards >Frank Ka...

excel duplicate range name warning
When copying worksheets in excel it is possible to duplicate range name causing local (worksheet specific) range names. Sometimes Excel warn you when this is going to happen, sometimes the warning does no appear. Could anyone tell me the rules as to wether the warning i given or no -- Message posted from http://www.ExcelForum.com I think you get the warning when there are formulae on the sheet you are copying referring to range names that could refer to either the new or the old workbook. "Key_masteruk >" wrote: > When copying worksheets in excel it is possible to duplica...

How to give other users read-only access to Calendar
I want to allow the group Everyone to have read-only access to a calendar in a certain mailbox. I can do this by granting the permission 'Full mailbox access' (under 'Mailbox rights', under 'Exchange Advanced', for the particular user). However this also allows people to to do everything (ie: they become read-write users). I notice that every mailbox in the system has 'Read permissions' granted to group Everyone. This does not allow other people to open items in the mailbox, but as I understand it, permits Exchange Server and Outlook to do shared meetin...

Read mail arn't marked as read anymore
After an SP upgrade of my Office 2000 the priviewed mail doesnt get marked as read anymore. I have tried to change the time (Tools->Options->Priview pane) from 2 -> 3 -> 4 seconds but nothing works. The only way to mark a mail as read is either to open it or right click it and chose Mark as read. Since I only use the priview pane this is very anoying for me. Is this a bug or has some setting changed with the SP? ...

reading confirmation
Good day, I have a problem with outlook. When they send a message to me that demands the shipment of a reading confirmation, even if I accept, the reading confirmation does not come received from the sender. Someone knows from what depends and in which way I can resolve the problem? Thanks for the eventual answers. Niki In news:eht7fo$251$1@fata.cs.interbusiness.it, Niki <nicola.pantaleo@yahoo.it> typed: > Good day, > > I have a problem with outlook. When they send a message to me that > demands the shipment of a reading confirmation, even if I accept, the > read...

"Unblock" feature should be optional when reading e-mail in CRM
When viewing e-mail messages in CRM, a line appears saying "Unblock" to allow the full message content to be read. Can this be made a configurable server or security setting? We are trying to reduce "clicks" as much as possible. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agre...

The memory could not be "read".
I'm at work yesterday afternoon responding to e-mail on my desktop, and Adobe pops up from the toolbar with a notice that there is an update available for Acrobat. I accept the download, keep plugging away at my e-mail, and install it when it's done. It runs through the install, tells me that I should restart, but I ignore it and keep working. It's near the end of the day and I'm going to be going home soon anyways. I forgot to turn it off when I left. Came in this morning, restarted it through the Start menu, and rebooted. Upon reaching the "Ctrl+Alt+Del" ...

Printing names
There is a View option to see formulae, so I can print the formulas. What about names? I can write code to list the names, put I'd rather print with names displayed. Is there an option to do this in Excel 97, 2000, 2002, or 2003? Nothing built into excel that I know. But if you're just looking (not printing), then change the window's zoom to 39% (or smaller) and you'll see the names of the ranges. I'd use Jan Karel Pieterse's (with Charles Williams and Matthew Henson) Name Manager: You can find it at: NameManager.Zip from http://www.oaltd.co.uk/mvp (Instead of ...

NAME OF AUTOSHAPE
How do you find the name of an autoshape? If you select the shape, its name will appear in the Name Box to the left of the Formula Bar. In VBA, you can use Selection.Name -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "Ronbo" <Ronbo@discussions.microsoft.com> wrote in message news:5D67F213-0CE6-415E-8418-097E8D87EE8B@microsoft.com... > How do you find the name of an autoshape? "Ronbo" wrote: > How do you find the name of an autoshape? Never mind. I found a MsgBox routine on the discussion group...

Range names in financial projections; to enable getting data from a specific period
Hello -- In projecting cash flows over time, I want to name the summary rows (revenue, expenses, capital expenditures, etc.) so that I can easily get each row's value for a specific period, for further processing. I have seen the method where columns and rows are named, and the intersection of a column and row is named using their combination, separated by a space (as the intersection operator). Can anyone recommend methods which have worked for them? Thanks for any help. Larrry Mehl mehl_at_cyvest.com Select table and set it up via Insert/Name/Creat -- Message posted from http:/...

Renaming user account and accessing old account named mail
Using W2K3 server and Exchange 2K3. I need to rename a users account. First I'd like to know the proper way to do it. Is right clicking and choosing rename the most appropriate and will it change the name in all the necessary places (display, etc). Or should I go to properties and modify the name on the general tab, the modify the name on the Exchange General tab and then on the account tab? Second, once the account has been renamed, where will the e-mail from the prevous account be? Will it show up in the inbox of the new account? Understand - all you are doing in essence is chang...

how can i copy a document to a CD without making it read only?
HOW CAN I COPY A DOCUMENT TO A CD WITHOUT MAKING IN READ ONLY? You can't. It is not the file, but the media, that is read only. Even CD-RW media does not allow editing a file on the CD. Copy te file from CD to HD, mak edits and if a CD-RW you should be able to burn the edited file back to the CD. hth "DON" wrote: > HOW CAN I COPY A DOCUMENT TO A CD WITHOUT MAKING IN READ ONLY? ...

Unable to Read Japanese Email
I correspond with several Japanese users and can read emails from some of them without a problem, but emails from others are nothing but a series of ?????. In one case, I can read one email but not another from the same sender. Changing the Encoding doesn't help. Sending emails in Japanese to them without a problem...they can read it fine. Would appreciate any suggestions/solutions as I'm stumped. I'm using Outlook 2003 on a Windows XP Home operating system. Japanese language support is installed. ...

Transferring read e-mail to another folder
Hello I was wondering whether there was a way in which I could automatically transfer my e-mail that has been read into another folder, such as "Old e-mail" or something like that? Thanks ...

Cannot insert duplicate key in object 'SY60100'
Using Great Plains 7.0. During Create Company process - trying to add one company, I received an error during the very last step of "Create Company Information". The error is: [Microsoft][ODBC SQL Server Driver][SQL Server]Violation of PRIMARY KEY constraint 'PKSY60100'. Cannot insert duplicate key in object 'SY60100'. make sure that the DYNAMICS database is owned by DYNSA make sure that the TWO database, if present is owned by DYNSA. THis you will have to check by using SQL enterprise manager or Query Analyzer. ------ Robert "mrosa" <mrosa@ProfitL...

use the insert key
I use a table in word and I want to insert part of a date over a date using the insert key. How can I turn on the insert key pad? I'm not aware of any "insert key pad." The Insert key toggles between Insert and Overtype, and it's not clear which of these you're trying to do. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA http://word.mvps.org "ladyfisher" <ladyfisher@discussions.microsoft.com> wrote in message news:B4E25894-A127-41CE-AD2C-FB251DD83B52@microsoft.com... >I use a table in word and I w...

Outlook not marking read emails as read
Hi - We have 1 computer that is doing the oddest thing, anytime the customer reads the last email in his box, exit's out of email and then comes back in, that email is now marked as unread - it's the weirdest thing I have seen in a long time. I uninstalled office XP, rebooted, then reinstalled and applied the 2 service packs, hoping that would fix it, but it didn't. So now I'm stuck and was wondering if anybody out there has any thoughts on what to do.... thanks! Gerri Urban gurban@ci.broomfield.co.us ...

Records with the same last name disappear...
I have a table with client names and another table with the family members of the client. Those are connected via a relationship. I have a query to generate a list of only those clients who are active as of a certain date. I have created a report which lists both the clients and the family members with a left join. However, if there are multiple clients with the same name that appears in the query, only the client who is last alphabetically appears. Any other records with that last name are missing from the report. For example, Nicole Smith appears, but Kelly and Jessica Sm...

Suggested reading
Any suggested reading for Access 2003 VBA? I have both "Step by Step Access 2003" And "Microsoft Access 2003 VBA for Dummies" (how Ironic) and niether have been very helpful. Try this book. It's a winner: Access 2003 VBA Programmer's Reference by Patricia Cardoza, Teresa Hennig, Graham Seach, and Armen Stein http://www.amazon.com/Access-2007-Programmers-Reference-Programmer/dp/0470047038/ref=sr_1_1/104-1181757-2327103?ie=UTF8&s=books&qid=1185824619&sr=8-1 -- Arvin Meyer, MCP, MVP http://www.datastrat.com http://www.mvps.org/access http://www.access...

changing product key
how do i change my product key,<br> <br> can i do it without reinstalling office 2008 for mac because it is a hassel<br> <br> but when i try reinstalling office numerous times the installer does not allow me to change the key and skips over that stage and continues to install the same way as before<br> <br> how can i do this???!<br> <br> thanks~ See here: http://www.entourage.mvps.org/version/license_version.html#reset jj@officeformac.com wrote: > how do i change my product key, > > can i do it without reinstalling office 2008 for mac ...

Message(s) Not Being Marked As Read
I have "Mark message read after displayed for" '0' seconds checked. But in my Junk e-mail folder the messages don't get marked as read when I select them, only when I open them. I'm assuming this is because there isn't a the reading pane for the Junk e-mail folder even though I have "Show reading pane" checked in "Layout" a reading pane doesn't display in the Junk email right pane. Is this normal? I'd rather just click on the message instead of opening the message to mark it as read. James > I'd rather just c...

Controling READ ONLY and READ/WRITE mode when opening a project PS
Hello All, I was looking for a way to force users to select between READ ONLY and READ/WRITE instead of it defaulting to READ/WRITE when opening projects in MS Project 2007. Any suggestions would be a huge help. Thanks, Eric Eric -- Short of using custom software development, there is no way to force this issue with your PMs. If you want to try the custom software development route, then please repost your message in the microsoft.public.project.developer newsgroup. Otherwise, make this a training and performance issue with your PMs. Hope this helps. -- Dale A. Ho...

Read/Not read
Hello We have an exhange-server environment. The Boss' secretary need's to be able to read the Boss' mail, without the messages being marked as read, within outlook 2003. She can access the Boss mail, but all mail she reads is being marked as read, hence the boss can not figure out what he has seen/not seen. What is the solution? Thanx a lot /Jan Hi Towli. There is no way to marked as unread automatically, Just she should be tick the unread option on the pop up menu after she open the her boss e-mail. Once you right click button one of e-mail on the e-mail list, you w...

read an ascii file with fopen
I try to open with fopen and read an ascii file, line by line, but get garbage - among the right data in the CString variable that is filled with this line data. Can someone copy&paste the right code how to so that? Thanks in advance. Mark "Mark" <mark@chasan.ar> wrote in message news:%23sPmEzsgGHA.2208@TK2MSFTNGP05.phx.gbl... > I try to open with fopen and read an ascii file, line by line, but get > garbage - among the right data in the CString variable that is filled with > this line data. > > Can someone copy&paste the right code how to so that?...