From 370c6910ed888c3d7df0b335d92e91ca030ee7ef Mon Sep 17 00:00:00 2001 From: Max Katz Date: Sun, 14 Jan 2024 00:18:43 -0800 Subject: [PATCH] Implement keyboard and remote (+touch) input on iOS and tvOS --- src/iOS/Avalonia.iOS/AvaloniaView.cs | 80 +++++- src/iOS/Avalonia.iOS/InputHandler.cs | 357 +++++++++++++++++++++++++++ src/iOS/Avalonia.iOS/TouchHandler.cs | 52 ---- 3 files changed, 428 insertions(+), 61 deletions(-) create mode 100644 src/iOS/Avalonia.iOS/InputHandler.cs delete mode 100644 src/iOS/Avalonia.iOS/TouchHandler.cs diff --git a/src/iOS/Avalonia.iOS/AvaloniaView.cs b/src/iOS/Avalonia.iOS/AvaloniaView.cs index b6cde47c7a..108caa0925 100644 --- a/src/iOS/Avalonia.iOS/AvaloniaView.cs +++ b/src/iOS/Avalonia.iOS/AvaloniaView.cs @@ -32,7 +32,7 @@ namespace Avalonia.iOS private readonly TopLevelImpl _topLevelImpl; private readonly EmbeddableControlRoot _topLevel; - private readonly TouchHandler _touches; + private readonly InputHandler _input; private TextInputMethodClient? _client; private IAvaloniaViewController? _controller; private IInputRoot? _inputRoot; @@ -41,7 +41,7 @@ namespace Avalonia.iOS public AvaloniaView() { _topLevelImpl = new TopLevelImpl(this); - _touches = new TouchHandler(this, _topLevelImpl); + _input = new InputHandler(this, _topLevelImpl); _topLevel = new EmbeddableControlRoot(_topLevelImpl); _topLevel.Prepare(); @@ -49,12 +49,33 @@ namespace Avalonia.iOS _topLevel.StartRendering(); InitLayerSurface(); -#if !TVOS - if (OperatingSystem.IsIOS() || OperatingSystem.IsMacCatalyst()) + + // Remote touch handling + if (OperatingSystem.IsTvOS()) { - MultipleTouchEnabled = true; + AddGestureRecognizer(new UISwipeGestureRecognizer(_input.Handle) + { + Direction = UISwipeGestureRecognizerDirection.Up + }); + AddGestureRecognizer(new UISwipeGestureRecognizer(_input.Handle) + { + Direction = UISwipeGestureRecognizerDirection.Right + }); + AddGestureRecognizer(new UISwipeGestureRecognizer(_input.Handle) + { + Direction = UISwipeGestureRecognizerDirection.Down + }); + AddGestureRecognizer(new UISwipeGestureRecognizer(_input.Handle) + { + Direction = UISwipeGestureRecognizerDirection.Left + }); } + else if (OperatingSystem.IsIOS() || OperatingSystem.IsMacCatalyst()) + { +#if !TVOS + MultipleTouchEnabled = true; #endif + } } [SuppressMessage("Interoperability", "CA1422:Validate platform compatibility")] @@ -284,14 +305,55 @@ namespace Avalonia.iOS } } - public override void TouchesBegan(NSSet touches, UIEvent? evt) => _touches.Handle(touches, evt); + /// + public override void TouchesBegan(NSSet touches, UIEvent? evt) => _input.Handle(touches, evt); + + /// + public override void TouchesMoved(NSSet touches, UIEvent? evt) => _input.Handle(touches, evt); - public override void TouchesMoved(NSSet touches, UIEvent? evt) => _touches.Handle(touches, evt); + /// + public override void TouchesEnded(NSSet touches, UIEvent? evt) => _input.Handle(touches, evt); - public override void TouchesEnded(NSSet touches, UIEvent? evt) => _touches.Handle(touches, evt); + /// + public override void TouchesCancelled(NSSet touches, UIEvent? evt) => _input.Handle(touches, evt); - public override void TouchesCancelled(NSSet touches, UIEvent? evt) => _touches.Handle(touches, evt); + /// + public override void PressesBegan(NSSet presses, UIPressesEvent evt) + { + if (!_input.Handle(presses, evt)) + { + base.PressesBegan(presses, evt); + } + } + + /// + public override void PressesChanged(NSSet presses, UIPressesEvent evt) + { + if (!_input.Handle(presses, evt)) + { + base.PressesBegan(presses, evt); + } + } + + /// + public override void PressesEnded(NSSet presses, UIPressesEvent evt) + { + if (!_input.Handle(presses, evt)) + { + base.PressesEnded(presses, evt); + } + } + + /// + public override void PressesCancelled(NSSet presses, UIPressesEvent evt) + { + if (!_input.Handle(presses, evt)) + { + base.PressesCancelled(presses, evt); + } + } + /// public override void LayoutSubviews() { _topLevelImpl.Resized?.Invoke(_topLevelImpl.ClientSize, WindowResizeReason.Layout); diff --git a/src/iOS/Avalonia.iOS/InputHandler.cs b/src/iOS/Avalonia.iOS/InputHandler.cs new file mode 100644 index 0000000000..7057f5a84d --- /dev/null +++ b/src/iOS/Avalonia.iOS/InputHandler.cs @@ -0,0 +1,357 @@ +using System; +using System.Collections.Generic; +using Avalonia.Input; +using Avalonia.Input.Raw; +using Avalonia.Platform; +using Foundation; +using UIKit; + +namespace Avalonia.iOS; + +internal sealed class InputHandler +{ + private readonly bool _supportsKey = OperatingSystem.IsIOSVersionAtLeast(13, 4) + || OperatingSystem.IsTvOSVersionAtLeast(13, 4); + + private readonly AvaloniaView _view; + private readonly ITopLevelImpl _tl; + public TouchDevice _device = new(); + private static long _nextTouchPointId = 1; + private readonly Dictionary _knownTouches = new Dictionary(); + + public InputHandler(AvaloniaView view, ITopLevelImpl tl) + { + _view = view; + _tl = tl; + } + + private static ulong Ts(UIEvent? evt) => evt is null ? 0 : (ulong)(evt.Timestamp * 1000); + private IInputRoot Root => _view.InputRoot; + + public void Handle(NSSet touches, UIEvent? evt) + { + foreach (UITouch t in touches) + { + var pt = t.LocationInView(_view).ToAvalonia(); + if (!_knownTouches.TryGetValue(t, out var id)) + _knownTouches[t] = id = _nextTouchPointId++; + + var ev = new RawTouchEventArgs(_device, Ts(evt), Root, + t.Phase switch + { + UITouchPhase.Began => RawPointerEventType.TouchBegin, + UITouchPhase.Ended => RawPointerEventType.TouchEnd, + UITouchPhase.Cancelled => RawPointerEventType.TouchCancel, + _ => RawPointerEventType.TouchUpdate + }, pt, RawInputModifiers.None, id); + + _tl.Input?.Invoke(ev); + + if (t.Phase == UITouchPhase.Cancelled || t.Phase == UITouchPhase.Ended) + _knownTouches.Remove(t); + } + } + + public bool Handle(NSSet presses, UIPressesEvent? evt) + { + var handled = false; + foreach (UIPress p in presses) + { + PhysicalKey physicalKey; + RawInputModifiers modifier = default; + string? characters = null; + KeyDeviceType keyDeviceType; + + if (_supportsKey && p.Key is { } uiKey + && s_keys.TryGetValue(uiKey.KeyCode, out physicalKey)) + { + var uiModifier = uiKey.ModifierFlags; + if (uiModifier.HasFlag(UIKeyModifierFlags.Shift)) + modifier |= RawInputModifiers.Shift; + if (uiModifier.HasFlag(UIKeyModifierFlags.Alternate)) + modifier |= RawInputModifiers.Alt; + if (uiModifier.HasFlag(UIKeyModifierFlags.Control)) + modifier |= RawInputModifiers.Control; + if (uiModifier.HasFlag(UIKeyModifierFlags.Command)) + modifier |= RawInputModifiers.Meta; + + keyDeviceType = KeyDeviceType.Keyboard; // very likely + + if (!uiKey.Characters.StartsWith("UIKey")) + characters = uiKey.Characters; + } + else + { + physicalKey = p.Type switch + { + UIPressType.UpArrow => PhysicalKey.ArrowUp, + UIPressType.DownArrow => PhysicalKey.ArrowDown, + UIPressType.LeftArrow => PhysicalKey.ArrowLeft, + UIPressType.RightArrow => PhysicalKey.ArrowRight, + UIPressType.Select => PhysicalKey.Space, + UIPressType.Menu => PhysicalKey.ContextMenu, + UIPressType.PlayPause => PhysicalKey.MediaPlayPause, + UIPressType.PageUp => PhysicalKey.PageUp, + UIPressType.PageDown => PhysicalKey.PageDown, + _ => PhysicalKey.None + }; + keyDeviceType = KeyDeviceType.Remote; // very likely + } + + var key = physicalKey.ToQwertyKey(); + if (key == Key.None) + continue; + + var ev = new RawKeyEventArgs(KeyboardDevice.Instance!, Ts(evt), Root, + p.Phase switch + { + UIPressPhase.Began => RawKeyEventType.KeyDown, + UIPressPhase.Changed => RawKeyEventType.KeyDown, + UIPressPhase.Stationary => RawKeyEventType.KeyDown, + UIPressPhase.Ended => RawKeyEventType.KeyUp, + _ => RawKeyEventType.KeyUp + }, key, modifier, physicalKey, keyDeviceType, characters); + + _tl.Input?.Invoke(ev); + handled |= ev.Handled; + + if (!ev.Handled && p.Phase == UIPressPhase.Began && !string.IsNullOrEmpty(characters)) + { + var rawTextEvent = new RawTextInputEventArgs( + KeyboardDevice.Instance!, + Ts(evt), + _view.InputRoot, + characters + ); + _tl.Input?.Invoke(rawTextEvent); + handled |= rawTextEvent.Handled; + } + } + + return handled; + } + + public void Handle(UISwipeGestureRecognizer recognizer) + { + var handled = false; + var direction = recognizer.Direction; + var timestamp = 0UL; // todo + + if (OperatingSystem.IsTvOS()) + { + if (direction.HasFlag(UISwipeGestureRecognizerDirection.Up)) + handled = handled || HandleNavigationKey(Key.Up); + if (direction.HasFlag(UISwipeGestureRecognizerDirection.Right)) + handled = handled || HandleNavigationKey(Key.Right); + if (direction.HasFlag(UISwipeGestureRecognizerDirection.Down)) + handled = handled || HandleNavigationKey(Key.Down); + if (direction.HasFlag(UISwipeGestureRecognizerDirection.Left)) + handled = handled || HandleNavigationKey(Key.Left); + } + + if (!handled) + { + // TODO raise RawPointerGestureEventArgs + } + + bool HandleNavigationKey(Key key) + { + // Don't pass PhysicalKey, as physically it's just a touch gesture. + var ev = new RawKeyEventArgs(KeyboardDevice.Instance!, timestamp, Root, + RawKeyEventType.KeyDown, key, RawInputModifiers.None, PhysicalKey.None, KeyDeviceType.Remote, null); + _tl.Input?.Invoke(ev); + var handled = ev.Handled; + + ev.Handled = false; + ev.Type = RawKeyEventType.KeyUp; + _tl.Input?.Invoke(ev); + handled |= ev.Handled; + + return handled; + } + } + + private static Dictionary s_keys = new() + { + //[UIKeyboardHidUsage.KeyboardErrorRollOver] = PhysicalKey.None, + //[UIKeyboardHidUsage.KeyboardPostFail] = PhysicalKey.None, + //[UIKeyboardHidUsage.KeyboardErrorUndefined] = PhysicalKey.None, + [UIKeyboardHidUsage.KeyboardA] = PhysicalKey.A, + [UIKeyboardHidUsage.KeyboardB] = PhysicalKey.B, + [UIKeyboardHidUsage.KeyboardC] = PhysicalKey.C, + [UIKeyboardHidUsage.KeyboardD] = PhysicalKey.D, + [UIKeyboardHidUsage.KeyboardE] = PhysicalKey.E, + [UIKeyboardHidUsage.KeyboardF] = PhysicalKey.F, + [UIKeyboardHidUsage.KeyboardG] = PhysicalKey.G, + [UIKeyboardHidUsage.KeyboardH] = PhysicalKey.H, + [UIKeyboardHidUsage.KeyboardI] = PhysicalKey.I, + [UIKeyboardHidUsage.KeyboardJ] = PhysicalKey.J, + [UIKeyboardHidUsage.KeyboardK] = PhysicalKey.K, + [UIKeyboardHidUsage.KeyboardL] = PhysicalKey.L, + [UIKeyboardHidUsage.KeyboardM] = PhysicalKey.M, + [UIKeyboardHidUsage.KeyboardN] = PhysicalKey.N, + [UIKeyboardHidUsage.KeyboardO] = PhysicalKey.O, + [UIKeyboardHidUsage.KeyboardP] = PhysicalKey.P, + [UIKeyboardHidUsage.KeyboardQ] = PhysicalKey.Q, + [UIKeyboardHidUsage.KeyboardR] = PhysicalKey.R, + [UIKeyboardHidUsage.KeyboardS] = PhysicalKey.S, + [UIKeyboardHidUsage.KeyboardT] = PhysicalKey.T, + [UIKeyboardHidUsage.KeyboardU] = PhysicalKey.U, + [UIKeyboardHidUsage.KeyboardV] = PhysicalKey.V, + [UIKeyboardHidUsage.KeyboardW] = PhysicalKey.W, + [UIKeyboardHidUsage.KeyboardX] = PhysicalKey.X, + [UIKeyboardHidUsage.KeyboardY] = PhysicalKey.Y, + [UIKeyboardHidUsage.KeyboardZ] = PhysicalKey.Z, + [UIKeyboardHidUsage.Keyboard1] = PhysicalKey.Digit1, + [UIKeyboardHidUsage.Keyboard2] = PhysicalKey.Digit2, + [UIKeyboardHidUsage.Keyboard3] = PhysicalKey.Digit3, + [UIKeyboardHidUsage.Keyboard4] = PhysicalKey.Digit4, + [UIKeyboardHidUsage.Keyboard5] = PhysicalKey.Digit5, + [UIKeyboardHidUsage.Keyboard6] = PhysicalKey.Digit6, + [UIKeyboardHidUsage.Keyboard7] = PhysicalKey.Digit7, + [UIKeyboardHidUsage.Keyboard8] = PhysicalKey.Digit8, + [UIKeyboardHidUsage.Keyboard9] = PhysicalKey.Digit9, + [UIKeyboardHidUsage.Keyboard0] = PhysicalKey.Digit0, + [UIKeyboardHidUsage.KeyboardReturnOrEnter] = PhysicalKey.Enter, + [UIKeyboardHidUsage.KeyboardEscape] = PhysicalKey.Escape, + [UIKeyboardHidUsage.KeyboardDeleteOrBackspace] = PhysicalKey.Delete, + [UIKeyboardHidUsage.KeyboardTab] = PhysicalKey.Tab, + [UIKeyboardHidUsage.KeyboardSpacebar] = PhysicalKey.Space, + [UIKeyboardHidUsage.KeyboardHyphen] = PhysicalKey.NumPadSubtract, + [UIKeyboardHidUsage.KeyboardEqualSign] = PhysicalKey.NumPadEqual, + [UIKeyboardHidUsage.KeyboardOpenBracket] = PhysicalKey.BracketLeft, + [UIKeyboardHidUsage.KeyboardCloseBracket] = PhysicalKey.BracketRight, + [UIKeyboardHidUsage.KeyboardBackslash] = PhysicalKey.Backslash, + // [UIKeyboardHidUsage.KeyboardNonUSPound] = 50, + [UIKeyboardHidUsage.KeyboardSemicolon] = PhysicalKey.Semicolon, + [UIKeyboardHidUsage.KeyboardQuote] = PhysicalKey.Quote, + // [UIKeyboardHidUsage.KeyboardGraveAccentAndTilde] = 53, + [UIKeyboardHidUsage.KeyboardComma] = PhysicalKey.Comma, + [UIKeyboardHidUsage.KeyboardPeriod] = PhysicalKey.Period, + [UIKeyboardHidUsage.KeyboardSlash] = PhysicalKey.Slash, + [UIKeyboardHidUsage.KeyboardCapsLock] = PhysicalKey.CapsLock, + [UIKeyboardHidUsage.KeyboardF1] = PhysicalKey.F1, + [UIKeyboardHidUsage.KeyboardF2] = PhysicalKey.F2, + [UIKeyboardHidUsage.KeyboardF3] = PhysicalKey.F3, + [UIKeyboardHidUsage.KeyboardF4] = PhysicalKey.F4, + [UIKeyboardHidUsage.KeyboardF5] = PhysicalKey.F5, + [UIKeyboardHidUsage.KeyboardF6] = PhysicalKey.F6, + [UIKeyboardHidUsage.KeyboardF7] = PhysicalKey.F7, + [UIKeyboardHidUsage.KeyboardF8] = PhysicalKey.F8, + [UIKeyboardHidUsage.KeyboardF9] = PhysicalKey.F9, + [UIKeyboardHidUsage.KeyboardF10] = PhysicalKey.F10, + [UIKeyboardHidUsage.KeyboardF11] = PhysicalKey.F11, + [UIKeyboardHidUsage.KeyboardF12] = PhysicalKey.F12, + [UIKeyboardHidUsage.KeyboardPrintScreen] = PhysicalKey.PrintScreen, + [UIKeyboardHidUsage.KeyboardScrollLock] = PhysicalKey.ScrollLock, + [UIKeyboardHidUsage.KeyboardPause] = PhysicalKey.Pause, + [UIKeyboardHidUsage.KeyboardInsert] = PhysicalKey.Insert, + [UIKeyboardHidUsage.KeyboardHome] = PhysicalKey.Home, + [UIKeyboardHidUsage.KeyboardPageUp] = PhysicalKey.PageUp, + [UIKeyboardHidUsage.KeyboardDeleteForward] = PhysicalKey.Delete, + [UIKeyboardHidUsage.KeyboardEnd] = PhysicalKey.End, + [UIKeyboardHidUsage.KeyboardPageDown] = PhysicalKey.PageDown, + [UIKeyboardHidUsage.KeyboardRightArrow] = PhysicalKey.ArrowRight, + [UIKeyboardHidUsage.KeyboardLeftArrow] = PhysicalKey.ArrowLeft, + [UIKeyboardHidUsage.KeyboardDownArrow] = PhysicalKey.ArrowDown, + [UIKeyboardHidUsage.KeyboardUpArrow] = PhysicalKey.ArrowUp, + [UIKeyboardHidUsage.KeypadNumLock] = PhysicalKey.NumLock, + [UIKeyboardHidUsage.KeypadSlash] = PhysicalKey.Slash, + [UIKeyboardHidUsage.KeypadAsterisk] = PhysicalKey.NumPadMultiply, + [UIKeyboardHidUsage.KeypadHyphen] = PhysicalKey.NumPadSubtract, + [UIKeyboardHidUsage.KeypadPlus] = PhysicalKey.NumPadAdd, + [UIKeyboardHidUsage.KeypadEnter] = PhysicalKey.Enter, + [UIKeyboardHidUsage.Keypad1] = PhysicalKey.NumPad1, + [UIKeyboardHidUsage.Keypad2] = PhysicalKey.NumPad2, + [UIKeyboardHidUsage.Keypad3] = PhysicalKey.NumPad3, + [UIKeyboardHidUsage.Keypad4] = PhysicalKey.NumPad4, + [UIKeyboardHidUsage.Keypad5] = PhysicalKey.NumPad5, + [UIKeyboardHidUsage.Keypad6] = PhysicalKey.NumPad6, + [UIKeyboardHidUsage.Keypad7] = PhysicalKey.NumPad7, + [UIKeyboardHidUsage.Keypad8] = PhysicalKey.NumPad8, + [UIKeyboardHidUsage.Keypad9] = PhysicalKey.NumPad9, + [UIKeyboardHidUsage.Keypad0] = PhysicalKey.NumPad0, + [UIKeyboardHidUsage.KeypadPeriod] = PhysicalKey.Period, + [UIKeyboardHidUsage.KeyboardNonUSBackslash] = PhysicalKey.IntlBackslash, + //[UIKeyboardHidUsage.KeyboardApplication] = 101, + //[UIKeyboardHidUsage.KeyboardPower] = 102, + //[UIKeyboardHidUsage.KeypadEqualSign] = 103, + [UIKeyboardHidUsage.KeyboardF13] = PhysicalKey.F13, + [UIKeyboardHidUsage.KeyboardF14] = PhysicalKey.F14, + [UIKeyboardHidUsage.KeyboardF15] = PhysicalKey.F15, + [UIKeyboardHidUsage.KeyboardF16] = PhysicalKey.F16, + [UIKeyboardHidUsage.KeyboardF17] = PhysicalKey.F17, + [UIKeyboardHidUsage.KeyboardF18] = PhysicalKey.F18, + [UIKeyboardHidUsage.KeyboardF19] = PhysicalKey.F19, + [UIKeyboardHidUsage.KeyboardF20] = PhysicalKey.F20, + [UIKeyboardHidUsage.KeyboardF21] = PhysicalKey.F21, + [UIKeyboardHidUsage.KeyboardF22] = PhysicalKey.F22, + [UIKeyboardHidUsage.KeyboardF23] = PhysicalKey.F23, + [UIKeyboardHidUsage.KeyboardF24] = PhysicalKey.F24, + //[UIKeyboardHidUsage.KeyboardExecute] = 116, + //[UIKeyboardHidUsage.KeyboardHelp] = 117, + //[UIKeyboardHidUsage.KeyboardMenu] = 118, + [UIKeyboardHidUsage.KeyboardSelect] = PhysicalKey.Space, + //[UIKeyboardHidUsage.KeyboardStop] = 120, + //[UIKeyboardHidUsage.KeyboardAgain] = 121, + //[UIKeyboardHidUsage.KeyboardUndo] = 122, + //[UIKeyboardHidUsage.KeyboardCut] = 123, + //[UIKeyboardHidUsage.KeyboardCopy] = 124, + //[UIKeyboardHidUsage.KeyboardPaste] = 125, + //[UIKeyboardHidUsage.KeyboardFind] = 126, + [UIKeyboardHidUsage.KeyboardMute] = PhysicalKey.AudioVolumeMute, + [UIKeyboardHidUsage.KeyboardVolumeUp] = PhysicalKey.AudioVolumeUp, + [UIKeyboardHidUsage.KeyboardVolumeDown] = PhysicalKey.AudioVolumeDown, + //[UIKeyboardHidUsage.KeyboardLockingCapsLock] = PhysicalKey.CapsLock, + //[UIKeyboardHidUsage.KeyboardLockingNumLock] = PhysicalKey.Space, + //[UIKeyboardHidUsage.KeyboardLockingScrollLock] = 132, + [UIKeyboardHidUsage.KeypadComma] = PhysicalKey.NumPadComma, + //[UIKeyboardHidUsage.KeypadEqualSignAS400] = 134, + //[UIKeyboardHidUsage.KeyboardInternational1] = 135, + //[UIKeyboardHidUsage.KeyboardInternational2] = 136, + //[UIKeyboardHidUsage.KeyboardInternational3] = 137, + //[UIKeyboardHidUsage.KeyboardInternational4] = 138, + //[UIKeyboardHidUsage.KeyboardInternational5] = 139, + //[UIKeyboardHidUsage.KeyboardInternational6] = 140, + //[UIKeyboardHidUsage.KeyboardInternational7] = 141, + //[UIKeyboardHidUsage.KeyboardInternational8] = 142, + //[UIKeyboardHidUsage.KeyboardInternational9] = 143, + //[UIKeyboardHidUsage.KeyboardHangul] = 144, + //[UIKeyboardHidUsage.KeyboardKanaSwitch] = 144, + //[UIKeyboardHidUsage.KeyboardLang1] = 144, + //[UIKeyboardHidUsage.KeyboardAlphanumericSwitch] = 145, + //[UIKeyboardHidUsage.KeyboardHanja] = 145, + //[UIKeyboardHidUsage.KeyboardLang2] = 145, + //[UIKeyboardHidUsage.KeyboardKatakana] = 146, + //[UIKeyboardHidUsage.KeyboardLang3] = 146, + //[UIKeyboardHidUsage.KeyboardHiragana] = 147, + //[UIKeyboardHidUsage.KeyboardLang4] = 147, + //[UIKeyboardHidUsage.KeyboardLang5] = 148, + //[UIKeyboardHidUsage.KeyboardZenkakuHankakuKanji] = 148, + //[UIKeyboardHidUsage.KeyboardLang6] = 149, + //[UIKeyboardHidUsage.KeyboardLang7] = 150, + //[UIKeyboardHidUsage.KeyboardLang8] = 151, + //[UIKeyboardHidUsage.KeyboardLang9] = 152, + //[UIKeyboardHidUsage.KeyboardAlternateErase] = 153, + //[UIKeyboardHidUsage.KeyboardSysReqOrAttention] = 154, + //[UIKeyboardHidUsage.KeyboardCancel] = PhysicalKey.Cancel, + //[UIKeyboardHidUsage.KeyboardClear] = PhysicalKey.NumPadClear, + //[UIKeyboardHidUsage.KeyboardPrior] = PhysicalKey.Prior, + //[UIKeyboardHidUsage.KeyboardReturn] = PhysicalKey.Return, + //[UIKeyboardHidUsage.KeyboardSeparator] = PhysicalKey.Separator, + //[UIKeyboardHidUsage.KeyboardOut] = 160, + //[UIKeyboardHidUsage.KeyboardOper] = 161, + //[UIKeyboardHidUsage.KeyboardClearOrAgain] = 162, + //[UIKeyboardHidUsage.KeyboardCrSelOrProps] = 163, + //[UIKeyboardHidUsage.KeyboardExSel] = 164, + [UIKeyboardHidUsage.KeyboardLeftControl] = PhysicalKey.ControlLeft, + [UIKeyboardHidUsage.KeyboardLeftShift] = PhysicalKey.ShiftLeft, + [UIKeyboardHidUsage.KeyboardLeftAlt] = PhysicalKey.AltLeft, + [UIKeyboardHidUsage.KeyboardLeftGui] = PhysicalKey.MetaLeft, + [UIKeyboardHidUsage.KeyboardRightControl] = PhysicalKey.ControlRight, + [UIKeyboardHidUsage.KeyboardRightShift] = PhysicalKey.ShiftRight, + [UIKeyboardHidUsage.KeyboardRightAlt] = PhysicalKey.AltRight, + [UIKeyboardHidUsage.KeyboardRightGui] = PhysicalKey.MetaRight, + //[UIKeyboardHidUsage.KeyboardReserved] = 65535, + }; +} diff --git a/src/iOS/Avalonia.iOS/TouchHandler.cs b/src/iOS/Avalonia.iOS/TouchHandler.cs deleted file mode 100644 index b85affbce5..0000000000 --- a/src/iOS/Avalonia.iOS/TouchHandler.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System.Collections.Generic; -using Avalonia.Input; -using Avalonia.Input.Raw; -using Avalonia.Platform; -using Foundation; -using UIKit; - -namespace Avalonia.iOS -{ - class TouchHandler - { - private readonly AvaloniaView _view; - private readonly ITopLevelImpl _tl; - public TouchDevice _device = new(); - - public TouchHandler(AvaloniaView view, ITopLevelImpl tl) - { - _view = view; - _tl = tl; - } - - static ulong Ts(UIEvent? evt) => evt is null ? 0 : (ulong) (evt.Timestamp * 1000); - private IInputRoot Root => _view.InputRoot; - private static long _nextTouchPointId = 1; - private Dictionary _knownTouches = new Dictionary(); - - public void Handle(NSSet touches, UIEvent? evt) - { - foreach (UITouch t in touches) - { - var pt = t.LocationInView(_view).ToAvalonia(); - if (!_knownTouches.TryGetValue(t, out var id)) - _knownTouches[t] = id = _nextTouchPointId++; - - var ev = new RawTouchEventArgs(_device, Ts(evt), Root, - t.Phase switch - { - UITouchPhase.Began => RawPointerEventType.TouchBegin, - UITouchPhase.Ended => RawPointerEventType.TouchEnd, - UITouchPhase.Cancelled => RawPointerEventType.TouchCancel, - _ => RawPointerEventType.TouchUpdate - }, pt, RawInputModifiers.None, id); - - _tl.Input?.Invoke(ev); - - if (t.Phase == UITouchPhase.Cancelled || t.Phase == UITouchPhase.Ended) - _knownTouches.Remove(t); - } - } - - } -}