Esempio n. 1
0
    void Update()
    {
        if ((Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter)) && Game.Instance.IsRunning)
        {
            string inputString = InputField.text;

            if (!string.IsNullOrWhiteSpace(inputString))
            {
                InputReceived?.Invoke(this, inputString);
                CommandContext lastCommand = Game.Instance.CommandManager.Parse(inputString);
                if (lastCommand.Command != null)
                {
                    AddToHistory(inputString);
                }
            }

            InputField.text = string.Empty;
            //eventSystem.SetSelectedGameObject(InputField.gameObject);
            InputField.ActivateInputField();
        }

        if (Input.GetKeyDown(KeyCode.Escape))
        {
            InputReceived?.Invoke(this, "Quit");
        }

        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            InputField.text = CommandHistory[Clamp(CommandHistoryIndex--, 0, CommandHistory.Count - 1)];
        }
        else if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            InputField.text = CommandHistory[Clamp(CommandHistoryIndex++, 0, CommandHistory.Count - 1)];
        }
    }
Esempio n. 2
0
        public void PollForInput()
        {
            InputResult inputReceived;
            var         key = ReadKey();

            switch (key.Key)
            {
            case ConsoleKey.W:
                inputReceived = InputResult.North;
                break;

            case ConsoleKey.A:
                inputReceived = InputResult.West;
                break;

            case ConsoleKey.S:
                inputReceived = InputResult.South;
                break;

            case ConsoleKey.D:
                inputReceived = InputResult.East;
                break;

            default:
                inputReceived = InputResult.Invalid;
                break;
            }

            if (inputReceived != InputResult.Invalid)
            {
                InputReceived?.Invoke(inputReceived);
            }
        }
Esempio n. 3
0
        public void KeyPressed(KeyCode keyCode, KeyModifiers keyModifiers)
        {
            if (keyCode == KeyCode.Return)
            {
                InputReceived?.Invoke(this, InputText);
                InputText     = string.Empty;
                IsTakingInput = false;
            }
            else if (keyCode == KeyCode.Backspace)
            {
                if (InputText.Length == 0)
                {
                    return;
                }

                InputText = InputText.Substring(0, InputText.Length - 1);
            }
            else if (keyCode == KeyCode.Escape)
            {
                InputText     = string.Empty;
                IsTakingInput = false;

                InputCanceled?.Invoke(this, EventArgs.Empty);
            }
        }
Esempio n. 4
0
 private void HandleStandaloneKeyboardInput()
 {
     if (Input.GetKeyDown(KeyCode.UpArrow))
     {
         InputReceived?.Invoke(InputType.SwipeUp);
     }
     if (Input.GetKeyDown(KeyCode.RightArrow))
     {
         InputReceived?.Invoke(InputType.SwipeRight);
     }
     if (Input.GetKeyDown(KeyCode.DownArrow))
     {
         InputReceived?.Invoke(InputType.SwipeDown);
     }
     if (Input.GetKeyDown(KeyCode.LeftArrow))
     {
         InputReceived?.Invoke(InputType.SwipeLeft);
     }
     if (Input.GetKeyDown(KeyCode.Space))
     {
         InputReceived?.Invoke(InputType.Tap);
     }
     if (Input.GetKeyDown(KeyCode.LeftAlt))
     {
         InputReceived?.Invoke(InputType.Hold);
     }
 }
 private void OnSourceKeyDown(object sender, KeyEventArgs e)
 {
     if (isInputActive)
     {
         InputReceived?.Invoke(new GameInputEventArgs(e.Key));
     }
 }
Esempio n. 6
0
        protected override IntPtr OnInputReceived(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (InputReceived == null)
            {
                return(base.OnInputReceived(nCode, wParam, lParam));
            }

            if (nCode >= 0)
            {
                var msg = (WindowsMessages)wParam.ToInt32();

                var input = new KeyboardInput((KeyCodes)Marshal.ReadInt32(lParam));

                switch (msg)
                {
                case WindowsMessages.WM_KEYDOWN:
                case WindowsMessages.WM_SYSKEYDOWN:
                    input.State = KeyState.Down;
                    break;

                case WindowsMessages.WM_KEYUP:
                case WindowsMessages.WM_SYSKEYUP:
                    input.State = KeyState.Up;
                    break;
                }

                InputReceived?.Invoke(input);
            }

            return(base.OnInputReceived(nCode, wParam, lParam));
        }
Esempio n. 7
0
        public void AwaitInput()
        {
            var input = Console.ReadKey(true).KeyChar;
            var val   = input - 48;

            InputReceived?.Invoke(null, val);
        }
Esempio n. 8
0
 public void Listen()
 {
     if (Console.KeyAvailable)
     {
         InputReceived?.Invoke(this, new EventArgs());
     }
 }
 public void GetInput()
 {
     string inputString = Console.ReadLine();
     if(string.IsNullOrWhiteSpace(inputString) == false)
     {
         InputReceived?.Invoke(this, inputString);
     }
 }
Esempio n. 10
0
 public void Start(IHero hero, IBoard board)
 {
     while (true)
     {
         var key = Console.ReadKey(true).Key;
         InputReceived?.Invoke(key, new HeroMovementArgs(hero, board));
     }
 }
Esempio n. 11
0
        //Preprocess non-serialized data and manage standard IPC messages
        private void PreProcessMessage(byte[] data)
        {
            IpcMessageType type = (IpcMessageType)data[0];

            if (type == IpcMessageType.AnonIpcInputData)
            {
                InputReceived?.Invoke(this, new ISInputData(data, 1));
                return;
            }
            else if (type == IpcMessageType.IpcPoll)
            {
                HandlePoll(new IpcMessage(data));
                return;
            }
            else if (type == IpcMessageType.IpcHostOK)
            {
                HandleHostOK();
                return;
            }
            else if (type == IpcMessageType.IpcClientOK)
            {
                HandleClientOK();
                return;
            }

            IpcMessage msg = null;

            if (type == IpcMessageType.AnonIpcClipboardData)
            {
                msg = new AnonIpc.Messages.AnonIpcClipboardDataMessage(data);
            }
            else if (type == IpcMessageType.AnonIpcDisplayConfigReply)
            {
                msg = new AnonIpc.Messages.AnonIpcDisplayConfigMessage(data);
            }
            else if (type == IpcMessageType.AnonIpcStreamReadResponse)
            {
                msg = new AnonIpc.Messages.AnonIpcReadStreamResponseMessage(data);
            }
            else if (type == IpcMessageType.AnonIpcDoDragDrop)
            {
                msg = new AnonIpc.Messages.AnonIpcDoDragDropMessage(data);
            }
            else if (type == IpcMessageType.AnonIpcFileTokenResponse)
            {
                msg = new AnonIpc.Messages.AnonIpcRequestFileTokenResponseMessage(data);
            }

            if (msg == null)
            {
                msg = new IpcMessage(data);
            }

            if (!CheckAwaitingMessages(msg))
            {
                ProcessMessage(type, data);
            }
        }
Esempio n. 12
0
#pragma warning restore CS0067

    public void ProcessInput()
    {
        Assert.IsNotNull(InputField);
        Assert.IsFalse(string.IsNullOrEmpty(InputField.text));

        InputReceived?.Invoke(this, InputField.text.Trim());

        InputField.text = string.Empty;
    }
Esempio n. 13
0
 public void AwaitInput()
 {
     // stick to the right-most wall
     var(next, s) = NextPosition();
     _last        = _pos;
     _pos         = next;
     _state       = s;
     InputReceived?.Invoke(this, (int)_state);
 }
        public void ProcessInput()
        {
            string inputString = Console.ReadLine().Trim();


            InputReceived?.Invoke(this, inputString);

            // if (inputreceived !=null) {  inputreceived,,,,, equiv
        }
Esempio n. 15
0
        public void Execute(object parameter)
        {
            KeyBinding keyBinding = parameter as KeyBinding;

            if (keyBinding != null && myIsInvokationEnabled)
            {
                InputReceived?.Invoke(new GameInputEventArgs(keyBinding.Key));
            }
        }
        /// <summary>
        /// Process the data received from the powershell on
        /// the client.
        /// </summary>
        /// <param name="receivedData">Data received.</param>
        internal void ProcessReceivedData(RemoteDataObject <PSObject> receivedData)
        {
            if (receivedData == null)
            {
                throw PSTraceSource.NewArgumentNullException("receivedData");
            }

            Dbg.Assert(receivedData.TargetInterface == RemotingTargetInterface.PowerShell,
                       "RemotingTargetInterface must be PowerShell");

            switch (receivedData.DataType)
            {
            case RemotingDataType.StopPowerShell:
            {
                Dbg.Assert(StopPowerShellReceived != null,
                           "ServerPowerShellDriver should subscribe to all data structure handler events");
                StopPowerShellReceived.SafeInvoke(this, EventArgs.Empty);
            }

            break;

            case RemotingDataType.PowerShellInput:
            {
                Dbg.Assert(InputReceived != null,
                           "ServerPowerShellDriver should subscribe to all data structure handler events");
                InputReceived.SafeInvoke(this, new RemoteDataEventArgs <object>(receivedData.Data));
            }

            break;

            case RemotingDataType.PowerShellInputEnd:
            {
                Dbg.Assert(InputEndReceived != null,
                           "ServerPowerShellDriver should subscribe to all data structure handler events");
                InputEndReceived.SafeInvoke(this, EventArgs.Empty);
            }

            break;

            case RemotingDataType.RemotePowerShellHostResponseData:
            {
                Dbg.Assert(HostResponseReceived != null,
                           "ServerPowerShellDriver should subscribe to all data structure handler events");

                RemoteHostResponse remoteHostResponse = RemoteHostResponse.Decode(receivedData.Data);

                // part of host message robustness algo. Now the host response is back, report to transport that
                // execution status is back to running
                _transportManager.ReportExecutionStatusAsRunning();

                HostResponseReceived.SafeInvoke(this, new RemoteDataEventArgs <RemoteHostResponse>(remoteHostResponse));
            }

            break;
            }
        }
Esempio n. 17
0
        /// <summary>Fires the event: <see cref="InputReceived"/></summary>
        private void OnInputReceived(TorXakisAction action)
        {
            // Sanity checks.
            if (action.Type != ActionType.Input)
            {
                throw new ArgumentException("Not input: " + action);
            }

            Log.Info(this, nameof(InputReceived) + ": " + action);
            InputReceived?.Invoke(action);
        }
Esempio n. 18
0
 public void StartListening(IModel model, IBoard board)
 {
     while (true)
     {
         ConsoleKeyInfo keyInfo = Console.ReadKey();
         InputReceived?.Invoke(this, new CommandEventArgs()
         {
             ReceivedCommand = keyInfo
         });
         HeroTripMine?.Invoke(model.Hero, new GameEventArgs());
     }
 }
Esempio n. 19
0
        public void StartListening()
        {
            while (true)
            {
                var keyInfo = Console.ReadKey();


                InputReceived?.Invoke(this, new CommandEventArgs()
                {
                    ReceivedCommand = keyInfo
                });
            }
        }
Esempio n. 20
0
        private void InputEventReceivedHandler(Input input)
        {
            InputReceived?.Invoke(input);

            if (input.GetType() == typeof(MouseInput))
            {
                MouseInputReceived?.Invoke(input as MouseInput);
            }
            else
            {
                KeyboardInputReceived?.Invoke(input as KeyboardInput);
            }
        }
    void Update()
    {
        if (Input.GetKey(KeyCode.Return))
        {
            string inputString = InputField.text;
            if (string.IsNullOrWhiteSpace(inputString) == false)
            {
                InputReceived?.Invoke(this, inputString);
            }

            InputField.text = string.Empty;
        }
    }
Esempio n. 22
0
        IntPtr KeyboardHook(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode >= 0)
            {
                var keyboardMessage = (WindowsApi.KeyboardMessage)wParam.ToInt32();
                var keyboardData    = (WindowsApi.KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(WindowsApi.KBDLLHOOKSTRUCT));

                var  key    = KeyFromVirtualCode(keyboardData.VkCode);
                bool isDown = keyboardMessage == WindowsApi.KeyboardMessage.WM_KEYDOWN || keyboardMessage == WindowsApi.KeyboardMessage.WM_SYSKEYDOWN;

                InputReceived?.Invoke(this, new KeyboardInputEventArgs(key, isDown));
            }

            return(WindowsApi.CallNextHookEx(IntPtr.Zero, nCode, wParam, lParam));
        }
Esempio n. 23
0
        public void StartListening()
        {
            while (true)
            {
                var key = System.Console.ReadKey().Key;

                if (key.Equals(ConsoleKey.Escape))
                {
                    break;
                }

                InputReceived?.Invoke(this, new CommandEventArgs {
                    ReceivedCommand = key
                });
            }
        }
Esempio n. 24
0
        public void Update()
        {
            var input = Vector3.zero;

            input.x = UnityEngine.Input.GetAxis("Horizontal");
            input.z = UnityEngine.Input.GetAxis("Vertical");
            MovementReceived?.Invoke(input);

            foreach (var key in actions.Keys)
            {
                if (UnityEngine.Input.GetKeyDown(key))
                {
                    InputReceived?.Invoke(actions[key]);
                }
            }
        }
Esempio n. 25
0
        public void StartListen()
        {
            while (true)
            {
                ConsoleKey key = Console.ReadKey().Key;

                if (key == ConsoleKey.Escape)
                {
                    Console.SetCursorPosition(0, StaticRegistry.board.Height + 1);
                    break;
                }

                InputReceived?.Invoke(this, new TurnEventArgs {
                    ReceivedCommand = key
                });
            }
        }
Esempio n. 26
0
        private void Backspace()
        {
            if (text.Length > 0 && InputPosition > 0)
            {
                text = text.Remove(InputPosition - 1, 1);
                InputPosition--;

                if (TextStartPosition > 0)
                {
                    TextStartPosition--;
                }

                TextEndPosition--;
                TextChanged?.Invoke(this, EventArgs.Empty);
            }

            InputReceived?.Invoke(this, EventArgs.Empty);
        }
        private void PollGamepadState()
        {
            if (window.Focused)
            {
                var newGamePadState = GamePad.GetState(0);
                if (!oldGamePadState.Equals(newGamePadState))
                {
                    if ((newGamePadState.Buttons.Back != oldGamePadState.Buttons.Back) &&
                        newGamePadState.Buttons.Back.Equals(ButtonState.Released))
                    {
                        InputReceived?.Invoke(InputType.EXIT);
                    }

                    if ((newGamePadState.Buttons.B != oldGamePadState.Buttons.B) &&
                        newGamePadState.Buttons.B.Equals(ButtonState.Released))
                    {
                        InputReceived?.Invoke(InputType.BACK);
                    }

                    if ((newGamePadState.Buttons.A != oldGamePadState.Buttons.A) &&
                        newGamePadState.Buttons.A.Equals(ButtonState.Released))
                    {
                        InputReceived?.Invoke(InputType.SELECT);
                    }

                    if ((newGamePadState.DPad.Left != oldGamePadState.DPad.Left) &&
                        newGamePadState.DPad.Left.Equals(ButtonState.Released))
                    {
                        InputReceived?.Invoke(InputType.LEFT);
                    }

                    if ((newGamePadState.DPad.Right != oldGamePadState.DPad.Right) &&
                        newGamePadState.DPad.Right.Equals(ButtonState.Released))
                    {
                        InputReceived?.Invoke(InputType.RIGHT);
                    }
                }

                oldGamePadState = newGamePadState;
            }
        }
Esempio n. 28
0
        private void DeleteCharacter()
        {
            if (text.Length > InputPosition)
            {
                text = text.Remove(InputPosition, 1);

                if (TextStartPosition > 0)
                {
                    TextStartPosition--;
                }

                if (TextEndPosition > text.Length || !TextFitsBox())
                {
                    TextEndPosition--;
                }

                TextChanged?.Invoke(this, EventArgs.Empty);
            }

            InputReceived?.Invoke(this, EventArgs.Empty);
        }
Esempio n. 29
0
        protected override IntPtr OnInputReceived(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (InputReceived == null)
            {
                return(base.OnInputReceived(nCode, wParam, lParam));
            }

            if (nCode >= 0 && lParam != IntPtr.Zero && wParam != IntPtr.Zero)
            {
                var msg            = (WindowsMessages)wParam.ToInt32();
                var msllhookstruct = Marshal.PtrToStructure <MSLLHOOKSTRUCT>(lParam);

                var input = _processorPipeline.Process(
                    msg,
                    msllhookstruct);

                InputReceived?.Invoke(input);
            }

            return(base.OnInputReceived(nCode, wParam, lParam));
        }
Esempio n. 30
0
        private void OnDataReceived(int clientId, byte[] data)
        {
            var reader     = new Deserializer(Compressor.Decompress(data));
            var messageTag = (MessageTag)reader.GetByte();

            switch (messageTag)
            {
            case MessageTag.Input:
                ++inputMessageCounter;

                var clientTick = reader.GetUInt();
                reader.GetByte();     //Client's lag-compensation
                var commandsCount = reader.GetInt();
                if (commandsCount > 0 || inputMessageCounter % 8 == 0)
                {
                    _server.Distribute(clientId, data);
                }

                InputReceived?.Invoke(this, new InputReceivedEventArgs(_actorIds[clientId], clientTick));
                break;

            case MessageTag.HashCode:
                var pkt = new HashCode();
                pkt.Deserialize(reader);
                if (!_hashCodes.ContainsKey(pkt.FrameNumber))
                {
                    _hashCodes[pkt.FrameNumber] = pkt.Value;
                }
                else
                {
                    Console.WriteLine((_hashCodes[pkt.FrameNumber] == pkt.Value ? "HashCode valid" : "Desync") + ": " + pkt.Value);
                }
                break;

            default:
                _server.Distribute(data);
                break;
            }
        }