diff --git a/devtools/src/lib.rs b/devtools/src/lib.rs index 6ad7ae9a..534103c5 100644 --- a/devtools/src/lib.rs +++ b/devtools/src/lib.rs @@ -381,14 +381,15 @@ where program.subscription(&self.state).map(Event::Program); debug::subscriptions_tracked(subscription.units()); - let hotkeys = - futures::keyboard::on_key_press(|key, _modifiers| match key { + let hotkeys = futures::keyboard::on_key_press( + |key, _physical_key, _modifiers| match key { keyboard::Key::Named(keyboard::key::Named::F12) => { Some(Message::ToggleComet) } _ => None, - }) - .map(Event::Message); + }, + ) + .map(Event::Message); let commands = debug::commands().map(Event::Command); diff --git a/examples/layout/src/main.rs b/examples/layout/src/main.rs index 4907f5a4..eae9228b 100644 --- a/examples/layout/src/main.rs +++ b/examples/layout/src/main.rs @@ -58,7 +58,7 @@ impl Layout { fn subscription(&self) -> Subscription { use keyboard::key; - keyboard::on_key_release(|key, _modifiers| match key { + keyboard::on_key_release(|key, _physical_key, _modifiers| match key { keyboard::Key::Named(key::Named::ArrowLeft) => { Some(Message::Previous) } diff --git a/examples/pane_grid/src/main.rs b/examples/pane_grid/src/main.rs index f94e83ca..63e3470d 100644 --- a/examples/pane_grid/src/main.rs +++ b/examples/pane_grid/src/main.rs @@ -117,12 +117,12 @@ impl Example { } fn subscription(&self) -> Subscription { - keyboard::on_key_press(|key_code, modifiers| { + keyboard::on_key_press(|key, _physical_key, modifiers| { if !modifiers.command() { return None; } - handle_hotkey(key_code) + handle_hotkey(key) }) } diff --git a/examples/screenshot/src/main.rs b/examples/screenshot/src/main.rs index 86827858..716706c6 100644 --- a/examples/screenshot/src/main.rs +++ b/examples/screenshot/src/main.rs @@ -227,7 +227,7 @@ impl Example { fn subscription(&self) -> Subscription { use keyboard::key; - keyboard::on_key_press(|key, _modifiers| { + keyboard::on_key_press(|key, _physical_key, _modifiers| { if let keyboard::Key::Named(key::Named::F5) = key { Some(Message::Screenshot) } else { diff --git a/examples/stopwatch/src/main.rs b/examples/stopwatch/src/main.rs index 9488f55a..d4023f0b 100644 --- a/examples/stopwatch/src/main.rs +++ b/examples/stopwatch/src/main.rs @@ -67,6 +67,7 @@ impl Stopwatch { fn handle_hotkey( key: keyboard::Key, + _physical_key: keyboard::key::Physical, _modifiers: keyboard::Modifiers, ) -> Option { use keyboard::key; diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs index 762657f9..b1339021 100644 --- a/examples/styling/src/main.rs +++ b/examples/styling/src/main.rs @@ -190,7 +190,7 @@ impl Styling { } fn subscription(&self) -> Subscription { - keyboard::on_key_press(|key, _modifiers| match key { + keyboard::on_key_press(|key, _physical_key, _modifiers| match key { keyboard::Key::Named( keyboard::key::Named::ArrowUp | keyboard::key::Named::ArrowLeft, ) => Some(Message::PreviousTheme), diff --git a/examples/todos/src/main.rs b/examples/todos/src/main.rs index 06fe11d1..6f027fa0 100644 --- a/examples/todos/src/main.rs +++ b/examples/todos/src/main.rs @@ -254,7 +254,7 @@ impl Todos { fn subscription(&self) -> Subscription { use keyboard::key; - keyboard::on_key_press(|key, modifiers| { + keyboard::on_key_press(|key, _physical_key, modifiers| { let keyboard::Key::Named(key) = key else { return None; }; diff --git a/futures/src/keyboard.rs b/futures/src/keyboard.rs index 036edb9c..f82ff2ed 100644 --- a/futures/src/keyboard.rs +++ b/futures/src/keyboard.rs @@ -2,7 +2,7 @@ use crate::MaybeSend; use crate::core; use crate::core::event; -use crate::core::keyboard::{Event, Key, Modifiers}; +use crate::core::keyboard::{Event, Key, Modifiers, key}; use crate::subscription::{self, Subscription}; /// Listens to keyboard key presses and calls the given function @@ -11,7 +11,7 @@ use crate::subscription::{self, Subscription}; /// If the function returns `None`, the key press will be simply /// ignored. pub fn on_key_press( - f: fn(Key, Modifiers) -> Option, + f: fn(Key, key::Physical, Modifiers) -> Option, ) -> Subscription where Message: MaybeSend + 'static, @@ -22,10 +22,15 @@ where subscription::filter_map((OnKeyPress, f), move |event| match event { subscription::Event::Interaction { event: - core::Event::Keyboard(Event::KeyPressed { key, modifiers, .. }), + core::Event::Keyboard(Event::KeyPressed { + key, + physical_key, + modifiers, + .. + }), status: event::Status::Ignored, .. - } => f(key, modifiers), + } => f(key, physical_key, modifiers), _ => None, }) } @@ -36,7 +41,7 @@ where /// If the function returns `None`, the key release will be simply /// ignored. pub fn on_key_release( - f: fn(Key, Modifiers) -> Option, + f: fn(Key, key::Physical, Modifiers) -> Option, ) -> Subscription where Message: MaybeSend + 'static, @@ -47,10 +52,15 @@ where subscription::filter_map((OnKeyRelease, f), move |event| match event { subscription::Event::Interaction { event: - core::Event::Keyboard(Event::KeyReleased { key, modifiers, .. }), + core::Event::Keyboard(Event::KeyReleased { + key, + physical_key, + modifiers, + .. + }), status: event::Status::Ignored, .. - } => f(key, modifiers), + } => f(key, physical_key, modifiers), _ => None, }) }