示例#1
0
 private void OnButtonDown(int button)
 {
     if (ButtonDown != null)
     {
         ButtonDown.Invoke(null, new MouseEventArgs(button));
     }
 }
示例#2
0
 private void RaiseButtonDown(Buttons button)
 {
     ButtonDown?.Invoke(this, MakeArgs(button));
     ButtonRepeated?.Invoke(this, MakeArgs(button));
     _lastButton          = button;
     _repeatedButtonTimer = 0;
 }
示例#3
0
        private void UpdateTimer(Keys key, Buttons button, float directionX, float directionY, float elapsedTime, ButtonDown downAction, ButtonUp upAction, ButtonPressed pressAction, ref float downTimer, ref float upTimer)
        {
            if (IsKeyDown(key) || currentGamePadState.IsButtonDown(button))
            {
                if (downAction != null && downTimer == 0)
                {
                    downAction.Invoke(directionX, directionY, upTimer, PlayerIndex);
                }

                downTimer += elapsedTime;
                upTimer    = 0;
            }
            else if (IsKeyUp(key) || currentGamePadState.IsButtonUp(button))
            {
                //Check if it was a press of key
                if (this.oldKeyboardState.IsKeyDown(key) || oldGamePadState.IsButtonDown(button))
                {
                    if (pressAction != null)
                    {
                        pressAction.Invoke(PlayerIndex);
                    }

                    if (upAction != null)
                    {
                        upAction.Invoke(downTimer, PlayerIndex);
                    }
                }
                upTimer  += elapsedTime;
                downTimer = 0;
            }
        }
示例#4
0
        private void mInputDevice_NoteOn(NoteOnMessage msg)
        {
            LaunchpadButton button = GetButton(msg.Pitch);

            if (button == null)
            {
                return;
            }
            button.State = (ButtonPressState)msg.Velocity;
            if (ButtonPressed == null)
            {
                return;
            }


            var pressEventArgs = (int)msg.Pitch % 16 == 8 ? new ButtonPressEventArgs((SideButton)((int)msg.Pitch / 16), button) : new ButtonPressEventArgs((int)msg.Pitch % 16, (int)msg.Pitch / 16, button);

            if (button.State == ButtonPressState.Up)
            {
                ButtonPressed?.Invoke(this, pressEventArgs);
                ButtonUp?.Invoke(this, pressEventArgs);
            }
            else
            {
                ButtonDown?.Invoke(this, pressEventArgs);
            }
        }
示例#5
0
        /// <summary>
        /// Raises the button down event.
        /// </summary>
        /// <param name="button">The button.</param>
        protected virtual void OnButtonDown(LogitechF710Button button)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(nameof(LogitechF710));
            }

            ButtonDown?.Invoke(this, new LogitechF710ButtonEventArgs(button));
        }
    void Start()
    {
        input = new InputControls();
        input.Enable();

        input.Gameplay.HitStraight.started  += ctrl => ButtonDown?.Invoke(Buttons.HitStraight);
        input.Gameplay.HitStraight.canceled += ctrl => ButtonUp?.Invoke(Buttons.HitStraight);

        input.Gameplay.HitLob.started  += ctrl => ButtonDown?.Invoke(Buttons.HitLob);
        input.Gameplay.HitLob.canceled += ctrl => ButtonUp?.Invoke(Buttons.HitLob);
    }
示例#7
0
 private void CheckButtonUpdate(MouseButtons button)
 {
     if (IsButtonPressed(button))
     {
         ButtonDown?.Invoke(new MouseEventArgs(this, Position, button));
     }
     else if (IsButtonReleased(button))
     {
         ButtonUp?.Invoke(new MouseEventArgs(this, Position, button));
     }
 }
示例#8
0
        internal void fireButtonDown(MouseButtonCode button)
        {
            int index = (int)button;

            buttonDownStatus[index] = true;
            pressedThisFrame[index] = true;

            if (ButtonDown != null)
            {
                ButtonDown.Invoke(this, button);
            }
        }
示例#9
0
 private void Button_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs args)
 {
     if (args.Edge == GpioPinEdge.FallingEdge)
     {
         pushStatus = PushStatus.DOWN;
         ValueChanged?.Invoke(this, pushStatus, args);
         ButtonDown?.Invoke(this, args);
     }
     else
     {
         pushStatus = PushStatus.UP;
         ValueChanged?.Invoke(this, pushStatus, args);
         ButtonUp?.Invoke(this, args);
     }
 }
示例#10
0
    public void Detect()
    {
        if (device.TryGetFeatureValue(button, out bool value))
        {
            if (!lastValue && value)
            {
                ButtonDown?.Invoke(this);
            }
            else if (lastValue && !value)
            {
                ButtonUp?.Invoke(this);
            }

            lastValue = value;
        }
    }
示例#11
0
        /// <summary>
        /// Handler for pressing the button.
        /// </summary>
        protected void HandleButtonPressed()
        {
            if (DateTime.UtcNow.Ticks - _debounceStartTicks < _debounceTime.Ticks)
            {
                return;
            }

            IsPressed = true;

            ButtonDown?.Invoke(this, new EventArgs());

            if (IsHoldingEnabled)
            {
                _holdingTimer = new Timer(StartHoldingHandler, null, (int)_holdingMs, Timeout.Infinite);
            }
        }
示例#12
0
        public void Tick()
        {
            if (Input.GetMouseButtonDown(MouseButtonIndex))
            {
                ButtonDown?.Invoke(ScreenToWorld(Input.mousePosition));
            }

            if (Input.GetMouseButton(MouseButtonIndex))
            {
                ButtonHold?.Invoke(ScreenToWorld(Input.mousePosition));
            }

            if (Input.GetMouseButtonUp(MouseButtonIndex))
            {
                ButtonUp?.Invoke(ScreenToWorld(Input.mousePosition));
            }
        }
示例#13
0
        public void Tick()
        {
            var touch = Input.GetTouch(TouchIndex);

            if (touch.phase == TouchPhase.Began)
            {
                ButtonDown?.Invoke(ScreenToWorld(touch.position));
            }

            if (touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Stationary)
            {
                ButtonHold?.Invoke(ScreenToWorld(touch.position));
            }

            if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled)
            {
                ButtonUp?.Invoke(ScreenToWorld(Input.mousePosition));
            }
        }
