pub fn is_key_pressed(key: KeyCode) -> bool {
    #[cfg(target_os = "windows")]
    unsafe {
        let key_code = key.to_i32().unwrap();
        let res = winapi::um::winuser::GetAsyncKeyState(key_code) as i32 & 0x8000;
        if res == 0 {
            false
        } else {
            true
        }
    }

    #[cfg(target_os = "linux")]
    unsafe {
        use x11::xlib::*;

        let key_code = key.to_u64().unwrap();

        let display = XOpenDisplay(0 as *const i8);
        let mut key_return = [0i8; 32];
        XQueryKeymap(display, &mut key_return as *mut i8);
        let kc = XKeysymToKeycode(display, key_code);
        let is_pressed = key_return[(kc >> 3) as usize] & (1 << (kc & 7));
        XCloseDisplay(display);

        if is_pressed == 0 {
            false
        } else {
            true
        }
    }
}
/// Queries system-wide key state.
///
/// # Examples
///
/// ```
/// // asking if Escape key is pressed right now
/// let answer = is_key_pressed(KeyCode::KEsc);
///
/// // asking if keyboard key T is pressed right now
/// let answer = is_key_pressed(KeyCode::KT);
/// ```
Queries system-wide key state.
Queries system - wide key state .
pub fn is_key_pressed(key: KeyCode) -> bool {
    #[cfg(target_os = "windows")]
    unsafe {
        let key_code = key.to_i32().unwrap();
        let res = winapi::um::winuser::GetAsyncKeyState(key_code) as i32 & 0x8000;
        if res == 0 {
            false
        } else {
            true
        }
    }
    #[cfg(target_os = "linux")]
    unsafe {
        use x11::xlib::*;
        let key_code = key.to_u64().unwrap();
        let display = XOpenDisplay(0 as *const i8);
        let mut key_return = [0i8; 32];
        XQueryKeymap(display, &mut key_return as *mut i8);
        let kc = XKeysymToKeycode(display, key_code);
        let is_pressed = key_return[(kc >> 3) as usize] & (1 << (kc & 7));
        XCloseDisplay(display);
        if is_pressed == 0 {
            false
        } else {
            true
        }
    }
}
pub fn is_key_pressed ( key : KeyCode ) -> bool { # [ cfg ( target_os " " ) ] unsafe { let key_code = key . to_i32 ( ) . unwrap ( ) ; let res = winapi :: um :: winuser :: GetAsyncKeyState ( key_code ) as i32 & 0x8000 ; if res == 0 { false } else { true } } # [ cfg ( target_os " " ) ] unsafe { use x11 :: xlib :: * ; let key_code = key . to_u64 ( ) . unwrap ( ) ; let display = XOpenDisplay ( 0 as * const i8 ) ; let mut key_return = [ 0i8 ; 32 ] ; XQueryKeymap ( display , & mut key_return as * mut i8 ) ; let kc = XKeysymToKeycode ( display , key_code ) ; let is_pressed = key_return [ ( kc >> 3 ) as usize ] & ( 1 << ( kc & 7 ) ) ; XCloseDisplay ( display ) ; if is_pressed == 0 { false } else { true } } }
Queries system-wide key state.
Queries system - wide key state .
key
KeyCode
examples
```
asking if Escape key is pressed right now
let answer = is_key_pressed(KeyCode::KEsc).

asking if keyboard key T is pressed right now
let answer = is_key_pressed(KeyCode::KT);
```
` ` ` asking if Escape key is pressed right now let answer = is_key_pressed ( KeyCode :: KEsc ) . asking if keyboard key T is pressed right now let answer = is_key_pressed ( KeyCode :: KT ) ; ` ` `