Beispiel #1
0
    public void InvokeInputEvent(int input)
    {
        InputEventType inputEvent = InputEventType.Default;

        switch (input)
        {
        case 0:
            inputEvent = InputEventType.Up;
            break;

        case 1:
            inputEvent = InputEventType.Down;
            break;

        case 2:
            inputEvent = InputEventType.Left;
            break;

        case 3:
            inputEvent = InputEventType.Right;
            break;

        default:
            Debug.Log("ERR: InvokeInputEvent received bad input");
            break;
        }

        DispatchAllEvents(EventType.InputEvent, inputEvent);
    }
        protected void SetEvent(IInputAction action, InputEventType eventType, InputEventHandleAction handleAction, IInputHandler handler)
        {
            switch (eventType)
            {
            case InputEventType.KeyUp:
                if (handleAction == InputEventHandleAction.Add)
                {
                    action.KeyUp += handler.HandleInput;
                }
                else
                {
                    action.KeyUp -= handler.HandleInput;
                }
                break;

            case InputEventType.KeyDown:
                if (handleAction == InputEventHandleAction.Add)
                {
                    action.KeyDown += handler.HandleInput;
                }
                else
                {
                    action.KeyDown -= handler.HandleInput;
                }
                break;
            }
        }
    void Update()
    {
        InputEventType isKeyEvent = InputEventType.LAST;

        for (int i = 0; i < (int)InputKeyName.Last; i++, isKeyEvent = InputEventType.LAST)
        {
            if (Input.GetKeyDown(keyMap.allKeys[i]))
            {
                keyMapper[(InputKeyName)i][(int)InputEventType.Push]?.Invoke();
                isKeyEvent = InputEventType.Push;
            }
            else if (Input.GetKey(keyMap.allKeys[i]))
            {
                keyMapper[(InputKeyName)i][(int)InputEventType.Pushed]?.Invoke();
                isKeyEvent = InputEventType.Pushed;
            }
            else if (Input.GetKeyUp(keyMap.allKeys[i]))
            {
                keyMapper[(InputKeyName)i][(int)InputEventType.UP]?.Invoke();
                isKeyEvent = InputEventType.UP;
            }
            if (isKeyEvent != InputEventType.LAST && ((InputKeyName)i).isGameArrowKey())
            {
                UpdateAxis((InputKeyName)i, isKeyEvent);
            }
        }
    }
Beispiel #4
0
        private void ProcessEvents(IntPtr input_context)
        {
            // Process all events in the event queue
            while (true)
            {
                // Data available
                int ret = LibInput.Dispatch(input_context);
                if (ret != 0)
                {
                    Debug.Print("[Input] LibInput.Dispatch({0:x}) failed. Error: {1}",
                                input_context, ret);
                    break;
                }

                IntPtr pevent = LibInput.GetEvent(input_context);
                if (pevent == IntPtr.Zero)
                {
                    break;
                }

                IntPtr         device = LibInput.GetDevice(pevent);
                InputEventType type   = LibInput.GetEventType(pevent);

                lock (Sync)
                {
                    switch (type)
                    {
                    case InputEventType.DeviceAdded:
                        HandleDeviceAdded(input_context, device);
                        break;

                    case InputEventType.DeviceRemoved:
                        HandleDeviceRemoved(input_context, device);
                        break;

                    case InputEventType.KeyboardKey:
                        HandleKeyboard(GetKeyboard(device), LibInput.GetKeyboardEvent(pevent));
                        break;

                    case InputEventType.PointerAxis:
                        HandlePointerAxis(GetMouse(device), LibInput.GetPointerEvent(pevent));
                        break;

                    case InputEventType.PointerButton:
                        HandlePointerButton(GetMouse(device), LibInput.GetPointerEvent(pevent));
                        break;

                    case InputEventType.PointerMotion:
                        HandlePointerMotion(GetMouse(device), LibInput.GetPointerEvent(pevent));
                        break;

                    case InputEventType.PointerMotionAbsolute:
                        HandlePointerMotionAbsolute(GetMouse(device), LibInput.GetPointerEvent(pevent));
                        break;
                    }
                }

                LibInput.DestroyEvent(pevent);
            }
        }
Beispiel #5
0
        private void OnMouseInputEvent(Vector2 pixelPosition, MouseButton button, InputEventType type, float value = 0)
        {
            // The mouse wheel event are still received even when the mouse cursor is out of the control boundaries. Discard the event in this case.
            if (type == InputEventType.Wheel && !uiControl.ClientRectangle.Contains(uiControl.PointToClient(Control.MousePosition)))
            {
                return;
            }

            // the mouse events series has been interrupted because out of the window.
            if (type == InputEventType.Up && !MouseButtonCurrentlyDown[(int)button])
            {
                return;
            }

            CurrentMousePosition = NormalizeScreenPosition(pixelPosition);

            var mouseInputEvent = new MouseInputEvent {
                Type = type, MouseButton = button, Value = value
            };

            lock (MouseInputEvents)
                MouseInputEvents.Add(mouseInputEvent);

            if (type != InputEventType.Wheel)
            {
                var buttonId = (int)button;
                MouseButtonCurrentlyDown[buttonId] = type == InputEventType.Down;
                HandlePointerEvents(buttonId, CurrentMousePosition, InputEventTypeToPointerState(type), PointerType.Mouse);
            }
        }
 private void HandleKeyFrameworkElement(KeyRoutedEventArgs args, InputEventType inputEventType)
 {
     if (HandleKey(args.Key, args.KeyStatus, inputEventType))
     {
         args.Handled = true;
     }
 }
Beispiel #7
0
 /// <summary>
 /// Will fire the input event to the possesed entity if one is possesed
 /// </summary>
 /// <param name="action">The action</param>
 /// <param name="type">The type</param>
 /// <param name="metaData">Metadata</param>
 /// <param name="gameTime">Game Time</param>
 public void TriggerInputEvent(InputAction action, InputEventType type, float metaData, GameTime gameTime)
 {
     if (possesedEntity != null)
     {
         possesedEntity.OnInputEvent(action, type, metaData, gameTime);
     }
 }
 private void HandleKeyCoreWindow(KeyEventArgs args, InputEventType inputEventType)
 {
     if (HandleKey(args.VirtualKey, args.KeyStatus, inputEventType))
     {
         args.Handled = true;
     }
 }
Beispiel #9
0
    //Method to add a custom event function to be fired when a key goes down, up or each frame
    //Event function will have the InputData for that key passsed to it as the first argument when fired
    public void AddEvent(KeyCode _keyIdentifier, InputEventType _eventType, Function _function)
    {
        switch (_eventType)
        {
        case InputEventType.Down:
            downEventDict.Add(_keyIdentifier, _function);
            break;

        case InputEventType.Up:
            upEventDict.Add(_keyIdentifier, _function);
            break;

        case InputEventType.Changed:
            changedEventDict.Add(_keyIdentifier, _function);
            break;

        case InputEventType.Update:
            updateEventDict.Add(_keyIdentifier, _function);
            break;

        default:
            Debug.Log("INPUT SYSTEM ERROR \"AddEvent\": event has invalid type");
            break;
        }
    }
Beispiel #10
0
 private void OnInputReceived(IInputDevice device, InputEventType eventType)
 {
     if (OnAnyInputReceived != null)
     {
         OnAnyInputReceived(device, eventType);
     }
 }
Beispiel #11
0
 public MouseInputEvent(EventPropagator source, InputEventType type, KeyboardModifiers modifiers, bool isFocused, UIElement element)
 {
     this.source    = source;
     this.type      = type;
     this.modifiers = modifiers;
     this.element   = element;
 }
Beispiel #12
0
 public void RegisterInputEvent(string bindingName, Action callback, InputEventType eventType = InputEventType.Pressed)
 {
     foreach (var binding in InputBindings.Where(binding => binding.Name != null && binding.Name.Equals(bindingName)))
     {
         RegisterInputEvent(binding, callback, eventType);
     }
 }
Beispiel #13
0
 public InputPointerData(int pointerId, UnityEngine.Vector3 worldPosition, InputEventType eventType)
 {
     this.pointerId          = pointerId;
     this.worldPosition      = worldPosition;
     this.pressWorldPosition = worldPosition;
     this.eventType          = eventType;
 }
Beispiel #14
0
 public InputPointerData(int pointerId, FLOAT3 worldPosition, InputEventType eventType)
 {
     this.pointerId          = pointerId;
     this.worldPosition      = worldPosition;
     this.pressWorldPosition = worldPosition;
     this.eventType          = eventType;
 }
Beispiel #15
0
        internal bool Invoke(InputEventType eventType)
        {
            if (!Enabled)
            {
                return(false);
            }

            InputEventList list = getEventList(eventType);

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

            for (int i = list.BindList.Count - 1; i >= 0; i--)
            {
                Delegate d = list.BindList[i];
                if ((bool)d.DynamicInvoke(null, null))
                {
                    return(true);
                }
            }

            return(false);
        }
 private IInputArgs GetInputArgs(InputEventType eventType)
 {
     return(new InputArgs()
     {
         ActionName = Name, Key = BindingKey, EventType = eventType
     });
 }