示例#14
0
        public override void OnUpdate()
        {
            var value = !pin.Value;

            if (IsPressed == value)
            {
                return;
            }
            IsPressed = value;
            if (IsPressed)
            {
                tracer.Verbose("Buton Down");
                ButtonDown?.Invoke();
            }
            else
            {
                tracer.Verbose("Buton Up");
                ButtonUp?.Invoke();
                Clicked?.Invoke();
            }
        }
示例#15
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            mode = 2;

            base.OnMouseClick(e);
            if (switchMode)
            {
                buttenDown = !buttenDown;
                if (buttenDown == true && ButtonDown != null)
                {
                    ButtonDown.Invoke(this, new EventArgs());
                }
                else if (ButtonUp != null)
                {
                    ButtonUp.Invoke(this, new EventArgs());
                }
            }

            this.Invalidate();
        }
示例#16
0
        private void mInputDevice_ControlChange(ControlChangeMessage msg)
        {
            ToolbarButton   toolbarButton = (ToolbarButton)(msg.Control - 104);
            LaunchpadButton button        = GetButton(toolbarButton);

            if (button == null)
            {
                return;
            }
            button.State = (ButtonPressState)msg.Value;

            var pressEventArgs = new ButtonPressEventArgs(toolbarButton, button);

            if (button.State == ButtonPressState.Up)
            {
                ButtonPressed?.Invoke(this, pressEventArgs);
                ButtonUp?.Invoke(this, pressEventArgs);
            }
            else
            {
                ButtonDown?.Invoke(this, pressEventArgs);
            }
        }
示例#17
0
        public void DoEvent(Event @event)
        {
            switch ((EventType)@event.Type)
            {
            case EventType.Joyaxismotion:
            {
                if (_axes.Length < @event.Jaxis.Axis + 1)
                {
                    Array.Resize(ref _axes, @event.Jaxis.Axis + 1);
                }

                AxisMoved?.Invoke
                (
                    this,
                    _axes[@event.Jaxis.Axis] = new Axis
                                                   (@event.Jaxis.Axis, (float)@event.Jaxis.Value / short.MaxValue)
                );
                break;
            }

            case EventType.Joyballmotion:
            {
                // todo investigate adding balls to the input spec later down the line
                break;
            }

            case EventType.Joyhatmotion:
            {
                if (_hats.Length < @event.Jhat.Hat + 1)
                {
                    Array.Resize(ref _hats, @event.Jhat.Hat + 1);
                }

                var val = @event.Jhat.Value;
                HatMoved?.Invoke
                (
                    this,
                    _hats[@event.Jhat.Hat] = new Hat
                                             (
                        @event.Jhat.Hat, (Position2D)((val & 0x01) * (int)Position2D.Up +
                                                      (val & 0x02) * (int)Position2D.Right +
                                                      (val & 0x04) * (int)Position2D.Down +
                                                      (val & 0x08) * (int)Position2D.Left)
                                             )
                );
                break;
            }

            case EventType.Joybuttondown:
            {
                if (_buttons.Length < @event.Jbutton.Button + 1)
                {
                    Array.Resize(ref _buttons, @event.Jbutton.Button + 1);
                }

                ButtonDown?.Invoke
                (
                    this,
                    _buttons[@event.Jbutton.Button] = new Button
                                                          ((ButtonName)@event.Jbutton.Button, @event.Jbutton.Button, true)
                );
                break;
            }

            case EventType.Joybuttonup:
            {
                if (_buttons.Length < @event.Jbutton.Button + 1)
                {
                    Array.Resize(ref _buttons, @event.Jbutton.Button + 1);
                }

                ButtonUp?.Invoke
                (
                    this,
                    _buttons[@event.Jbutton.Button] = new Button
                                                          ((ButtonName)@event.Jbutton.Button, @event.Jbutton.Button, false)
                );
                break;
            }

            case EventType.Joydeviceadded:
            {
                _ctx.ChangeConnection(this, true);
                break;
            }

            case EventType.Joydeviceremoved:
            {
                _ctx.ChangeConnection(this, false);
                break;
            }
            }
        }
示例#18
0
 // trigger callbacks
 private void OnButtonDown(int buttonNo)
 {
     ButtonDown?.Invoke(this, new DevJoystickButtonEventArgs(buttonNo));
 }
示例#19
0
文件: Button.cs 项目: Metibor/ualbion
        public Button(IUiElement content)
        {
            On <HoverEvent>(_ => { IsHovered = true; Hover?.Invoke(); });
            On <BlurEvent>(_ => { IsHovered = false; Blur?.Invoke(); });
            On <UiLeftClickEvent>(e =>
            {
                if (!IsHovered)
                {
                    return;
                }

                if (!IsClicked)
                {
                    ButtonDown?.Invoke();
                }

                IsClicked = true;
                if (Typematic)
                {
                    Click?.Invoke();
                }

                e.Propagating = false;
            });

            On <UiLeftReleaseEvent>(e =>
            {
                if (!IsClicked)
                {
                    return;
                }
                IsClicked = false;

                if (Typematic)
                {
                    _typematicAccrual = 0;
                    return;
                }

                if (!IsHovered)
                {
                    return;
                }

                if (DoubleClick == null || !AllowDoubleClick || SuppressNextDoubleClick) // Simple single click only button
                {
                    Click?.Invoke();
                    SuppressNextDoubleClick = false;
                    return;
                }

                if (ClickTimerPending) // If they double-clicked...
                {
                    DoubleClick?.Invoke();
                    ClickTimerPending = false; // Ensure the single-click behaviour doesn't happen.
                }
                else // For the first click, just start the double-click timer.
                {
                    var config = Resolve <GameConfig>();
                    Raise(new StartTimerEvent(TimerName, config.UI.ButtonDoubleClickIntervalSeconds, this));
                    ClickTimerPending = true;
                }
            });

            On <UiRightClickEvent>(e =>
            {
                e.Propagating  = false;
                IsRightClicked = true;
            });

            On <UiRightReleaseEvent>(e =>
            {
                if (IsRightClicked && IsHovered)
                {
                    RightClick?.Invoke();
                }
                IsRightClicked = false;
            });

            On <TimerElapsedEvent>(e =>
            {
                if (e.Id != TimerName)
                {
                    return;
                }

                if (!ClickTimerPending) // They've already double-clicked
                {
                    return;
                }

                Click?.Invoke();
                ClickTimerPending = false;
            });

            On <EngineUpdateEvent>(e =>
            {
                if (!Typematic || !IsClicked)
                {
                    return;
                }

                var oldAccrual     = _typematicAccrual;
                _typematicAccrual += e.DeltaSeconds;
                var rate           = 8 * (int)(2 * oldAccrual);
                var oldAmount      = (int)(oldAccrual * rate);
                var newAmount      = (int)(_typematicAccrual * rate);
                var delta          = newAmount - oldAmount;
                for (int i = 0; i < delta; i++)
                {
                    Click?.Invoke();
                }
            });

            _id    = Interlocked.Increment(ref _nextId);
            _frame = AttachChild(new ButtonFrame(content));
        }
示例#20
0
 protected virtual void OnButtonDown(object sneder, NativeMenuItemButtonEventArgs e)
 {
     ButtonDown?.Invoke(sneder, e);
 }
示例#21
0
 /// <summary>
 ///     Raises the <see cref="E:ButtonDown" /> event.
 /// </summary>
 /// <param name="e">The <see cref="LogiFrame.ButtonEventArgs" /> instance containing the event data.</param>
 protected virtual void OnButtonDown(ButtonEventArgs e)
 {
     ButtonDown?.Invoke(this, e);
 }
示例#22
0
        private void InputSource_InputAvailable(object sender, RawMouseInputEventArgs e)
        {
            // only evaluate this event if it is actually intended for this device
            // TODO: implement smarter input dispatching
            if (e.Header.hDevice != DeviceHandle)
            {
                return;
            }

            if ((e.Data.ButtonFlags & RI_MOUSE_WHEEL) == RI_MOUSE_WHEEL)
            {
                Wheel?.Invoke(this, new MouseWheelInputEventArgs(e.Data.ButtonData));
            }

            if ((e.Data.ButtonFlags & RI_MOUSE_LEFT_BUTTON_DOWN) == RI_MOUSE_LEFT_BUTTON_DOWN)
            {
                ButtonDown?.Invoke(this, new MouseButtonInputEventArgs(VirtualKeys.LeftButton));
            }

            if ((e.Data.ButtonFlags & RI_MOUSE_LEFT_BUTTON_UP) == RI_MOUSE_LEFT_BUTTON_UP)
            {
                ButtonUp?.Invoke(this, new MouseButtonInputEventArgs(VirtualKeys.LeftButton));
            }

            if ((e.Data.ButtonFlags & RI_MOUSE_RIGHT_BUTTON_DOWN) == RI_MOUSE_RIGHT_BUTTON_DOWN)
            {
                ButtonDown?.Invoke(this, new MouseButtonInputEventArgs(VirtualKeys.RightButton));
            }

            if ((e.Data.ButtonFlags & RI_MOUSE_RIGHT_BUTTON_UP) == RI_MOUSE_RIGHT_BUTTON_UP)
            {
                ButtonUp?.Invoke(this, new MouseButtonInputEventArgs(VirtualKeys.RightButton));
            }

            if ((e.Data.ButtonFlags & RI_MOUSE_MIDDLE_BUTTON_DOWN) == RI_MOUSE_MIDDLE_BUTTON_DOWN)
            {
                ButtonDown?.Invoke(this, new MouseButtonInputEventArgs(VirtualKeys.MiddleButton));
            }

            if ((e.Data.ButtonFlags & RI_MOUSE_MIDDLE_BUTTON_UP) == RI_MOUSE_MIDDLE_BUTTON_UP)
            {
                ButtonUp?.Invoke(this, new MouseButtonInputEventArgs(VirtualKeys.MiddleButton));
            }

            // wheel and XBUTTON aren't possible at the same time
            if ((e.Data.ButtonFlags & RI_MOUSE_BUTTON_4_DOWN) == RI_MOUSE_BUTTON_4_DOWN)
            {
                ButtonDown?.Invoke(this, new MouseButtonInputEventArgs(VirtualKeys.ExtraButton1));
            }

            if ((e.Data.ButtonFlags & RI_MOUSE_BUTTON_4_UP) == RI_MOUSE_BUTTON_4_UP)
            {
                ButtonUp?.Invoke(this, new MouseButtonInputEventArgs(VirtualKeys.ExtraButton1));
            }

            if ((e.Data.ButtonFlags & RI_MOUSE_BUTTON_5_DOWN) == RI_MOUSE_BUTTON_5_DOWN)
            {
                ButtonDown?.Invoke(this, new MouseButtonInputEventArgs(VirtualKeys.ExtraButton2));
            }

            if ((e.Data.ButtonFlags & RI_MOUSE_BUTTON_5_UP) == RI_MOUSE_BUTTON_5_UP)
            {
                ButtonUp?.Invoke(this, new MouseButtonInputEventArgs(VirtualKeys.ExtraButton2));
            }

            if (e.Data.LastX != LastX || e.Data.LastY != LastY)
            {
                Move?.Invoke(this, new MouseMoveInputEventArgs(e.Data.LastX, e.Data.LastY));
            }

            LastX = e.Data.LastX;
            LastY = e.Data.LastY;
        }
示例#23
0
 protected void RaiseButtonDown(MidiMessageType type, byte midiId) => ButtonDown?.Invoke(type, midiId);
 private void InvokeButtonDown(ButtonFlags button)
 {
     ButtonDown?.Invoke(this, new ControllerButtonDownEventArgs(button));
 }
