@@ -1528,18 +1528,26 @@ bool UpdateAcceleratorTable(int32 tag, ExtensionString& keyStr)
1528
1528
// Get the virtual key code for non-alpha-numeric characters.
1529
1529
int keyCode = ::VkKeyScan (ascii);
1530
1530
WORD vKey = (short )(keyCode & 0x000000FF );
1531
+ bool isAltGr = ((keyCode & 0x0000FF00 ) >> 8 ) >= 6 ;
1531
1532
1532
1533
// Get unshifted key from keyCode so that we can determine whether the
1533
1534
// key is a shifted one or not.
1534
1535
UINT unshiftedChar = ::MapVirtualKey (vKey, 2 );
1535
1536
bool isDeadKey = ((unshiftedChar & 0x80000000 ) == 0x80000000 );
1536
1537
1537
- // If key code is -1 or unshiftedChar is 0 or the key is a shifted key sharing with
1538
- // one of the number keys on the keyboard, then we don't have a functionable shortcut.
1538
+ // If one of the following is found, then the shortcut is not available for the
1539
+ // current keyboard layout.
1540
+ //
1541
+ // * keyCode is -1 -- meaning the key is not available on the current keyboard layout
1542
+ // * is a dead key -- a key used to attach a specific diacritic to a base letter.
1543
+ // * is altGr character -- the character is only available when Ctrl and Alt keys are also pressed together.
1544
+ // * unshiftedChar is 0 -- meaning the key is not available on the current keyboard layout
1545
+ // * The key is a shifted character sharing with one of the number keys on the keyboard. An example
1546
+ // of this is the '/' key on German keyboard layout. It is a shifted key on number key '7'.
1547
+ //
1539
1548
// So don't update the accelerator table. Just return false here so that the
1540
- // caller can remove the shortcut string from the menu title. An example of this
1541
- // is the '/' key on German keyboard layout. It is a shifted key on number key '7'.
1542
- if (keyCode == -1 || isDeadKey || unshiftedChar == 0 ||
1549
+ // caller can remove the shortcut string from the menu title.
1550
+ if (keyCode == -1 || isDeadKey || isAltGr || unshiftedChar == 0 ||
1543
1551
(unshiftedChar >= ' 0' && unshiftedChar <= ' 9' )) {
1544
1552
LocalFree (lpaccelNew);
1545
1553
return false ;
@@ -1674,6 +1682,13 @@ int32 AddMenuItem(CefRefPtr<CefBrowser> browser, ExtensionString parentCommand,
1674
1682
if (displayKeyStr.length () > 0 ) {
1675
1683
title = title + L" \t " + displayKeyStr;
1676
1684
}
1685
+
1686
+ // Add shortcut to the accelerator table first. If the shortcut cannot
1687
+ // be added, then don't show it in the menu title.
1688
+ if (!isSeparator && !UpdateAcceleratorTable (tag, keyStr)) {
1689
+ title = title.substr (0 , title.find (' \t ' ));
1690
+ }
1691
+
1677
1692
int32 positionIdx;
1678
1693
int32 errCode = getNewMenuPosition (browser, parentCommand, position, relativeId, positionIdx);
1679
1694
bool inserted = false ;
@@ -1724,11 +1739,6 @@ int32 AddMenuItem(CefRefPtr<CefBrowser> browser, ExtensionString parentCommand,
1724
1739
1725
1740
NativeMenuModel::getInstance (getMenuParent (browser)).setOsItem (tag, (void *)submenu);
1726
1741
1727
- if (!isSeparator && !UpdateAcceleratorTable (tag, keyStr)) {
1728
- title = title.substr (0 , title.find (' \t ' ));
1729
- SetMenuTitle (browser, command, title);
1730
- }
1731
-
1732
1742
return errCode;
1733
1743
}
1734
1744
0 commit comments