![]() |
![]() |
All Products | Support | Search | microsoft.com Guide | |||||||||||||||||
|   |
![]() |
||||||||||||||||||
|
|||||||||||||||||||
| ARCHIVES | These archives are not updated | |||||
The Professional Developer's Site for Software Globalization InformationARCHIVESBack to ARCHIVES |
ALT GR Madness: Shortcut Keys for International Users of Windows-based Applicationsby Nadine Kano QuickLookThere are three distinct ways of using keystroke combinations as commands, all of which are subject to the same ALT GR madness:
You can read through this article, or choose a topic of interest from this list.
OverviewWhen you're creating a global application for Microsoft® Windows®, you sometimes have to think about obscure details, which, if ignored, can render your application all but useless in some locales. Let's consider the difficulty of assigning unique shortcut key combinations to commands in applications with lots of commands, such as Microsoft Word. Shortcut keys allow users to save files or to cut and paste by pressing one or two keys on the keyboard, instead of activating a menu and a dialog box. In the English version of Word, for example, pressing CTRL+S saves the file the user is currently editing. A user can see a complete list of all the shortcut key combinations in Word by choosing Customize from the Tools menu and selecting the Keyboard dialog box, and then choosing the items in the Commands listbox. Not all commands have pre-assigned shortcut keys, but a number of them do; and some, such as Open from the File menu, have more than one. Shortcut keys take the form of F1 through F12, ALT+<key>, ALT+SHIFT+<key>, or CTRL+ALT+<key>, where <key> can be a number, letter, or punctuation character, or a function key. Even with these available alternatives, the number of possible key combinations is limited. It gets worse, because on many European keyboard layouts, the CTRL+ALT+<key> shortcut combinations conflict with ALT GR key combinations. Where in the World is ALT GR?ALT GR on European keyboards is the right ALT key. If you get a hold of a French or German keyboard (or look at a picture of the layout in your MS-DOS® documentation), you'll see that some key tops have three or four characters on them. The first character is generated by pressing the key. The second is generated by pressing SHIFT+<key>. The third (and this is where it gets interesting) is generated by pressing ALT GR+<key>, and the fourth by pressing SHIFT+ALTGR+<key>. On U.S. keyboard layouts, the right ALT key is the same as the left ALT key--pressing this key generates a VK_MENU message. When you are running U.S. or European editions of Windows, however, you can change your keyboard layout to any of a number of different international keyboard layouts using the Control Panel (this is independent of your hardware). If you install the Turkish keyboard layout, for example, the left ALT key will still generate a VK_MENU message, but the right ALT key will now generate two messages: VK_MENU and VK_CONTROL, as though you had pressed the key combination CTRL+ALT. ALT GR Problems and Some SolutionsHere's the problem. Say I am using U.S. version of Microsoft Word for Windows 95® with the Pan European edition of Windows 95, entering text using the Turkish keyboard layout. I want to enter the character 'ß' so I type ALT GR+S. Windows receives a WM_KEYDOWN message indicating that the CTRL, ALT, and S keys were pressed simultaneously. ALT+CTRL+S just happens to be the shortcut key combination for Split Document Pane in the English edition of Word. So what should Word do, split the document pane, or generate the character 'ß'? There are a couple of ways around this predicament.
These workarounds are not completely satisfactory; after all, not using any CTRL+ALT key combinations limits the total number of shortcut keys you can assign, especially if shortcut combinations are customizable, as they are in Word. A Better Solution: Distinguishing Between ALT GR and CTRL+ALTA better solution is to determine whether a WM_KEYDOWN message is generated via a CTRL+ALT key combination or via the ALT GR key. This may seem obvious, but you couldn't do this under Windows 3.1. Under Win32®, your application can check to see which ALT key the user pressed--the right or the left. If the user presses the right ALT key--the ALT GR key--Windows generates a right-hand ALT and a left-hand CTRL virtual key. When your application receives a WM_KEYDOWN message, it can call the API GetKeyboardState to test for VK_CONTROL and VK_MENU. Since the scancode looks the same for both the WM_KEYDOWN and WM_SYSKEYDOWN messages, you need to look at bit 24, the extended bit of lParam, to see whether you have you have a left-CTRL/left-ALT pair or a right-CTRL/right-ALT pair (a good indication that the user is pressing the ALT GR key, even though conceivably they could press the left CTRL and the right ALT keys separately). You can predict whether ALT GR+<key> produces a character on the currently active layout by calling ToUnicode (or ToAscii if you are still in the 8-bit world). This does the same thing as TranslateMessage, but simply returns the character generated, if any, instead of posting it to your queue. For example, if you type ALT GR+R using the English Canadian layout (to get the paragraph symbol), the ALT GR key generates: WM_KEYDOWN VK_CONTROL lParam = 001d0001 (left CTRL)
WM_KEYDOWN VK_MENU lParam = 21380001 (right ALT)
The R key generates WM_KEYDOWN R lParam = 20130001 at this point ToUnicode would return one character : 0xB6 WM_CHAR 0xB6 lParam = 20130001
WM_KEYUP R lParam = E0130001
If the character generated (the lParam of WM_CHAR) is generated on the active keyboard layout using ALT GR (as in the case of the ß character on the Turkish keyboard), then your application should handle the key sequence as the input of an individual character. Otherwise, it should activate the appropriate function or command (treat the key combination as CTRL+ALT+S). The API GetKeyboardLayout will tell you which keyboard layout is currently active. It returns a 32-bit identifier that includes a language ID. Rejecting the shortcut key combination in favor of the ALT GR character won't be the right choice all the time--you're making a safe guess. Users who are actually trying to activate the command instead of generating the character will have to find some other way to activate the command. For example, a Turkish user of the U.S. version of Word would activate the Window menu and choose Split Document Pane, or use the Customize dialog box from the Tools menu to assign a different combination to Split Document Pane. Note Localized editions of Word for Windows generally do not use the same shortcut key combinations as the U.S. version. Microsoft gurus Ian James (from the Windows NT team) and Nobuya "Higgy" Higashiyama (from the Word team) contributed to this article. Questions or comments about this page, this site or international issues? Email drintl@microsoft.com. ©2002 Microsoft Corporation. All rights reserved. Terms of Use |
|||||