示例#25
0
        public VisualInventorySlot(InventorySlotId slotId, IText amountSource, Func <IReadOnlyItemSlot> getSlot)
        {
            On <IdleClockEvent>(e => _frameNumber++);

            _slotId  = slotId;
            _getSlot = getSlot;
            _overlay = new UiSpriteElement(Base.CoreSprite.UiBroken)
            {
                IsActive = false
            };
            var text = new UiText(amountSource);

            if (!slotId.Slot.IsSpecial())
            {
                _size = slotId.Slot.IsBodyPart() ?
                        new Vector2(18, 18) : //16x16 surrounded by 1px borders
                        new Vector2(16, 20);
                _sprite = new UiSpriteElement(SpriteId.None);
                _button = AttachChild(new Button(new FixedPositionStack()
                                                 .Add(
                                                     new LayerStack(
                                                         _sprite,
                                                         _overlay),
                                                     1, 1, 16, 16) //16x16 surrounded by 1px borders
                                                 .Add(text, 0, 20 - 9, 16, 9))
                {
                    Padding = -1,
                    Margin  = 0,
                    Theme   = slotId.Slot.IsBodyPart()
                                ? (ButtonFrame.ThemeFunction)ButtonTheme.Default
                                : ButtonTheme.InventorySlot,

                    IsPressed = !slotId.Slot.IsBodyPart()
                }
                                      .OnHover(() => Hover?.Invoke())
                                      .OnBlur(() => Blur?.Invoke())
                                      .OnClick(() => Click?.Invoke())
                                      .OnRightClick(() => RightClick?.Invoke())
                                      .OnDoubleClick(() => DoubleClick?.Invoke())
                                      .OnButtonDown(() => ButtonDown?.Invoke()));
            }
            else
            {
                _sprite = new UiSpriteElement(
                    slotId.Slot == ItemSlotId.Gold
                        ? Base.CoreSprite.UiGold
                        : Base.CoreSprite.UiFood);

                _button = AttachChild(new Button(
                                          new VerticalStack(
                                              new Spacing(31, 0),
                                              _sprite,
                                              new UiText(amountSource)
                                              )
                {
                    Greedy = false
                })
                                      .OnHover(() => Hover?.Invoke())
                                      .OnBlur(() => Blur?.Invoke())
                                      .OnClick(() => Click?.Invoke())
                                      .OnRightClick(() => RightClick?.Invoke())
                                      .OnDoubleClick(() => DoubleClick?.Invoke())
                                      .OnButtonDown(() => ButtonDown?.Invoke()));
            }
        }
示例#26
0
        public void Update()
        {
            _controllers.NumControllers = 0;
            if (!_controllers.Supported)
            {
                return;
            }

            for (int i = 0; i < _controllers.controllers.Length; i++)
            {
                if (!_controllers.controllers[i].IsConnected)
                {
                    _controllers.states[i] = default(Gamepad);
                    continue;
                }

                _controllers.NumControllers++;

                State s = _controllers.controllers[i].GetState();
                if (s.PacketNumber == _controllers.stateNumbers[i])
                {
                    continue;
                }
                _controllers.stateNumbers[i] = s.PacketNumber;

                Gamepad tempState = s.Gamepad;

                if ((tempState.Buttons & GamepadButtonFlags.A) != GamepadButtonFlags.None && (_controllers.states[i].Buttons & GamepadButtonFlags.A) == GamepadButtonFlags.None)
                {
                    _controllers.CurrentlyUsingController = true;
                    ButtonDown?.Invoke(_focusedWindow, new ButtonEventArgs(XboxButtonCode.A));
                }
                else if ((tempState.Buttons & GamepadButtonFlags.A) == GamepadButtonFlags.None && (_controllers.states[i].Buttons & GamepadButtonFlags.A) != GamepadButtonFlags.None)
                {
                    _controllers.CurrentlyUsingController = true;
                    ButtonUp?.Invoke(_focusedWindow, new ButtonEventArgs(XboxButtonCode.A));
                }
                if ((tempState.Buttons & GamepadButtonFlags.B) != GamepadButtonFlags.None && (_controllers.states[i].Buttons & GamepadButtonFlags.B) == GamepadButtonFlags.None)
                {
                    _controllers.CurrentlyUsingController = true;
                    ButtonDown?.Invoke(_focusedWindow, new ButtonEventArgs(XboxButtonCode.B));
                }
                else if ((tempState.Buttons & GamepadButtonFlags.B) == GamepadButtonFlags.None && (_controllers.states[i].Buttons & GamepadButtonFlags.B) != GamepadButtonFlags.None)
                {
                    _controllers.CurrentlyUsingController = true;
                    ButtonUp?.Invoke(_focusedWindow, new ButtonEventArgs(XboxButtonCode.B));
                }
                if ((tempState.Buttons & GamepadButtonFlags.Y) != GamepadButtonFlags.None && (_controllers.states[i].Buttons & GamepadButtonFlags.Y) == GamepadButtonFlags.None)
                {
                    _controllers.CurrentlyUsingController = true;
                    ButtonDown?.Invoke(_focusedWindow, new ButtonEventArgs(XboxButtonCode.Y));
                }
                else if ((tempState.Buttons & GamepadButtonFlags.Y) == GamepadButtonFlags.None && (_controllers.states[i].Buttons & GamepadButtonFlags.Y) != GamepadButtonFlags.None)
                {
                    _controllers.CurrentlyUsingController = true;
                    ButtonUp?.Invoke(_focusedWindow, new ButtonEventArgs(XboxButtonCode.Y));
                }
                if ((tempState.Buttons & GamepadButtonFlags.X) != GamepadButtonFlags.None && (_controllers.states[i].Buttons & GamepadButtonFlags.X) == GamepadButtonFlags.None)
                {
                    _controllers.CurrentlyUsingController = true;
                    ButtonDown?.Invoke(_focusedWindow, new ButtonEventArgs(XboxButtonCode.X));
                }
                else if ((tempState.Buttons & GamepadButtonFlags.X) == GamepadButtonFlags.None && (_controllers.states[i].Buttons & GamepadButtonFlags.X) != GamepadButtonFlags.None)
                {
                    _controllers.CurrentlyUsingController = true;
                    ButtonUp?.Invoke(_focusedWindow, new ButtonEventArgs(XboxButtonCode.X));
                }

                if ((tempState.Buttons & GamepadButtonFlags.LeftShoulder) != GamepadButtonFlags.None && (_controllers.states[i].Buttons & GamepadButtonFlags.LeftShoulder) == GamepadButtonFlags.None)
                {
                    _controllers.CurrentlyUsingController = true;
                    ButtonDown?.Invoke(_focusedWindow, new ButtonEventArgs(XboxButtonCode.LeftBumper));
                }
                else if ((tempState.Buttons & GamepadButtonFlags.LeftShoulder) == GamepadButtonFlags.None && (_controllers.states[i].Buttons & GamepadButtonFlags.LeftShoulder) != GamepadButtonFlags.None)
                {
                    _controllers.CurrentlyUsingController = true;
                    ButtonUp?.Invoke(_focusedWindow, new ButtonEventArgs(XboxButtonCode.LeftBumper));
                }
                if ((tempState.Buttons & GamepadButtonFlags.RightShoulder) != GamepadButtonFlags.None && (_controllers.states[i].Buttons & GamepadButtonFlags.RightShoulder) == GamepadButtonFlags.None)
                {
                    _controllers.CurrentlyUsingController = true;
                    ButtonDown?.Invoke(_focusedWindow, new ButtonEventArgs(XboxButtonCode.RightBumper));
                }
                else if ((tempState.Buttons & GamepadButtonFlags.RightShoulder) == GamepadButtonFlags.None && (_controllers.states[i].Buttons & GamepadButtonFlags.RightShoulder) != GamepadButtonFlags.None)
                {
                    _controllers.CurrentlyUsingController = true;
                    ButtonUp?.Invoke(_focusedWindow, new ButtonEventArgs(XboxButtonCode.RightBumper));
                }

                if ((tempState.Buttons & GamepadButtonFlags.LeftThumb) != GamepadButtonFlags.None && (_controllers.states[i].Buttons & GamepadButtonFlags.LeftThumb) == GamepadButtonFlags.None)
                {
                    _controllers.CurrentlyUsingController = true;
                    ButtonDown?.Invoke(this, new ButtonEventArgs(XboxButtonCode.LeftStick));
                }
                else if ((tempState.Buttons & GamepadButtonFlags.LeftThumb) == GamepadButtonFlags.None && (_controllers.states[i].Buttons & GamepadButtonFlags.LeftThumb) != GamepadButtonFlags.None)
                {
                    _controllers.CurrentlyUsingController = true;
                    ButtonUp?.Invoke(_focusedWindow, new ButtonEventArgs(XboxButtonCode.LeftStick));
                }
                if ((tempState.Buttons & GamepadButtonFlags.RightThumb) != GamepadButtonFlags.None && (_controllers.states[i].Buttons & GamepadButtonFlags.RightThumb) == GamepadButtonFlags.None)
                {
                    _controllers.CurrentlyUsingController = true;
                    ButtonDown?.Invoke(_focusedWindow, new ButtonEventArgs(XboxButtonCode.RightStick));
                }
                else if ((tempState.Buttons & GamepadButtonFlags.RightThumb) == GamepadButtonFlags.None && (_controllers.states[i].Buttons & GamepadButtonFlags.RightThumb) != GamepadButtonFlags.None)
                {
                    _controllers.CurrentlyUsingController = true;
                    ButtonUp?.Invoke(_focusedWindow, new ButtonEventArgs(XboxButtonCode.RightStick));
                }

                if ((tempState.Buttons & GamepadButtonFlags.Start) != GamepadButtonFlags.None && (_controllers.states[i].Buttons & GamepadButtonFlags.Start) == GamepadButtonFlags.None)
                {
                    _controllers.CurrentlyUsingController = true;
                    ButtonDown?.Invoke(_focusedWindow, new ButtonEventArgs(XboxButtonCode.Start));
                }
                else if ((tempState.Buttons & GamepadButtonFlags.Start) == GamepadButtonFlags.None && (_controllers.states[i].Buttons & GamepadButtonFlags.Start) != GamepadButtonFlags.None)
                {
                    _controllers.CurrentlyUsingController = true;
                    ButtonUp?.Invoke(_focusedWindow, new ButtonEventArgs(XboxButtonCode.Start));
                }
                if ((tempState.Buttons & GamepadButtonFlags.Back) != GamepadButtonFlags.None && (_controllers.states[i].Buttons & GamepadButtonFlags.Back) == GamepadButtonFlags.None)
                {
                    _controllers.CurrentlyUsingController = true;
                    ButtonDown?.Invoke(_focusedWindow, new ButtonEventArgs(XboxButtonCode.Back));
                }
                else if ((tempState.Buttons & GamepadButtonFlags.Back) == GamepadButtonFlags.None && (_controllers.states[i].Buttons & GamepadButtonFlags.Back) != GamepadButtonFlags.None)
                {
                    _controllers.CurrentlyUsingController = true;
                    ButtonUp?.Invoke(_focusedWindow, new ButtonEventArgs(XboxButtonCode.Back));
                }

                if ((tempState.Buttons & GamepadButtonFlags.DPadUp) != GamepadButtonFlags.None && (_controllers.states[i].Buttons & GamepadButtonFlags.DPadUp) == GamepadButtonFlags.None)
                {
                    _controllers.CurrentlyUsingController = true;
                    ButtonDown?.Invoke(_focusedWindow, new ButtonEventArgs(XboxButtonCode.Up));
                }
                else if ((tempState.Buttons & GamepadButtonFlags.DPadUp) == GamepadButtonFlags.None && (_controllers.states[i].Buttons & GamepadButtonFlags.DPadUp) != GamepadButtonFlags.None)
                {
                    _controllers.CurrentlyUsingController = true;
                    ButtonUp?.Invoke(_focusedWindow, new ButtonEventArgs(XboxButtonCode.Up));
                }
                if ((tempState.Buttons & GamepadButtonFlags.DPadDown) != GamepadButtonFlags.None && (_controllers.states[i].Buttons & GamepadButtonFlags.DPadDown) == GamepadButtonFlags.None)
                {
                    _controllers.CurrentlyUsingController = true;
                    ButtonDown?.Invoke(_focusedWindow, new ButtonEventArgs(XboxButtonCode.Down));
                }
                else if ((tempState.Buttons & GamepadButtonFlags.DPadDown) == GamepadButtonFlags.None && (_controllers.states[i].Buttons & GamepadButtonFlags.DPadDown) != GamepadButtonFlags.None)
                {
                    _controllers.CurrentlyUsingController = true;
                    ButtonUp?.Invoke(_focusedWindow, new ButtonEventArgs(XboxButtonCode.Down));
                }
                if ((tempState.Buttons & GamepadButtonFlags.DPadLeft) != GamepadButtonFlags.None && (_controllers.states[i].Buttons & GamepadButtonFlags.DPadLeft) == GamepadButtonFlags.None)
                {
                    _controllers.CurrentlyUsingController = true;
                    ButtonDown?.Invoke(_focusedWindow, new ButtonEventArgs(XboxButtonCode.Left));
                }
                else if ((tempState.Buttons & GamepadButtonFlags.DPadLeft) == GamepadButtonFlags.None && (_controllers.states[i].Buttons & GamepadButtonFlags.DPadLeft) != GamepadButtonFlags.None)
                {
                    _controllers.CurrentlyUsingController = true;
                    ButtonUp?.Invoke(_focusedWindow, new ButtonEventArgs(XboxButtonCode.Left));
                }
                if ((tempState.Buttons & GamepadButtonFlags.DPadRight) != GamepadButtonFlags.None && (_controllers.states[i].Buttons & GamepadButtonFlags.DPadRight) == GamepadButtonFlags.None)
                {
                    _controllers.CurrentlyUsingController = true;
                    ButtonDown?.Invoke(_focusedWindow, new ButtonEventArgs(XboxButtonCode.Right));
                }
                else if ((tempState.Buttons & GamepadButtonFlags.DPadRight) == GamepadButtonFlags.None && (_controllers.states[i].Buttons & GamepadButtonFlags.DPadRight) != GamepadButtonFlags.None)
                {
                    _controllers.CurrentlyUsingController = true;
                    ButtonUp?.Invoke(_focusedWindow, new ButtonEventArgs(XboxButtonCode.Right));
                }

                short dzPos = (short)(_controllers.StickDeadZone * 32767.0d);
                short dzNeg = (short)(_controllers.StickDeadZone * -32768.0d);

                if (tempState.LeftThumbY >= dzPos && tempState.LeftThumbX < maxAnglePos && tempState.LeftThumbX > maxAngleNeg)
                {
                    _controllers.CurrentlyUsingController = true;
                    StickMoved?.Invoke(_focusedWindow, new StickEventArgs(XboxStickCode.LeftN, new PrecisePoint((tempState.LeftThumbX < 0) ? tempState.LeftThumbX / 32768.0d : tempState.LeftThumbX / 32767.0d, (tempState.LeftThumbY < 0) ? tempState.LeftThumbY / 32768.0d : tempState.LeftThumbY / 32767.0d)));
                }
                else if (tempState.LeftThumbX >= dzPos && tempState.LeftThumbY < maxAnglePos && tempState.LeftThumbY > maxAngleNeg)
                {
                    _controllers.CurrentlyUsingController = true;
                    StickMoved?.Invoke(_focusedWindow, new StickEventArgs(XboxStickCode.LeftE, new PrecisePoint((tempState.LeftThumbX < 0) ? tempState.LeftThumbX / 32768.0d : tempState.LeftThumbX / 32767.0d, (tempState.LeftThumbY < 0) ? tempState.LeftThumbY / 32768.0d : tempState.LeftThumbY / 32767.0d)));
                }
                else if (tempState.LeftThumbY <= dzNeg && tempState.LeftThumbX < maxAnglePos && tempState.LeftThumbX > maxAngleNeg)
                {
                    _controllers.CurrentlyUsingController = true;
                    StickMoved?.Invoke(_focusedWindow, new StickEventArgs(XboxStickCode.LeftS, new PrecisePoint((tempState.LeftThumbX < 0) ? tempState.LeftThumbX / 32768.0d : tempState.LeftThumbX / 32767.0d, (tempState.LeftThumbY < 0) ? tempState.LeftThumbY / 32768.0d : tempState.LeftThumbY / 32767.0d)));
                }
                else if (tempState.LeftThumbX <= dzNeg && tempState.LeftThumbY < maxAnglePos && tempState.LeftThumbY > maxAngleNeg)
                {
                    _controllers.CurrentlyUsingController = true;
                    StickMoved?.Invoke(_focusedWindow, new StickEventArgs(XboxStickCode.LeftW, new PrecisePoint((tempState.LeftThumbX < 0) ? tempState.LeftThumbX / 32768.0d : tempState.LeftThumbX / 32767.0d, (tempState.LeftThumbY < 0) ? tempState.LeftThumbY / 32768.0d : tempState.LeftThumbY / 32767.0d)));
                }
                else if (tempState.LeftThumbY >= dzPos && tempState.LeftThumbX >= maxAnglePos)
                {
                    _controllers.CurrentlyUsingController = true;
                    StickMoved?.Invoke(_focusedWindow, new StickEventArgs(XboxStickCode.LeftNE, new PrecisePoint((tempState.LeftThumbX < 0) ? tempState.LeftThumbX / 32768.0d : tempState.LeftThumbX / 32767.0d, (tempState.LeftThumbY < 0) ? tempState.LeftThumbY / 32768.0d : tempState.LeftThumbY / 32767.0d)));
                }
                else if (tempState.LeftThumbY >= dzPos && tempState.LeftThumbX <= maxAngleNeg)
                {
                    _controllers.CurrentlyUsingController = true;
                    StickMoved?.Invoke(_focusedWindow, new StickEventArgs(XboxStickCode.LeftNW, new PrecisePoint((tempState.LeftThumbX < 0) ? tempState.LeftThumbX / 32768.0d : tempState.LeftThumbX / 32767.0d, (tempState.LeftThumbY < 0) ? tempState.LeftThumbY / 32768.0d : tempState.LeftThumbY / 32767.0d)));
                }
                else if (tempState.LeftThumbY <= dzNeg && tempState.LeftThumbX >= maxAnglePos)
                {
                    _controllers.CurrentlyUsingController = true;
                    StickMoved?.Invoke(_focusedWindow, new StickEventArgs(XboxStickCode.LeftSE, new PrecisePoint((tempState.LeftThumbX < 0) ? tempState.LeftThumbX / 32768.0d : tempState.LeftThumbX / 32767.0d, (tempState.LeftThumbY < 0) ? tempState.LeftThumbY / 32768.0d : tempState.LeftThumbY / 32767.0d)));
                }
                else if (tempState.LeftThumbY <= dzNeg && tempState.LeftThumbX <= maxAngleNeg)
                {
                    _controllers.CurrentlyUsingController = true;
                    StickMoved?.Invoke(_focusedWindow, new StickEventArgs(XboxStickCode.LeftSW, new PrecisePoint((tempState.LeftThumbX < 0) ? tempState.LeftThumbX / 32768.0d : tempState.LeftThumbX / 32767.0d, (tempState.LeftThumbY < 0) ? tempState.LeftThumbY / 32768.0d : tempState.LeftThumbY / 32767.0d)));
                }
                if (tempState.RightThumbY >= dzPos && tempState.RightThumbX < maxAnglePos && tempState.RightThumbX > maxAngleNeg)
                {
                    _controllers.CurrentlyUsingController = true;
                    StickMoved?.Invoke(_focusedWindow, new StickEventArgs(XboxStickCode.RightN, new PrecisePoint((tempState.RightThumbX < 0) ? tempState.RightThumbX / 32768.0d : tempState.RightThumbX / 32767.0d, (tempState.RightThumbY < 0) ? tempState.RightThumbY / 32768.0d : tempState.RightThumbY / 32767.0d)));
                }
                else if (tempState.RightThumbX >= dzPos && tempState.RightThumbY < maxAnglePos && tempState.RightThumbY > maxAngleNeg)
                {
                    _controllers.CurrentlyUsingController = true;
                    StickMoved?.Invoke(_focusedWindow, new StickEventArgs(XboxStickCode.RightE, new PrecisePoint((tempState.RightThumbX < 0) ? tempState.RightThumbX / 32768.0d : tempState.RightThumbX / 32767.0d, (tempState.RightThumbY < 0) ? tempState.RightThumbY / 32768.0d : tempState.RightThumbY / 32767.0d)));
                }
                else if (tempState.RightThumbY <= dzNeg && tempState.RightThumbX < maxAnglePos && tempState.RightThumbX > maxAngleNeg)
                {
                    _controllers.CurrentlyUsingController = true;
                    StickMoved?.Invoke(_focusedWindow, new StickEventArgs(XboxStickCode.RightS, new PrecisePoint((tempState.RightThumbX < 0) ? tempState.RightThumbX / 32768.0d : tempState.RightThumbX / 32767.0d, (tempState.RightThumbY < 0) ? tempState.RightThumbY / 32768.0d : tempState.RightThumbY / 32767.0d)));
                }
                else if (tempState.RightThumbX <= dzNeg && tempState.RightThumbY < maxAnglePos && tempState.RightThumbY > maxAngleNeg)
                {
                    _controllers.CurrentlyUsingController = true;
                    StickMoved?.Invoke(_focusedWindow, new StickEventArgs(XboxStickCode.RightW, new PrecisePoint((tempState.RightThumbX < 0) ? tempState.RightThumbX / 32768.0d : tempState.RightThumbX / 32767.0d, (tempState.RightThumbY < 0) ? tempState.RightThumbY / 32768.0d : tempState.RightThumbY / 32767.0d)));
                }
                else if (tempState.RightThumbY >= dzPos && tempState.RightThumbX >= maxAnglePos)
                {
                    _controllers.CurrentlyUsingController = true;
                    StickMoved?.Invoke(_focusedWindow, new StickEventArgs(XboxStickCode.RightNE, new PrecisePoint((tempState.RightThumbX < 0) ? tempState.RightThumbX / 32768.0d : tempState.RightThumbX / 32767.0d, (tempState.RightThumbY < 0) ? tempState.RightThumbY / 32768.0d : tempState.RightThumbY / 32767.0d)));
                }
                else if (tempState.RightThumbY >= dzPos && tempState.RightThumbX <= maxAngleNeg)
                {
                    _controllers.CurrentlyUsingController = true;
                    StickMoved?.Invoke(_focusedWindow, new StickEventArgs(XboxStickCode.RightNW, new PrecisePoint((tempState.RightThumbX < 0) ? tempState.RightThumbX / 32768.0d : tempState.RightThumbX / 32767.0d, (tempState.RightThumbY < 0) ? tempState.RightThumbY / 32768.0d : tempState.RightThumbY / 32767.0d)));
                }
                else if (tempState.RightThumbY <= dzNeg && tempState.RightThumbX >= maxAnglePos)
                {
                    _controllers.CurrentlyUsingController = true;
                    StickMoved?.Invoke(_focusedWindow, new StickEventArgs(XboxStickCode.RightSE, new PrecisePoint((tempState.RightThumbX < 0) ? tempState.RightThumbX / 32768.0d : tempState.RightThumbX / 32767.0d, (tempState.RightThumbY < 0) ? tempState.RightThumbY / 32768.0d : tempState.RightThumbY / 32767.0d)));
                }
                else if (tempState.RightThumbY <= dzNeg && tempState.RightThumbX <= maxAngleNeg)
                {
                    _controllers.CurrentlyUsingController = true;
                    StickMoved?.Invoke(_focusedWindow, new StickEventArgs(XboxStickCode.RightSW, new PrecisePoint((tempState.RightThumbX < 0) ? tempState.RightThumbX / 32768.0d : tempState.RightThumbX / 32767.0d, (tempState.RightThumbY < 0) ? tempState.RightThumbY / 32768.0d : tempState.RightThumbY / 32767.0d)));
                }

                byte dzTrig = (byte)(_controllers.TriggerDeadZone * 255.0d);

                if (tempState.LeftTrigger >= dzTrig)
                {
                    _controllers.CurrentlyUsingController = true;
                    TriggerPressed?.Invoke(_focusedWindow, new TriggerEventArgs(XboxTriggerCode.Left, tempState.LeftTrigger / 255.0d));
                }
                if (tempState.RightTrigger >= dzTrig)
                {
                    _controllers.CurrentlyUsingController = true;
                    TriggerPressed?.Invoke(_focusedWindow, new TriggerEventArgs(XboxTriggerCode.Right, tempState.RightTrigger / 255.0d));
                }

                _controllers.states[i] = tempState;
            }
        }
