forked from rust-windowing/winit
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New keyboard API for Windows (rust-windowing#1788)
* Introducing the new `KeyEvent` and renaming old stuff * Implemented physical_key on Windows * Ran cargo fmt * Progress with the keyboard's windows implementation * Add proper handling of dead keys * Add translation for non-printable virtual keys * Run `cargo fmt` * Fix for AltGraph not being reported * Synthesize key events when focus enters or leaves * Minor improvements * Remove obsolete API * Fix numlock and pause not being reported correctly * Ran `cargo fmt` * Fix numpad keys being reported incorrectly * Update examples * Ran `cargo fmt` * Add documentation for `ScanCode` * Add key binding example * Use consistent modifier key names rust-windowing#1343 * WONT COMPILE transitioning to new keyboard API * WONT COMPILE Implement new keyboard layout preparation * WONT COMPILE new keyboard API progress * Main compile errors fixed for keyboard * Fix bugs in new keyboard handling * Remove obsolete code * Fix examples * Ran `cargo fmt` * Fix build error with serde * Ran `cargo fmt` * Tweaks in the Windows keyboard implementation * Add `KeyCodeExtScancode` * Add `reset_dead_keys` * Improve the documentation for `Key` and `KeyCode` * Rename the meta key to super * Address feedback for the keyboard API * Fix for rustdoc Co-authored-by: Markus Røyset <maroider@protonmail.com> * Improve documentation Co-authored-by: Markus Røyset <maroider@protonmail.com> * Fix for arrow keys being reported as unidentified. And minor improvements * Fix media keys reporting Unidentified * Don't report text on key release events * Fix for NumLock being reported as Pause in raw input * Fix for strange behaviour around NumLock and Pause * Fix for NumLock being ineffective * Fix for location not being reported correctly * `RawKeyEvent`s now report repeat * Don't report text for synthetic key releases * Address feedback - Add the `Space` variant to the `to_text` function. - Mark `get_kbd_state` safe. - Change `[MaybeUninit<u8>; 256]` to `MaybeUninit<[u8; 256]>` * Filter `Unidentified` from PrtSc key device events * Don't report incorrect `RawKeyEvent` for shift + numpad * AltGraph is not reported again * Document Windows specific behaviour for shift+numpad * Fix typo * Dead keys now affect characters from logical_key * Prevent Pause and NumLock mappings in window events * Apply suggestions from code review Co-authored-by: Markus Røyset <maroider@protonmail.com> * Ran `cargo fmt` * Add W3C license for `Key` and `KeyCode` * Extend documentation according to feedback * Ignore NumLock in `key_without_modifiers` * Remove unused `key_code_to_non_char_key` * Remove empty event.rs file * Use space for resetting dead keys * Fix reporting multiple graphemes in logical_key * Avoid incorrect synthetic keypress during setfocus * Fixed the AltGr keypress not being reported when the AltGr key is pressed and released in a very quick succession * Filter fake Ctrl events when pressing AltGr * Improve code quality * Remove `repeat` from `RawKeyEvent` * Allow fractional scroll in raw mouse events * Fix typo Co-authored-by: Markus Siglreithmaier <m.siglreith@gmail.com> * Remove unused imports * Remove unused variable * Remove unnecessary `unwrap()` Co-authored-by: Markus Siglreithmaier <m.siglreith@gmail.com> * Avoid using the deprecated `into_rgba()` * Fix IME crash Co-authored-by: Markus Røyset <maroider@protonmail.com> Co-authored-by: Markus Siglreithmaier <m.siglreith@gmail.com> Fix the `drag_window` example
- Loading branch information
1 parent
8af222c
commit 3ee2f02
Showing
30 changed files
with
4,516 additions
and
1,264 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use simple_logger::SimpleLogger; | ||
use winit::{ | ||
dpi::LogicalSize, | ||
event::{ElementState, Event, KeyEvent, WindowEvent}, | ||
event_loop::{ControlFlow, EventLoop}, | ||
keyboard::{Key, ModifiersState}, | ||
window::WindowBuilder, | ||
}; | ||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
// WARNING: This is not available on all platforms (for example on the web). | ||
use winit::platform::modifier_supplement::KeyEventExtModifierSupplement; | ||
///////////////////////////////////////////////////////////////////////////// | ||
|
||
fn main() { | ||
SimpleLogger::new().init().unwrap(); | ||
let event_loop = EventLoop::new(); | ||
|
||
let _window = WindowBuilder::new() | ||
.with_inner_size(LogicalSize::new(400.0, 200.0)) | ||
.build(&event_loop) | ||
.unwrap(); | ||
|
||
let mut modifiers = ModifiersState::default(); | ||
|
||
event_loop.run(move |event, _, control_flow| { | ||
*control_flow = ControlFlow::Wait; | ||
|
||
match event { | ||
Event::WindowEvent { event, .. } => match event { | ||
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit, | ||
WindowEvent::ModifiersChanged(new_state) => { | ||
modifiers = new_state; | ||
} | ||
WindowEvent::KeyboardInput { event, .. } => { | ||
handle_key_event(modifiers, event); | ||
} | ||
_ => (), | ||
}, | ||
_ => (), | ||
}; | ||
}); | ||
} | ||
|
||
fn handle_key_event(modifiers: ModifiersState, event: KeyEvent) { | ||
if event.state == ElementState::Pressed && !event.repeat { | ||
match event.key_without_modifiers() { | ||
Key::Character("1") => { | ||
if modifiers.shift_key() { | ||
println!("Shift + 1 | logical_key: {:?}", event.logical_key); | ||
} else { | ||
println!("1"); | ||
} | ||
} | ||
_ => (), | ||
} | ||
} | ||
} |
This file contains 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
Oops, something went wrong.