Checks if specific controller physically connected.
Takes controller (controller handle from inpCreateController, positive integer).
Returns 1 if controller connected, 0 if disconnected or error.
Input
Parameters & Returns
Parameters
controllerInt
Returns
Int
Quick Summary
Checks if specific controller physically connected.
Takes controller (controller handle from inpCreateController, positive integer).
Returns 1 if controller connected, 0 if disconnected or error.
Technical Exegesis...
Checks if specific controller physically connected. Takes controller (controller handle from inpCreateController, positive integer). Returns 1 if controller connected, 0 if disconnected or error. Queries XInput system for physical controller presence on handle's port, detects hotplug/unplug events.
Checks if specific controller physically connected. Takes controller (controller handle from inpCreateController, positive integer). Returns 1 if controller connected, 0 if disconnected or error. Queries XInput system for physical controller presence on handle's port, detects hotplug/unplug events.
Connection status: 1=controller physically connected (hardware present on port), 0=controller disconnected (no hardware on port, or handle invalid), connection state independent of handle creation (handle persists even when controller unplugged), check each frame for hotplug detection (controllers can be plugged/unplugged during gameplay).
Use cases: (1) Hotplug detection (detect controller connect/disconnect during gameplay: If inpIsControllerConnected(ctrl%) Then process input), (2) Multiplayer validation (check each player's controller connected before match), (3) UI prompts (show "press A to join" only for connected controllers), (4) Graceful degradation (fall back to keyboard if controller disconnected), (5) Connection status display (show player controller status in lobby).
Common patterns: connection check = If inpIsControllerConnected(controller%) Then update input Else show reconnect prompt; hotplug detect = connected%=inpIsControllerConnected(controller%): If connected%<>wasConnected% Then handle connect/disconnect event: wasConnected%=connected%; multiplayer validation = For i=0 To 3: If inpIsControllerConnected(controllers%(i)) Then player i active.
Hotplug events: Windows XInput supports hotplug (controllers detected when plugged in), call inpIsControllerConnected each frame or periodically (detects state changes), compare to previous frame status (detect connect/disconnect transitions), update UI/gameplay based on status changes (pause game, show reconnect message, etc.).
Handle persistence: controller handle created with inpCreateController persists (handle valid even when controller disconnected), inpIsControllerConnected checks current physical connection (returns 0 if unplugged, 1 if plugged back in), no need to recreate handle on reconnect (same handle works when controller reconnects).
Validation before input: best practice to check connection before querying input (If inpIsControllerConnected(ctrl%) Then read buttons), prevents errors from querying disconnected controllers (though queries return 0/neutral when disconnected), improves robustness (handle controller removal gracefully).
Performance: fast query (~0.001ms, simple XInput state check), safe for per-frame calls (intended usage pattern, no overhead), no controller update required (queries system connection state directly).
Connection vs input state: inpIsControllerConnected checks physical connection only (hardware present on port), does not check if controller powered on or responsive (though powered-off controllers usually report disconnected), does not validate controller type (any XInput device reports connected).
Return values: 1 if controller connected (hardware present on handle's port), 0 if controller disconnected (no hardware on port), 0 on error (invalid controller handle, prints error message).
Error handling: returns 0 for invalid controller handle (check handle > 0 before calling), prints error if handle out of range (check stderr for diagnostics), safe to call with any handle (won't crash, just returns 0).
Related: inpCreateController creates controller handle for port, inpGetControllerAmount returns total connected controller count, inpUpdateController updates controller input state (call before querying buttons/sticks).