I'm using MonoGame and SDL2. I'm having a strange problem with the Gamepad. When I disconnect it during the game, before the disconnected event fires, the left and right triggers return values as if they were half-pressed.

The following code demonstrates the problem. Left or right trigger isn't really being pressed at all.

GamePadTriggers triggers = new GamePadTriggers(c.LeftTrigger.ReadFloat(device), c.RightTrigger.ReadFloat(device));
// The following is debug code added by me
var rawSDLvalue= SDL.SDL_GameControllerGetAxis(device, (SDL.SDL_GameControllerAxis)(c.LeftTrigger.ID));
Console.WriteLine("DURRURRRURRRRRRRR WHY IS IT NOT ZERO, IT SHOULD BE????" + c.LeftTrigger.ReadFloat(device) +" RAW "+rawSDLvalue);
}


Is there any real solution to this? Since the disconnected event fires afterward, I have no means to distinguish whether the triggers were really pressed or not. Any ideas? Are other SDL2 users experiencing this too?

I would guess this is due to the way triggers are implemented by your hardware. Often they are a single axis, with unpressed at -, fully pressed at +, and 0 when they are halfway pressed. This certainly happens with my classic Xbox controllers, and can cause issues when software thinks you are holding the axis fully negative when in fact you are not touching it. So what happens is a higher level software like SDL remaps driver output to something sensible.

I think what is happening is that when you unplug, Windows still allows you to read for a brief period, and just returns 0 for all axis/controls. This is then remapped to "halfway pressed" by the same remapping code. This seems like a bug, but there might not be anything SDL can do about it if Windows is sending spurious events like this.