Example #1
0
        /// <summary>
        /// Gets the <see cref="Command"/> encoded by given command string.
        /// </summary>
        /// <param name="commandString">The command string to parse.</param>
        /// <returns>The <see cref="Command"/> encoded by given command string.</returns>
        public static Command GetCommand(string commandString)
        {
            if (commandString.StartsWith("IRCODE"))
            {
                return(IrCommand.Parse(commandString));
            }

            if (commandString.StartsWith("KEYBOARD"))
            {
                return(KeyboardCommand.Parse(commandString));
            }

            if (commandString.StartsWith("SETCH"))
            {
                return(SetChCommand.Parse(commandString));
            }

            if (commandString.StartsWith("FORCECH"))
            {
                return(ForceChCommand.Parse(commandString));
            }

            if (commandString.StartsWith("TELEPORT"))
            {
                return(TeleportCommand.Parse(commandString));
            }

            return(null);
        }
        private bool HandleCtrlPress(Key e)
        {
            if (isHotKeysDisable)
            {
                return(false);
            }

            switch (e)
            {
            case Key.Space:
                currentCommand = KeyboardCommand.Search;
                App.ClipBoardHook.CopyFromActiveProgram();
                return(true);

            case Key.R:
                currentCommand = KeyboardCommand.OCRSentences;
                SnippingTool.Snip();
                return(true);

            case Key.D1:
                currentCommand = KeyboardCommand.OCROneLetter;
                SnippingTool.Snip();
                return(true);

            case Key.T:
                currentCommand = KeyboardCommand.TTS;
                App.ClipBoardHook.CopyFromActiveProgram();
                return(true);

            default:
                return(false);
            }
        }
Example #3
0
    // One of the keyboard input is pressed
    private void HandleKeyPressedCommand(KeyboardCommand command)
    {
        switch (command)
        {
        case KeyboardCommand.MoveLeft:
            controlledPlayer.MoveX(-1f);
            hasMoved = true;
            break;

        case KeyboardCommand.MoveRight:
            controlledPlayer.MoveX(1f);
            hasMoved = true;
            break;

        case KeyboardCommand.Jump:
            break;

        case KeyboardCommand.Transpose:
            break;

        case KeyboardCommand.Interact:
            break;

        case KeyboardCommand.ResetShadow:
            break;
        }
    }
Example #4
0
    // One of the gamepad button input is released
    private void HandleKeyDownCommand(KeyboardCommand command)
    {
        switch (command)
        {
        case KeyboardCommand.MoveLeft:
            break;

        case KeyboardCommand.MoveRight:
            break;

        case KeyboardCommand.Jump:
            controlledPlayer.Jump();
            break;

        case KeyboardCommand.Transpose:
            controlledPlayer.Transpose();
            hasTransposed = true;
            break;

        case KeyboardCommand.Interact:
            controlledPlayer.Interact();
            hasInteracted = true;
            break;

        case KeyboardCommand.ResetShadow:
            controlledPlayer.ResetShadow();
            break;
        }
    }
Example #5
0
            public KeyboardCommand createUnicodeKey(ScanCodeShort unicode)
            {
                var res = new KeyboardCommand();

                res.keyType = KeyType.UNICODE;
                res.scanKey = unicode;
                res.keyDown = false;
                return(res);
            }
Example #6
0
            public KeyboardCommand createVirtualKey(VirtualKeyShort vk, bool keyDown = true)
            {
                var res = new KeyboardCommand();

                res.keyType = KeyType.VIRTUAL_KEY;
                res.vk      = vk;
                res.keyDown = keyDown;
                return(res);
            }
Example #7
0
            public KeyboardCommand createScanKey(ScanCodeShort scanKey, bool extendedKey = false, bool keyDown = true)
            {
                var res = new KeyboardCommand();

                res.keyType         = KeyType.SCAN;
                res.scanKey         = scanKey;
                res.scanExtendedKey = extendedKey;
                res.keyDown         = keyDown;
                return(res);
            }
Example #8
0
        protected internal virtual void HandleCommandPressed(KeyboardCommand command)
        {
            switch (command)
            {
            case KeyboardCommand.Backspace:
                if (Text.Length > 0 && CursorPosition > 0)
                {
                    CursorPosition--;
                    Text = Text.Remove(CursorPosition, 1);
                }
                break;

            case KeyboardCommand.Enter:
                EnterPressed?.Invoke(this, EventArgs.Empty);
                break;

            case KeyboardCommand.CursorLeft:
                if (CursorPosition > 0)
                {
                    CursorPosition--;
                }
                break;

            case KeyboardCommand.CursorRight:
                if (CursorPosition < Text.Length)
                {
                    CursorPosition++;
                }
                break;

            case KeyboardCommand.CursorUp:
                //TODO cursor up handling
                break;

            case KeyboardCommand.CursorDown:
                //TODO cursor down handling
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        // 键鼠事件
        public Packet hidCommandExec(Packet packet)
        {
            int        hidType    = packet.nextByte() & 0xff;
            int        eventType  = packet.nextByte() & 0xff;
            int        key        = packet.nextByte() & 0xff;
            short      x          = packet.nextShort();
            short      y          = packet.nextShort();
            int        timestamp  = packet.nextInt() & 0x7fffffff;
            HIDCommand hidCommand = null;

            if (hidType == HIDCommand.TYPE_MOUSE)
            {
                hidCommand = new MouseCommand(eventType, key, x, y, timestamp);
                hidExecutor.add(hidCommand);
            }
            else
            {
                hidCommand = new KeyboardCommand(key, eventType, timestamp);
            }
            return(null);
        }
Example #10
0
        public void LoadCommands()
        {
            var texts = System.IO.File.ReadAllLines(@"WriteLines.txt");

            Commands = new List <AbstractCommand>();
            foreach (var line in texts)
            {
                if (line.StartsWith("C"))
                {
                    Commands.Add(MouseClickCommand.FromString(line));
                }
                else if (line.StartsWith("M"))
                {
                    Commands.Add(MoveCommand.FromString(line));
                }
                else if (line.StartsWith("K"))
                {
                    Commands.Add(KeyboardCommand.FromString(line));
                }
            }
        }
Example #11
0
    // One of the keyboard input is released
    private void HandleKeyUpCommand(KeyboardCommand command)
    {
        switch (command)
        {
        case KeyboardCommand.MoveLeft:
        case KeyboardCommand.MoveRight:
            controlledPlayer.MoveX(0f);
            hasMoved = true;
            break;

        case KeyboardCommand.Jump:
            //controlledPlayer.Jump(false);
            break;

        case KeyboardCommand.Transpose:
            break;

        case KeyboardCommand.Interact:
            break;
        }
    }
Example #12
0
        private void FindAndReplaceRootGrid_KeyDown(object sender, KeyRoutedEventArgs e)
        {
            var ctrlDown  = Window.Current.CoreWindow.GetKeyState(VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down);
            var altDown   = Window.Current.CoreWindow.GetKeyState(VirtualKey.Menu).HasFlag(CoreVirtualKeyStates.Down);
            var shiftDown = Window.Current.CoreWindow.GetKeyState(VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down);

            var isNativeKeyboardCommand = false;

            foreach (var KeyboardCommand in _nativeKeyboardCommands)
            {
                if (KeyboardCommand.Hit(ctrlDown, altDown, shiftDown, e.Key))
                {
                    isNativeKeyboardCommand = true;
                    break;
                }
            }

            if (!isNativeKeyboardCommand && !e.Handled)
            {
                OnFindReplaceControlKeyDown?.Invoke(sender, e);
            }
        }
Example #13
0
 protected internal void OnKeyPressed(KeyboardCommand key)
 {
     KeyPressed?.Invoke(this, new KeyEventArgs(key));
 }
 public KeyEventArgs(KeyboardCommand command)
 {
     InputType = InputType.Command;
     Command   = command;
 }
 public KeyboardMessageHeader(KeyboardCommand cmd)
     : this((uint)cmd)
 {
 }
 public KeyboardMessageHeader(KeyboardCommand cmd, KeyboardCommand arg1)
     : this((uint)cmd, (uint)arg1)
 {
 }
        /// <summary>
        /// Handles commands for the TiVo published to MQTT.
        /// </summary>
        /// <param name="e">Event args.</param>
        protected override async void Mqtt_MqttMsgPublishReceived(MqttApplicationMessageReceivedEventArgs e)
        {
            var message = e.ApplicationMessage.ConvertPayloadToString();

            _log.LogInformation("MQTT message received for topic " + e.ApplicationMessage.Topic + ": " + message);

            var commandType = e.ApplicationMessage.Topic.Replace(TopicRoot + "/controls/", string.Empty).Replace("/set", string.Empty);

            Command command = null;

            if (commandType == "setCh")
            {
                var messageParts = message.Split('.');
                if (int.TryParse(messageParts[0], out int channel))
                {
                    if (messageParts.Length == 1)
                    {
                        command = new SetChCommand {
                            Channel = channel
                        };
                    }
                    else if (messageParts.Length == 2 && int.TryParse(messageParts[0], out int subchannel))
                    {
                        command = new SetChCommand {
                            Channel = channel, Subchannel = subchannel
                        };
                    }
                }
            }

            if (commandType == "forceCh")
            {
                var messageParts = message.Split('.');
                if (int.TryParse(messageParts[0], out int channel))
                {
                    if (messageParts.Length == 1)
                    {
                        command = new ForceChCommand {
                            Channel = channel
                        };
                    }
                    else if (messageParts.Length == 2 && int.TryParse(messageParts[0], out int subchannel))
                    {
                        command = new ForceChCommand {
                            Channel = channel, Subchannel = subchannel
                        };
                    }
                }
            }

            if (commandType == "irCode")
            {
                command = new IrCommand {
                    IrCode = message
                }
            }
            ;

            if (commandType == "teleport")
            {
                command = new TeleportCommand {
                    TeleportCode = message
                }
            }
            ;

            if (commandType == "keyboard")
            {
                command = new KeyboardCommand {
                    KeyboardCode = message
                }
            }
            ;

            if (command != null)
            {
                await _client.SendCommandAsync(command)
                .ConfigureAwait(false);
            }
        }