From ee79a4e2a10c3f75fc8e24f875e0304fafdcab2b Mon Sep 17 00:00:00 2001
From: Neil
Date: Sat, 25 Jan 2020 08:34:03 +1100
Subject: Bug [#2152]. Ignore Alt+Keypad keys that will result in a WM_CHAR.
---
doc/ScintillaDoc.html | 6 ++++++
doc/ScintillaHistory.html | 6 ++++++
win32/ScintillaWin.cxx | 33 +++++++++++++++++++++++++++++++--
3 files changed, 43 insertions(+), 2 deletions(-)
diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html
index 4ad921cf5..ec1e79afb 100644
--- a/doc/ScintillaDoc.html
+++ b/doc/ScintillaDoc.html
@@ -5549,6 +5549,12 @@ struct Sci_TextToFind {
If you are building a table, you might
want to use SCMOD_NORM, which has the value 0, to mean no modifiers.
+ 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
+ SCMOD_ALT,SCK_UP will only be active for the Up key on the
+ main cursor keys, not the numeric keypad.
+
SCI_ASSIGNCMDKEY(int keyDefinition, int sciCommand)
This assigns the given key definition to a Scintilla command identified by
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html
index 4ed002f36..7ca70eeff 100644
--- a/doc/ScintillaHistory.html
+++ b/doc/ScintillaHistory.html
@@ -571,6 +571,12 @@
Fix drag and drop between different encodings by always providing CF_UNICODETEXT only.
Bug #2151.
+
+ 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.
+ Bug #2152.
+
Release 4.3.0
diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx
index a2e59687d..4ed03c787 100644
--- a/win32/ScintillaWin.cxx
+++ b/win32/ScintillaWin.cxx
@@ -169,6 +169,30 @@ bool KeyboardIsKeyDown(int key) noexcept {
return (::GetKeyState(key) & 0x80000000) != 0;
}
+constexpr 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
@@ -1551,16 +1575,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(wParam)),
ModifierFlags(KeyboardIsKeyDown(VK_SHIFT),
KeyboardIsKeyDown(VK_CONTROL),
- KeyboardIsKeyDown(VK_MENU)),
+ altDown),
&lastKeyDownConsumed);
if (!ret && !lastKeyDownConsumed) {
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
--
cgit v1.2.3