Skip to content

Commit

Permalink
Merge pull request #313 from NuriYuri/add-scan-codes
Browse files Browse the repository at this point in the history
Make Scancode public and add missing scan field to KeyReleased event
  • Loading branch information
crumblingstatue authored Aug 16, 2023
2 parents 2c41c4b + 0b828ac commit 2247ca4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
18 changes: 15 additions & 3 deletions examples/pong.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use {
Transformable,
},
system::{Clock, Time, Vector2f},
window::{ContextSettings, Event, Key, Style},
window::{ContextSettings, Event, Key, Scancode, Style},
},
std::{env, f32::consts::PI},
};
Expand Down Expand Up @@ -134,13 +134,25 @@ fn main() {
}
}
}
Event::KeyPressed { code: Key::Up, .. } => up = true,
Event::KeyReleased { code: Key::Up, .. } => up = false,
Event::KeyPressed { code: Key::Up, .. }
| Event::KeyPressed {
scan: Scancode::W, ..
} => up = true,
Event::KeyReleased { code: Key::Up, .. }
| Event::KeyReleased {
scan: Scancode::W, ..
} => up = false,
Event::KeyPressed {
code: Key::Down, ..
}
| Event::KeyPressed {
scan: Scancode::S, ..
} => down = true,
Event::KeyReleased {
code: Key::Down, ..
}
| Event::KeyReleased {
scan: Scancode::S, ..
} => down = false,
_ => {}
}
Expand Down
3 changes: 3 additions & 0 deletions src/window/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ pub enum Event {
KeyReleased {
/// The released key
code: ffi::Key,
/// The scancode of the released key
scan: ffi::Scancode,
/// Is alt released too?
alt: bool,
/// Is ctrl released too?
Expand Down Expand Up @@ -228,6 +230,7 @@ impl Event {
},
EventType::KeyReleased => KeyReleased {
code: event.union.key.code,
scan: event.union.key.scan,
alt: event.union.key.alt,
ctrl: event.union.key.control,
shift: event.union.key.shift,
Expand Down
2 changes: 2 additions & 0 deletions src/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ pub use self::{
window::{Handle, Window},
};

pub use crate::ffi::window::Scancode;

pub mod clipboard;
mod context;
mod context_settings;
Expand Down

0 comments on commit 2247ca4

Please sign in to comment.