Created
April 11, 2017 07:42
-
-
Save fkaa/3216d6a4e6be47ce0cd4a98d5f6b1139 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use winit::{WindowEvent, ElementState}; | |
static mut KEYS: [bool; 256] = [false; 256]; | |
static mut KEYS_PRESSED: [bool; 256] = [false; 256]; | |
static mut KEYS_RELEASED: [bool; 256] = [false; 256]; | |
pub fn key_poll(evt: WindowEvent) { | |
match evt { | |
WindowEvent::KeyboardInput(ElementState::Pressed, scan, _, _) => { | |
unsafe { | |
KEYS[scan as usize] = true; | |
KEYS_PRESSED[scan as usize] = true; | |
} | |
}, | |
WindowEvent::KeyboardInput(ElementState::Released, scan, _, _) => { | |
unsafe { | |
KEYS[scan as usize] = false; | |
KEYS_RELEASED[scan as usize] = true; | |
} | |
}, | |
_ => {} | |
} | |
} | |
pub fn key_down(code: u8) -> bool { | |
unsafe { KEYS[code as usize] } | |
} | |
pub fn key_pressed(code: u8) -> bool { | |
unsafe { KEYS[code as usize] } | |
} | |
pub fn key_released(code: u8) -> bool { | |
unsafe { KEYS[code as usize] } | |
} | |
pub fn frame() { | |
unsafe { | |
KEYS_PRESSED = [false; 256]; | |
KEYS_RELEASED = [false; 256]; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment