Skip to main content

enable

Function enable 

Source
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_state again.)
  • Cause xinput::get_state to 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

  • enabletrue to accept input and allow vibration, false to 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

§See Also