VirtualBox

Ignore:
Timestamp:
Apr 29, 2013 2:12:02 PM (12 years ago)
Author:
vboxsync
Message:

FE/Qt: attempt to fix AltGr in host key combination editor.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIHostComboEditor.cpp

    r44798 r45815  
    384384
    385385#ifdef Q_WS_WIN
     386/**
     387 * @brief isSyntheticLCtrl
     388 * @param   pMsg  Windows event message structure
     389 * @return  true if this is a synthetic LCtrl event, false otherwise
     390 * This function is a heuristic to tell whether a key event is the first in
     391 * a synthetic LCtrl+RAlt sequence which Windows uses to signal AltGr.  Our
     392 * heuristic is in two parts.  First of all, we check whether there is a pending
     393 * RAlt key event matching this LCtrl event (i.e. both key up or both key down)
     394 * and if there is, we check whether the current layout has an AltGr key.  We
     395 * check this by comparing the translation of the 'A' virtual key with and
     396 * without LCtrl and RAlt held down.  In all layouts I checked without an AltGr
     397 * key, the translation was the same, and in all with it was different.  An
     398 * alternative test would be to use GetKeyNameText() on the AltGr scan code.
     399 * I feel marginally safer with the first test though.
     400 */
     401static bool isSyntheticLCtrl(MSG *pMsg)
     402{
     403    MSG peekMsg;
     404    BYTE auKeyStates[256] = { 0 };
     405    WORD achNoAltGr, achAltGr;
     406    int cbToAscii;
     407
     408    if ((pMsg->lParam & 0x01FF0000) >> 16 != 0x1d /* LCtrl */)
     409        return false;
     410    if (!PeekMessage(&peekMsg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_NOREMOVE))
     411        return false;
     412    if (   (pMsg->message == WM_KEYDOWN || pMsg->message == WM_SYSKEYDOWN)
     413        && (peekMsg.message != WM_KEYDOWN && peekMsg.message != WM_SYSKEYDOWN))
     414        return false;
     415    if (   (pMsg->message == WM_KEYUP || pMsg->message == WM_SYSKEYUP)
     416        && (peekMsg.message != WM_KEYUP && peekMsg.message != WM_SYSKEYUP))
     417        return false;
     418    if ((peekMsg.lParam & 0x01FF0000) >> 16 != 0x138 /* RAlt */)
     419        return false;
     420    auKeyStates[VK_LCTRL] = 0x80;
     421    auKeyStates[VK_RMENU] = 0x80;
     422    cbToAscii = ToAscii('A', 0, NULL, &achNoAltGr, 0);
     423    if (!cbToAscii || cbToAscii != ToAscii('A', 0, auKeyStates, &achAltGr, 0))
     424        return false;
     425    if (achNoAltGr == achAltGr)
     426        return false;
     427    return true;
     428}
     429
    386430bool UIHostComboEditor::winEvent(MSG *pMsg, long* /* pResult */)
    387431{
     
    395439            /* Get key-code: */
    396440            int iKeyCode = UINativeHotKey::distinguishModifierVKey((int)pMsg->wParam, (int)pMsg->lParam);
     441
     442            /* If this is the first event in a synthetic AltGr = LCtrl+RAlt
     443             * sequence then swallow it. */
     444            if (isSyntheticLCtrl(pMsg))
     445                return true;
    397446
    398447            /* Process the key event: */
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette