Skip to content

Instantly share code, notes, and snippets.

@MartinZikmund
Created December 19, 2025 23:05
Show Gist options
  • Select an option

  • Save MartinZikmund/1b395cc0028efe59d02085a6ce693541 to your computer and use it in GitHub Desktop.

Select an option

Save MartinZikmund/1b395cc0028efe59d02085a6ce693541 to your computer and use it in GitHub Desktop.
if (_doom == null || Gamepad.Gamepads.Count == 0)
return;
var gamepad = Gamepad.Gamepads[0]; // Use first gamepad
var reading = gamepad.GetCurrentReading();
ProcessButtons(reading);
ProcessMovementStick(reading.LeftThumbstickX, reading.LeftThumbstickY);
ProcessLookStick(reading.RightThumbstickX, reading.RightThumbstickY);
ProcessTriggers(reading.LeftTrigger, reading.RightTrigger);
// ...
private void ProcessMovementStick(double x, double y)
{
// Apply deadzone
if (Math.Abs(x) < ThumbstickDeadzone) x = 0;
if (Math.Abs(y) < ThumbstickDeadzone) y = 0;
// Forward/Backward movement (Y-axis)
bool shouldMoveForward = y > ThumbstickDeadzone;
bool shouldMoveBackward = y < -ThumbstickDeadzone;
if (shouldMoveForward != _isMovingForward)
{
var eventType = shouldMoveForward ? EventType.KeyDown : EventType.KeyUp;
_userInput.SetKeyStatus(eventType, DoomKey.W, _doom!, new EventTimestamp());
_isMovingForward = shouldMoveForward;
}
if (shouldMoveBackward != _isMovingBackward)
{
var eventType = shouldMoveBackward ? EventType.KeyDown : EventType.KeyUp;
_userInput.SetKeyStatus(eventType, DoomKey.S, _doom!, new EventTimestamp());
_isMovingBackward = shouldMoveBackward;
}
// Strafe movement (X-axis)
bool shouldStrafeRight = x > ThumbstickDeadzone;
bool shouldStrafeLeft = x < -ThumbstickDeadzone;
if (shouldStrafeRight != _isStrafingRight)
{
var eventType = shouldStrafeRight ? EventType.KeyDown : EventType.KeyUp;
_userInput.SetKeyStatus(eventType, DoomKey.D, _doom!, new EventTimestamp());
_isStrafingRight = shouldStrafeRight;
}
if (shouldStrafeLeft != _isStrafingLeft)
{
var eventType = shouldStrafeLeft ? EventType.KeyDown : EventType.KeyUp;
_userInput.SetKeyStatus(eventType, DoomKey.A, _doom!, new EventTimestamp());
_isStrafingLeft = shouldStrafeLeft;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment