Browse Source

Fix right ALT and CTRL being reported as left.

pull/3320/head
Dariusz Komosiński 7 years ago
parent
commit
be4d1ef038
  1. 3
      src/Avalonia.Input/AccessKeyHandler.cs
  2. 21
      src/Windows/Avalonia.Win32/Input/KeyInterop.cs
  3. 4
      src/Windows/Avalonia.Win32/WindowImpl.cs

3
src/Avalonia.Input/AccessKeyHandler.cs

@ -140,7 +140,7 @@ namespace Avalonia.Input
/// <param name="e">The event args.</param>
protected virtual void OnPreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.LeftAlt)
if (e.Key == Key.LeftAlt || e.Key == Key.RightAlt)
{
_altIsDown = true;
@ -218,6 +218,7 @@ namespace Avalonia.Input
switch (e.Key)
{
case Key.LeftAlt:
case Key.RightAlt:
_altIsDown = false;
if (_ignoreAltUp)

21
src/Windows/Avalonia.Win32/Input/KeyInterop.cs

@ -364,10 +364,25 @@ namespace Avalonia.Win32.Input
{ 254, Key.OemClear },
};
public static Key KeyFromVirtualKey(int virtualKey)
public static Key KeyFromVirtualKey(int virtualKey, int flags)
{
Key result;
s_keyFromVirtualKey.TryGetValue(virtualKey, out result);
s_keyFromVirtualKey.TryGetValue(virtualKey, out var result);
// Indicates whether the key is an extended key, such as the right-hand ALT and CTRL keys.
// According to https://docs.microsoft.com/en-us/windows/win32/inputdev/wm-keydown.
const int extendedMask = 1 << 24;
bool isExtended = (flags & extendedMask) != 0;
if (isExtended)
{
return result switch
{
Key.LeftAlt => Key.RightAlt,
Key.LeftCtrl => Key.RightCtrl,
_ => result
};
}
return result;
}

4
src/Windows/Avalonia.Win32/WindowImpl.cs

@ -516,7 +516,7 @@ namespace Avalonia.Win32
timestamp,
_owner,
RawKeyEventType.KeyDown,
KeyInterop.KeyFromVirtualKey(ToInt32(wParam)), WindowsKeyboardDevice.Instance.Modifiers);
KeyInterop.KeyFromVirtualKey(ToInt32(wParam), ToInt32(lParam)), WindowsKeyboardDevice.Instance.Modifiers);
break;
case UnmanagedMethods.WindowsMessage.WM_MENUCHAR:
@ -530,7 +530,7 @@ namespace Avalonia.Win32
timestamp,
_owner,
RawKeyEventType.KeyUp,
KeyInterop.KeyFromVirtualKey(ToInt32(wParam)), WindowsKeyboardDevice.Instance.Modifiers);
KeyInterop.KeyFromVirtualKey(ToInt32(wParam), ToInt32(lParam)), WindowsKeyboardDevice.Instance.Modifiers);
break;
case UnmanagedMethods.WindowsMessage.WM_CHAR:
// Ignore control chars

Loading…
Cancel
Save