示例#27
0
文件: Joystick.cs 项目: moose3/iRTVO
        private void OrderData()
        {
            //Buttons
            byte[] bButtons = state.GetButtons();
            Dictionary <Int32, Boolean> LButtons = new Dictionary <int, bool>();

            for (Int32 i = 0; i < Buttons; i++)
            {
                if (bButtons[i] >= 128)
                {
                    LButtons.Add(i, true);
                }
                else
                {
                    LButtons.Add(i, false);
                }
            }



            if (ButtonList != null && (ButtonUp != null || ButtonDown != null))
            {
                foreach (KeyValuePair <Int32, Boolean> B in LButtons)
                {
                    if (B.Value != ButtonList[B.Key])
                    {
                        if (B.Value == true)
                        {
                            if (ButtonDown != null)
                            {
                                ButtonDown.Invoke(B.Key, this);
                            }
                        }
                        else
                        {
                            if (ButtonUp != null)
                            {
                                ButtonUp.Invoke(B.Key, this);
                            }
                        }
                    }
                }
            }

            ButtonList = LButtons;

            //Axis
            X  = state.X;
            Y  = state.Y;
            Z  = state.Z;
            Rz = state.Rz;

            if (AxeChanged != null)
            {
                AxeChanged.Invoke(X, Y, Z, Rz, this);
            }

            //Shift
            try
            {
                Int32 P = state.GetSlider()[0];
                if (PushChange != null && P != Push)
                {
                    PushChange.Invoke(P, this);
                }
                Push = P;
            }
            catch { }

            //Get Data
            if (GetData != null)
            {
                GetData.Invoke(this);
            }
        }
示例#28
0
 void _guiFuseeLink_OnGUIButtonDown(GUIButton sender, GUIButtonEventArgs mea)
 {
     ButtonDown?.Invoke(this, null);
 }
示例#29
0
        private void UpdateTimer(Keys key, Buttons button, float directionX, float directionY, float elapsedTime, ButtonDown downAction, ButtonUp upAction, ButtonPressed pressAction, ref float downTimer, ref float upTimer)
        {
            if (IsKeyDown(key) || currentGamePadState.IsButtonDown(button))
            {
                if(downAction != null && downTimer == 0)
                    downAction.Invoke(directionX, directionY, upTimer, PlayerIndex);

                downTimer += elapsedTime;
                upTimer = 0;
            }
            else if (IsKeyUp(key) || currentGamePadState.IsButtonUp(button))
            {
                //Check if it was a press of key
                if(this.oldKeyboardState.IsKeyDown(key) || oldGamePadState.IsButtonDown(button)){
                    if (pressAction != null)
                        pressAction.Invoke(PlayerIndex);

                    if (upAction != null)
                        upAction.Invoke(downTimer, PlayerIndex);
                }
                upTimer += elapsedTime;
                downTimer = 0;
            }
        }
示例#30
0
        public void DoEvent(Event @event)
        {
            switch ((EventType)@event.Type)
            {
            case EventType.Controlleraxismotion:
            {
                switch ((GameControllerAxis)@event.Caxis.Axis)
                {
                case GameControllerAxis.ControllerAxisLeftx:
                {
                    _thumbsticksChanged[0] = true;
                    _thumbsticks[0]        = new Thumbstick
                                                 (0, (float)@event.Caxis.Value / short.MaxValue, _thumbsticks[0].Y);
                    break;
                }

                case GameControllerAxis.ControllerAxisLefty:
                {
                    _thumbsticksChanged[0] = true;
                    _thumbsticks[0]        = new Thumbstick
                                                 (0, _thumbsticks[0].X, (float)@event.Caxis.Value / short.MaxValue);
                    break;
                }

                case GameControllerAxis.ControllerAxisRightx:
                {
                    _thumbsticksChanged[1] = true;
                    _thumbsticks[1]        = new Thumbstick
                                                 (1, (float)@event.Caxis.Value / short.MaxValue, _thumbsticks[1].Y);
                    break;
                }

                case GameControllerAxis.ControllerAxisRighty:
                {
                    _thumbsticksChanged[1] = true;
                    _thumbsticks[1]        = new Thumbstick
                                                 (1, _thumbsticks[1].X, (float)@event.Caxis.Value / short.MaxValue);
                    break;
                }

                case GameControllerAxis.ControllerAxisTriggerleft:
                {
                    TriggerMoved?.Invoke
                        (this, _triggers[0] = new Trigger(0, (float)@event.Caxis.Value / short.MaxValue));
                    break;
                }

                case GameControllerAxis.ControllerAxisTriggerright:
                {
                    TriggerMoved?.Invoke
                        (this, _triggers[1] = new Trigger(1, (float)@event.Caxis.Value / short.MaxValue));
                    break;
                }
                }

                break;
            }

            case EventType.Controllerbuttondown:
            {
                var ogBtn = _buttons[@event.Cbutton.Button];
                ButtonDown?.Invoke
                    (this, _buttons[@event.Cbutton.Button] = new Button(ogBtn.Name, ogBtn.Index, true));
                break;
            }

            case EventType.Controllerbuttonup:
            {
                var ogBtn = _buttons[@event.Cbutton.Button];
                ButtonUp?.Invoke
                    (this, _buttons[@event.Cbutton.Button] = new Button(ogBtn.Name, ogBtn.Index, false));
                break;
            }

            case EventType.Controllerdeviceadded:
            {
                _ctx.ChangeConnection(this, true);
                break;
            }

            case EventType.Controllerdeviceremoved:
            {
                _ctx.ChangeConnection(this, false);
                break;
            }
            }

            for (var i = 0; i < _thumbsticksChanged.Length; i++)
            {
                if (_thumbsticksChanged[i])
                {
                    ThumbstickMoved?.Invoke(this, _thumbsticks[i]);
                    _thumbsticksChanged[i] = false;
                }
            }
        }
 protected override void OnButtonDown(XTouchMiniMcButton button)
 {
     base.OnButtonDown(button);
     ButtonDown?.Invoke(this, new DeviceButtonEventArgs(_buttons[button.MidiCode]));
 }