/// <summary>
 /// Constructs a new RemoteControlKeyEventArgs object for a key type, key name, and platform key name.
 /// </summary>
 /// <param name="sender">The VisualElement that sends the event.</param>
 /// <param name="keyType">The type of a remote control key.</param>
 /// <param name="keyName">The name of a remote control key.</param>
 /// <param name="platformKeyName">The name of a platform key name.</param>
 public RemoteControlKeyEventArgs(VisualElement sender, RemoteControlKeyTypes keyType, RemoteControlKeyNames keyName, string platformKeyName)
 {
     Sender          = sender;
     KeyType         = keyType;
     KeyName         = keyName;
     PlatformKeyName = platformKeyName;
 }
Exemple #2
0
        bool InvokeActionAndEvent(RemoteControlKeyTypes keyType, string keyName, bool isHandled = false)
        {
            RemoteControlKeyEventArgs args = RemoteControlKeyEventArgs.Create((VisualElement)Element, keyType, keyName, isHandled);

            if (args == null)
            {
                return(false);
            }

            if (Element is Page targetPage)
            {
                if (!IsOnMainPage(targetPage))
                {
                    return(false);
                }
            }

            var handlers = InputEvents.GetEventHandlers(Element);

            foreach (RemoteKeyHandler item in handlers)
            {
                item.SendKeyEvent(args);
            }
            return(args.Handled);
        }
Exemple #3
0
 /// <summary>
 /// Initializes a new instance of the RemoteKeyHandler class with its action which is set to Command and key type.
 /// </summary>
 /// <param name="action">An action to invoke when the remote control event with the specifiec key type is invoked.</param>
 /// <param name="keyType">A key type to invoke the action.</param>
 public RemoteKeyHandler(Action <RemoteControlKeyEventArgs> action, RemoteControlKeyTypes keyType)
 {
     Command          = new Command <RemoteControlKeyEventArgs>(action);
     _acceptedKeyType = keyType;
 }
        internal static RemoteControlKeyEventArgs Create(VisualElement visualElement, RemoteControlKeyTypes keyType, string keyName, bool isHandled = false)
        {
            RemoteControlKeyNames key = RemoteControlKeyNames.Unknown;

            if (!Enum.TryParse(keyName, out key))
            {
                if (!Enum.TryParse("NUM" + keyName, out key))
                {
                    if (keyName.StartsWith("XF86"))
                    {
                        string simpleKeyName = keyName.Replace("XF86", "").Replace("Audio", "");
                        Enum.TryParse(simpleKeyName, out key);
                    }
                }
            }

            return(new RemoteControlKeyEventArgs(visualElement, keyType, key, keyName)
            {
                Handled = isHandled
            });
        }