Beispiel #17
0
 protected DragEventHandlerAttribute(Type requiredType, KeyboardModifiers modifiers, InputEventType eventType, EventPhase phase)
 {
     this.modifiers    = modifiers;
     this.eventType    = eventType;
     this.phase        = phase;
     this.requiredType = requiredType;
 }
        private void OnMouseInputEvent(Vector2 pixelPosition, H1MouseButton button, InputEventType type, float value = 0.0f)
        {
            // the mouse wheel event are still received when the mouse cursor is out of the control boundaries. discard the event in this case
            if (type == InputEventType.Wheel && !Control.IsMouseOver)
            {
                return;
            }

            // the mouse event series has been interrupted because out of the window
            if (type == InputEventType.Up && !m_MouseButtonCurrentlyDown[(int)button])
            {
                return;
            }

            m_CurrentMousePosition = NormalizeScreenPosition(pixelPosition);

            var mouseInputEvent = new MouseInputEvent {
                Type = type, MouseButton = button, Value = value
            };

            m_MouseInputEvents.Add(mouseInputEvent);

            if (type != InputEventType.Wheel)
            {
                var buttonId = (int)button;
                m_MouseButtonCurrentlyDown[buttonId] = type == InputEventType.Down;
                HandleMouseMovingEvents(buttonId, m_CurrentMousePosition, InputEventTypeToMouseState(type));
            }
        }
Beispiel #19
0
 private void OnInputReceived(IInputDevice inputDevice, InputEventType inputEvent)
 {
     if (m_IsGameReadyToStart && inputEvent == InputEventType.Start)
     {
         ((IAnimation)m_EndAnimation).StartAnimation(() => { SceneController.TransitionToScene(m_FightScene); });
     }
 }
Beispiel #20
0
 /// <summary>
 /// Event for axis changes.
 /// </summary>
 /// <param name="owner"></param>
 /// <param name="axisId"></param>
 /// <param name="delta"></param>
 /// <param name="state"></param>
 public InputEvent(InputDevice owner, uint axisId, long delta, long state)
 {
     this.owner       = owner;
     this.id          = axisId;
     this.delta       = delta;
     this.stateRecord = state;
     this.type        = InputEventType.Axis;
 }
Beispiel #21
0
 private InputEvent(InputEventType type, long timestamp, int param) : this()
 {
     Type      = type;
     Timestamp = timestamp;
     Param     = param;
     Handled   = false;
     Paused    = false;
 }
 public InputEvent(string name, bool negative, InputEventType type, UnityAction callback)
 {
     this.name     = name;
     this.negative = negative;
     this.type     = type;
     this.callback = new UnityEvent();
     this.callback.AddListener(callback);
 }
Beispiel #23
0
 public KeyboardInputEvent(EventPropagator source, InputEventType type, KeyCode keyCode, char character, KeyboardModifiers modifiers, bool isFocused)
 {
     this.source    = source;
     this.eventType = type;
     this.keyCode   = keyCode;
     this.modifiers = modifiers;
     this.character = character;
     this.isFocused = isFocused;
 }
 protected KeyboardInputBindingAttribute(KeyCode key, char character, KeyboardModifiers modifiers, InputEventType eventType, bool requiresFocusKeyEventPhase, EventPhase keyEventPhase)
 {
     this.key           = key;
     this.character     = character;
     this.modifiers     = modifiers;
     this.eventType     = eventType;
     this.requiresFocus = requiresFocusKeyEventPhase;
     this.keyEventPhase = keyEventPhase;
 }
Beispiel #25
0
        internal void Unbind(InputEventType eventType, InputHandlerDelegate del)
        {
            InputEventList list = getEventList(eventType);

            if (list != null)
            {
                list.BindList.Remove(del);
            }
        }
Beispiel #26
0
 /// <summary>
 /// Event for buttons.
 /// </summary>
 /// <param name="owner"></param>
 /// <param name="buttonId"></param>
 /// <param name="state"></param>
 public InputEvent(InputDevice owner, uint buttonId, bool state,
                   InputEventModifier modifiers, KeyboardModifiers keyModifiers)
 {
     this.owner             = owner;
     this.type              = InputEventType.Button;
     this.stateRecord       = state ? 1 : 0;
     this.id                = buttonId;
     this.inputModifiers    = modifiers;
     this.keyboardModifiers = keyModifiers;
 }
Beispiel #27
0
        private void SendEvent(InputControl ic, InputEventType et, long now)
        {
            var e = new InputEvent {
                Type    = et,
                Control = ic
            };

            ic.NotifyEvent(ref e);
            ic.LastEventTime = now;
        }
Beispiel #28
0
 public void HitTest(MapLocation pos, InputEventType inputtype)
 {
     foreach (MapLayer maplayer in maplayerItems)
     {
         maplayer.HitTest(pos, inputtype);
     }
     foreach (Layer layer in layerItems)
     {
         layer.HitTest(pos, inputtype);
     }
 }
