Skip to content

Commit

Permalink
Merge pull request #7374 from AvaloniaUI/fixes/5849-textinput-keydown…
Browse files Browse the repository at this point in the history
…-handed-2

win32: Don't raise TextInput event when KeyDown was handled (Attempt #2)
  • Loading branch information
danwalmsley authored Jan 18, 2022
2 parents 0fff429 + 7d354a2 commit 38f726f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ protected virtual unsafe IntPtr AppWndProc(IntPtr hWnd, uint msg, IntPtr wParam,
}
case WindowsMessage.WM_CHAR:
{
// Ignore control chars
if (ToInt32(wParam) >= 32)
// Ignore control chars and chars that were handled in WM_KEYDOWN.
if (ToInt32(wParam) >= 32 && !_ignoreWmChar)
{
e = new RawTextInputEventArgs(WindowsKeyboardDevice.Instance, timestamp, _owner,
new string((char)ToInt32(wParam), 1));
Expand Down Expand Up @@ -519,6 +519,15 @@ protected virtual unsafe IntPtr AppWndProc(IntPtr hWnd, uint msg, IntPtr wParam,
{
Input(e);

if ((WindowsMessage)msg == WindowsMessage.WM_KEYDOWN)
{
// Handling a WM_KEYDOWN message should cause the subsequent WM_CHAR message to
// be ignored. This should be safe to do as WM_CHAR should only be produced in
// response to the call to TranslateMessage/DispatchMessage after a WM_KEYDOWN
// is handled.
_ignoreWmChar = e.Handled;
}

if (e.Handled)
{
return IntPtr.Zero;
Expand Down
1 change: 1 addition & 0 deletions src/Windows/Avalonia.Win32/WindowImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public partial class WindowImpl : IWindowImpl, EglGlPlatformSurface.IEglWindowGl
private bool _shown;
private bool _hiddenWindowIsParent;
private uint _langid;
private bool _ignoreWmChar;

public WindowImpl()
{
Expand Down

0 comments on commit 38f726f

Please sign in to comment.