Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions lighthouse-protocol/src/input/input_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub enum InputEvent {
mod tests {
use serde_json::json;

use crate::{EventSource, GamepadAxisEvent, GamepadButtonEvent, GamepadControlEvent, GamepadEvent, InputEvent, KeyEvent, MouseButton, MouseEvent, Pos};
use crate::{EventSource, GamepadAxisEvent, GamepadButtonEvent, GamepadControlEvent, GamepadEvent, InputEvent, KeyEvent, KeyModifiers, MouseButton, MouseEvent, Pos};

#[test]
fn key_event() {
Expand All @@ -26,20 +26,19 @@ mod tests {
"down": true,
"repeat": false,
"code": "ArrowUp",
"altKey": false,
"ctrlKey": false,
"metaKey": false,
"shiftKey": false,
"modifiers": {
"alt": false,
"ctrl": false,
"meta": false,
"shift": false,
},
})).unwrap(),
InputEvent::Key(KeyEvent {
source: EventSource::Int(0),
down: true,
repeat: false,
code: "ArrowUp".into(),
alt_key: false,
ctrl_key: false,
meta_key: false,
shift_key: false,
modifiers: KeyModifiers::default(),
})
);
}
Expand Down
12 changes: 3 additions & 9 deletions lighthouse-protocol/src/input/key_event.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};

use super::EventSource;
use super::{EventSource, KeyModifiers};

/// A keyboard event.
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
Expand All @@ -14,12 +14,6 @@ pub struct KeyEvent {
pub repeat: bool,
/// The key pressed, see the docs on JS's `KeyboardEvent.code` for details.
pub code: String, // TODO: Extract stronger `Key` type
/// Whether the alt key is held.
pub alt_key: bool,
/// Whether the ctrl key is held.
pub ctrl_key: bool,
/// Whether the meta key is held.
pub meta_key: bool,
/// Whether the shiftKey key is held.
pub shift_key: bool,
/// The held key modifiers.
pub modifiers: KeyModifiers,
}
26 changes: 26 additions & 0 deletions lighthouse-protocol/src/input/key_modifiers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use serde::{Deserialize, Serialize};

/// A keyboard event.
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
#[serde(rename_all = "camelCase")]
pub struct KeyModifiers {
/// Whether the alt key is held.
pub alt: bool,
/// Whether the ctrl key is held.
pub ctrl: bool,
/// Whether the meta key is held.
pub meta: bool,
/// Whether the shiftKey key is held.
pub shift: bool,
}

impl Default for KeyModifiers {
fn default() -> Self {
Self {
alt: false,
ctrl: false,
meta: false,
shift: false,
}
}
}
2 changes: 2 additions & 0 deletions lighthouse-protocol/src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod gamepad_control_event;
mod gamepad_event;
mod input_event;
mod key_event;
mod key_modifiers;
mod legacy_input_event;
mod mouse_button;
mod mouse_event;
Expand All @@ -16,6 +17,7 @@ pub use gamepad_control_event::*;
pub use gamepad_event::*;
pub use input_event::*;
pub use key_event::*;
pub use key_modifiers::*;
pub use legacy_input_event::*;
pub use mouse_button::*;
pub use mouse_event::*;