Beispiel #29
0
        private InputEventList getEventList(InputEventType eventType)
        {
            InputEventList list = eventLists.Find(h => h.Type == eventType);

            if (list == null)
            {
                eventLists.Add(list = new InputEventList(eventType));
            }

            return(list);
        }
Beispiel #30
0
 public InputEvent(string name)
 {
     m_name       = name;
     m_actionName = "";
     m_keyCode    = KeyCode.None;
     m_eventType  = InputEventType.Key;
     m_inputState = InputState.Pressed;
     m_playerID   = PlayerID.One;
     m_onAxis     = new AxisEvent();
     m_onAction   = new ActionEvent();
 }
Beispiel #31
0
 private static extern void ICall_Input_GetCurrentKeyEvent(int index, out Code code, out InputEventType _event);
Beispiel #32
0
 private static extern void ICall_Input_GetCurrentMouseButtonEvent(int index, out MouseCode code, out InputEventType _event);
Beispiel #33
0
 private static extern void ICall_Input_GetCurrentTouchEvent(int index, out int id, out InputEventType _event);
 private void HandleKeyFrameworkElement(KeyRoutedEventArgs args, InputEventType inputEventType)
 {
     if (HandleKey(args.Key, args.KeyStatus, inputEventType))
         args.Handled = true;
 }
 private void HandleKeyCoreWindow(KeyEventArgs args, InputEventType inputEventType)
 {
     if (HandleKey(args.VirtualKey, args.KeyStatus, inputEventType))
         args.Handled = true;
 }
        private void OnMouseInputEvent(Vector2 pixelPosition, MouseButton button, InputEventType type, float value = 0)
        {
            // The mouse wheel event are still received even when the mouse cursor is out of the control boundaries. Discard the event in this case.
            if (type == InputEventType.Wheel && !uiControl.ClientRectangle.Contains(uiControl.PointToClient(Control.MousePosition)))
                return;

            // the mouse events series has been interrupted because out of the window.
            if (type == InputEventType.Up && !MouseButtonCurrentlyDown[(int)button])
                return;

            CurrentMousePosition = NormalizeScreenPosition(pixelPosition);

            var mouseInputEvent = new MouseInputEvent { Type = type, MouseButton = button, Value = value};
            lock (MouseInputEvents)
                MouseInputEvents.Add(mouseInputEvent);

            if (type != InputEventType.Wheel)
            {
                var buttonId = (int)button;
                MouseButtonCurrentlyDown[buttonId] = type == InputEventType.Down;
                HandlePointerEvents(buttonId, CurrentMousePosition, InputEventTypeToPointerState(type), PointerType.Mouse);
            }
        }
 private static PointerState InputEventTypeToPointerState(InputEventType type)
 {
     switch (type)
     {
         case InputEventType.Up:
             return PointerState.Up;
         case InputEventType.Down:
             return PointerState.Down;
         default:
             throw new ArgumentOutOfRangeException("type");
     }
 }
Beispiel #38
0
 // TODO:  put DX/DY value in to show change relative to last position
 public VariableInputEvent(InputEventType eventType, VariableInputType inputType, Vector2 value)
 {
     EventType = eventType;
     InputType = inputType;
     Value = value;
 }
        private bool HandleKey(VirtualKey virtualKey, CorePhysicalKeyStatus keyStatus, InputEventType type)
        {
            // If our EditText TextBox is active, let's ignore all key events
            if (Game.Context is GameContextUWP && ((GameContextUWP)Game.Context).EditTextBox.Parent != null)
            {
                return false;
            }

            // Remap certain keys
            switch (virtualKey)
            {
                case VirtualKey.Shift:
                    // Only way to differentiate left and right shift is through the scan code
                    virtualKey = keyStatus.ScanCode == 54 ? VirtualKey.RightShift : VirtualKey.LeftShift;
                    break;
                case VirtualKey.Control:
                    virtualKey = keyStatus.IsExtendedKey ? VirtualKey.RightControl : VirtualKey.LeftControl;
                    break;
                case VirtualKey.Menu:
                    virtualKey = keyStatus.IsExtendedKey ? VirtualKey.RightMenu : VirtualKey.LeftMenu;
                    break;
            }

            // Let Alt + F4 go through
            if (virtualKey == VirtualKey.F4 && IsKeyDownNow(Keys.LeftAlt))
                return false;

            Keys key;
            if (!mapKeys.TryGetValue(virtualKey, out key))
                key = Keys.None;

            lock (KeyboardInputEvents)
            {
                KeyboardInputEvents.Add(new KeyboardInputEvent { Key = key, Type = type });
            }

            return true;
        }
Beispiel #40
0
 public GamePadButtonEvent(InputEventType type, Buttons button)
 {
     EventType = type;
     Button = button;
 }
Beispiel #41
0
 public KeyboardEvent(InputEventType type, Keys key)
 {
     EventType = type;
     Key = key;
 }