1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use window::Window;

pub trait Key {
    fn is_pressed(&self, window: &Window) -> bool;
}

#[derive(PartialEq, Clone, Copy)]
pub enum SpecialKey {
    Escape,
    Control,
    Shift,
    Alt,
    Return,
    Backspace,
    Left,
    Right,
    Up,
    Down,
}

impl Key for char {
    fn is_pressed(&self, window: &Window) -> bool {
        window.event.chars.contains(|ref c| c == self)
    }
}

impl Key for SpecialKey {
    fn is_pressed(&self, window: &Window) -> bool {
        window.event.keys.contains(self)
    }
}