diff options
| -rw-r--r-- | doc/ScintillaDoc.html | 6 | ||||
| -rw-r--r-- | doc/ScintillaHistory.html | 6 | ||||
| -rw-r--r-- | win32/ScintillaWin.cxx | 33 |
3 files changed, 43 insertions, 2 deletions
diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index 46262e0a5..f3d5c9fd3 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -5494,6 +5494,12 @@ struct Sci_TextToFind { If you are building a table, you might want to use <code>SCMOD_NORM</code>, which has the value 0, to mean no modifiers.</p> + <p>On Win32, the numeric keypad with Alt pressed can be used to enter characters by number. + This can produce unexpected results in non-numlock mode when function keys are assigned so + potentially problematic keys are ignored. For example, setting + <code>SCMOD_ALT</code>,<code>SCK_UP</code> will only be active for the Up key on the + main cursor keys, not the numeric keypad.</p> + <p><b id="SCI_ASSIGNCMDKEY">SCI_ASSIGNCMDKEY(int <a class="jump" href="#keyDefinition">keyDefinition</a>, int sciCommand)</b><br /> This assigns the given key definition to a Scintilla command identified by diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index 884d0fa98..c6ed95a5a 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -584,6 +584,12 @@ CF_UNICODETEXT. </li> <li> + On Win32, the numeric keypad with Alt pressed can be used to enter characters by number. + This can produce unexpected results in non-numlock mode when function keys are assigned. + Potentially problematic keys like Alt+KeypadUp are now ignored. + <a href="https://sourceforge.net/p/scintilla/bugs/2152/">Bug #2152</a>. + </li> + <li> Improve IME behaviour on GTK. Set candidate position for windowed IME. Improve location of candidate window. diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx index 21bd90288..298d0e022 100644 --- a/win32/ScintillaWin.cxx +++ b/win32/ScintillaWin.cxx @@ -168,6 +168,30 @@ bool KeyboardIsKeyDown(int key) noexcept { return (::GetKeyState(key) & 0x80000000) != 0; } +bool KeyboardIsNumericKeypadFunction(uptr_t wParam, sptr_t lParam) { + // Bit 24 is the extended keyboard flag and the numeric keypad is non-extended + if ((lParam & (1 << 24)) != 0) { + // Not from the numeric keypad + return false; + } + + switch (wParam) { + case VK_INSERT: // 0 + case VK_END: // 1 + case VK_DOWN: // 2 + case VK_NEXT: // 3 + case VK_LEFT: // 4 + case VK_CLEAR: // 5 + case VK_RIGHT: // 6 + case VK_HOME: // 7 + case VK_UP: // 8 + case VK_PRIOR: // 9 + return true; + default: + return false; + } +} + } class ScintillaWin; // Forward declaration for COM interface subobjects @@ -1541,16 +1565,21 @@ sptr_t ScintillaWin::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam case WM_KEYDOWN: { // Platform::DebugPrintf("Keydown %c %c%c%c%c %x %x\n", // iMessage == WM_KEYDOWN ? 'K' : 'S', - // (lParam & 1 << 24) ? '-' : 'E', + // (lParam & (1 << 24)) ? 'E' : '-', // KeyboardIsKeyDown(VK_SHIFT) ? 'S' : '-', // KeyboardIsKeyDown(VK_CONTROL) ? 'C' : '-', // KeyboardIsKeyDown(VK_MENU) ? 'A' : '-', // wParam, lParam); lastKeyDownConsumed = false; + const bool altDown = KeyboardIsKeyDown(VK_MENU); + if (altDown && KeyboardIsNumericKeypadFunction(wParam, lParam)) { + // Don't interpret these as they may be characters entered by number. + return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam); + } const int ret = KeyDownWithModifiers(KeyTranslate(static_cast<int>(wParam)), ModifierFlags(KeyboardIsKeyDown(VK_SHIFT), KeyboardIsKeyDown(VK_CONTROL), - KeyboardIsKeyDown(VK_MENU)), + altDown), &lastKeyDownConsumed); if (!ret && !lastKeyDownConsumed) { return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam); |
