pub fn enable(enable: impl Into<bool>) -> Result<(), Error>Expand description
[microsoft.com] XInputEnable (1.1+)
Meant to be called when an application gains or loses activation (WM_ACTIVATEAPP),
to enable or disable XInput for this app.
“Disabling” xinput for the current process with xinput::enable(false) will:
- Stop all vibration (including if you call
xinput::set_stateagain.) - Cause
xinput::get_stateto retrieve neutral data for connected controllers (no buttons held, 0ed axises.)
While this is plenty sufficient for games wanting to handle OS-level application focus,
this is not particularly useful if you instead want to enable/disable xinput access on a
per window or per focused control basis instead of application-wide.
Wrapping get_state, set_state, etc. to filter these at a more granular level is left
as an exercise to the API consumer and whatever wrappers around xinput they might write.
§Arguments
enable—trueto accept input and allow vibration,falseto block input and vibration.
§Example
unsafe extern "system"
fn wndproc(hwnd: HWND, msg: u32, wparam: WPARAM, lparam: LPARAM) -> LRESULT {
match msg {
WM_ACTIVATEAPP => { let _ = xinput::enable(wparam as BOOL != FALSE); },
_ => {},
}
DefWindowProcW(hwnd, msg, wparam, lparam)
}§Errors
- error::INVALID_FUNCTION - API unavailable: requires XInput 1.1 or later
§See Also
WM_ACTIVATEAPP— Application gains/loses activation.WM_ACTIVATE— Individual top-level window gains/loses activation. I generally don’t recommend callingenablefrom this.- How is the Focus working in a windows program? — archive.org’ed codeguru.com thread from 2007 with multiple replies by “SuperKoko” detailing message order, the nuances of activated window vs focused window, etc.