void GrabUpdate(CustomHand hand) { if ((rightHand || leftHand) && GetMyGrabPoserTransform(hand)) { hand.SkeletonUpdate(); GetComponentInChildren <MeshRenderer>().material.color = Color.grey; float tempDistance = Mathf.Clamp(StartButtonPosition - (StartButtonPosition - transform.InverseTransformPoint(hand.PivotPoser.position).z) * DistanceMultiply, StartButtonPosition, distanseToPress); if (tempDistance >= distanseToPress) { GetComponentInChildren <MeshRenderer>().material.color = Color.blue; if (!press) { ButtonDown.Invoke(); } press = true; ButtonUpdate.Invoke(); } else { if (press) { ButtonUp.Invoke(); } press = false; } MoveObject.localPosition = new Vector3(0, 0, tempDistance); MoveObject.rotation = Quaternion.LookRotation(GetMyGrabPoserTransform(hand).forward, hand.PivotPoser.up); hand.GrabUpdateCustom(); } }
private void OnButtonUp(int button) { if (ButtonUp != null) { ButtonUp.Invoke(null, new MouseEventArgs(button)); } }
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; } }
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); } }
/// <summary> /// Raises the button up event. /// </summary> /// <param name="button">The button.</param> protected virtual void OnButtonUp(LogitechF710Button button) { if (_disposed) { throw new ObjectDisposedException(nameof(LogitechF710)); } ButtonUp?.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); }
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)); } }
public void ResetButton() { if (switchMode && buttenDown == true) { if (ButtonUp != null) { ButtonUp.Invoke(this, new EventArgs()); } buttenDown = false; this.Invalidate(); } }
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); } }
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; } }
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)); } }
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)); } }
internal void fireButtonUp(MouseButtonCode button) { int index = (int)button; //Make sure the button is down if (buttonDownStatus[index]) { buttonDownStatus[index] = false; if (pressedThisFrame[index]) { downAndUpThisFrame[index] = true; } if (ButtonUp != null) { ButtonUp.Invoke(this, button); } } }
/// <summary> /// Handler for releasing the button. /// </summary> protected void HandleButtonReleased() { if (_debounceTime.Ticks > 0 && !IsPressed) { return; } _debounceStartTicks = DateTime.UtcNow.Ticks; _holdingTimer?.Dispose(); _holdingTimer = null; IsPressed = false; ButtonUp?.Invoke(this, new EventArgs()); Press?.Invoke(this, new EventArgs()); if (IsHoldingEnabled && _holdingState == ButtonHoldingState.Started) { _holdingState = ButtonHoldingState.Completed; Holding?.Invoke(this, new ButtonHoldingEventArgs { HoldingState = ButtonHoldingState.Completed }); } if (IsDoublePressEnabled) { if (_lastPress == DateTime.MinValue.Ticks) { _lastPress = DateTime.UtcNow.Ticks; } else { if (DateTime.UtcNow.Ticks - _lastPress <= _doublePressTicks) { DoublePress?.Invoke(this, new EventArgs()); } _lastPress = DateTime.MinValue.Ticks; } } }
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(); }
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(); } }
/// <inheritdoc /> public void Update(TimeSpan total, TimeSpan elapsed, bool isRunningSlowly) { if (!IsWithinGameWindow(core.Location.X, core.Location.Y)) { return; } lastLocation = core.Location; PreUpdate?.Invoke(this, new UpdateEventArgs(total, elapsed, isRunningSlowly)); if (Left == MouseButtonState.Released && leftPrevious == MouseButtonState.Pressed) { ButtonUp?.Invoke(this, new MouseButtonClickEventArgs(X, Y, MouseButton.Left)); } else if (Middle == MouseButtonState.Released && middlePrevious == MouseButtonState.Pressed) { ButtonUp?.Invoke(this, new MouseButtonClickEventArgs(X, Y, MouseButton.Middle)); } else if (Right == MouseButtonState.Released && rightPrevious == MouseButtonState.Pressed) { ButtonUp?.Invoke(this, new MouseButtonClickEventArgs(X, Y, MouseButton.Right)); } else if (X1 == MouseButtonState.Released && x1Previous == MouseButtonState.Pressed) { ButtonUp?.Invoke(this, new MouseButtonClickEventArgs(X, Y, MouseButton.X1)); } else if (X2 == MouseButtonState.Released && x2Previous == MouseButtonState.Pressed) { ButtonUp?.Invoke(this, new MouseButtonClickEventArgs(X, Y, MouseButton.X2)); } leftPrevious = Left; middlePrevious = Middle; rightPrevious = Right; x1Previous = X1; x2Previous = X2; PostUpdate?.Invoke(this, new UpdateEventArgs(total, elapsed, isRunningSlowly)); }
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); } }
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; } } }
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; }
private void OnButtonUp(int buttonNo) { ButtonUp?.Invoke(this, new DevJoystickButtonEventArgs(buttonNo)); }
protected virtual void OnButtonUp(object sneder, NativeMenuItemButtonEventArgs e) { ButtonUp?.Invoke(sneder, e); }
protected void RaiseButtonUp(MidiMessageType type, byte midiId) => ButtonUp?.Invoke(type, midiId);
protected override void OnButtonUp(XTouchMiniMcButton button) { base.OnButtonUp(button); ButtonUp?.Invoke(this, new DeviceButtonEventArgs(_buttons[button.MidiCode])); }
private void RaiseButtonUp(Buttons button) { ButtonUp?.Invoke(this, MakeArgs(button)); _lastButton = 0; }
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); } }
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; } }
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; } } }
/// <summary> /// Raises the <see cref="E:ButtonUp" /> event. /// </summary> /// <param name="e">The <see cref="LogiFrame.ButtonEventArgs" /> instance containing the event data.</param> protected virtual void OnButtonUp(ButtonEventArgs e) { ButtonUp?.Invoke(this, e); }
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; } }
private void InvokeButtonUp(ButtonFlags button) { ButtonUp?.Invoke(this, new ControllerButtonUpEventArgs(button)); }