Changeset 802


Ignore:
Timestamp:
Oct 20, 2010, 9:39:11 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

gui: Fixed: Make sure that pressing Shift[+Ctrl]]+<numpad_digit> will generate a cursor movement code in NumLock mode off instead of a digit. This is necessary to make it possible to select text using numpad keys with Shift pressed (closes #183).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gui/kernel/qkeymapper_pm.cpp

    r668 r802  
    592592        state = state ^ Qt::MetaModifier;
    593593
     594    bool isNumLockOn = WinGetKeyState(HWND_DESKTOP, VK_NUMLOCK) & 0x0001;
     595
    594596    // detect numeric keypad keys
    595597    if (chm.vkey == VK_ENTER || chm.vkey == VK_NUMLOCK) {
     
    598600    } else if (((chm.vkey >= VK_PAGEUP && chm.vkey <= VK_DOWN) ||
    599601                chm.vkey == VK_INSERT || chm.vkey == VK_DELETE)) {
     602        // these are numbers 0-9 and the numeric comma/dot
    600603        if ((chm.chr & 0xFF) != 0xE0) {
    601604            state |= Qt::KeypadModifier;
     
    608611                return false;
    609612            }
     613            if (state & (Qt::KeyboardModifierMask & ~Qt::KeypadModifier)) {
     614                // the OS/2 keyboard driver tends to invert the NumLock state
     615                // when some modifiers (e.g. Shift) are pressed so that cursor
     616                // movement event becomes a digit and and vice versa; we want
     617                // to cancel replacing movements with digits to make it possible
     618                // to e.g. select the text using numpad keys in NumLock OFF mode
     619                // with Shift pressed. It seems that other applications (e.g.
     620                // standard PM controls) do exactly the same.
     621                if (!isNumLockOn) {
     622                    // suppress generation of digits
     623                    chm.chr = 0;
     624                    chm.fs &= ~KC_CHAR;
     625                }
     626            }
    610627        }
    611628    }
     
    618635                // hide the key from Qt (see above)
    619636                return false;
    620             } else {
    621                 // scancode is zero if Numlock is set
    622                 if (!code)
    623                     code = Qt::Key_Clear;
    624             }
     637            }
     638            if (state & (Qt::KeyboardModifierMask & ~Qt::KeypadModifier)) {
     639                if (!isNumLockOn) {
     640                    // suppress generation of digits, see above (note that
     641                    // standard PM applications don't seem to do that for the
     642                    // "5" key; we correct it here as it seems more logical)
     643                    chm.chr = 0;
     644                    chm.fs &= ~KC_CHAR;
     645                }
     646            }
     647            // scancode is zero if Numlock is set
     648            if (!code)
     649                code = Qt::Key_Clear;
     650            // this key doesn't have a virtual key assigned, but pretend we're
     651            // a virtual key to avoid interpreting chm.chr as DBCS below
     652            chm.fs |= KC_VIRTUALKEY;
    625653            break;
    626654        case 0x37: // *
Note: See TracChangeset for help on using the changeset viewer.