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
4 changes: 2 additions & 2 deletions lighthouse-client/examples/snake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ async fn run_updater(lh: Lighthouse<TokioWebSocket>, shared_state: Arc<Mutex<Sta
async fn run_controller(mut stream: impl Stream<Item = Result<ServerMessage<InputEvent>>> + Unpin, shared_state: Arc<Mutex<State>>) -> Result<()> {
while let Some(msg) = stream.next().await {
match msg?.payload {
InputEvent::Key(KeyEvent { key, down, .. }) if down => {
InputEvent::Key(KeyEvent { code, down, .. }) if down => {
// Map the key code to a direction vector
let opt_dir = match key.as_str() {
let opt_dir = match code.as_str() {
"ArrowLeft" => Some(Delta::<i32>::LEFT),
"ArrowUp" => Some(Delta::<i32>::UP),
"ArrowRight" => Some(Delta::<i32>::RIGHT),
Expand Down
14 changes: 12 additions & 2 deletions lighthouse-protocol/src/input/input_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,22 @@ mod tests {
"type": "key",
"source": 0,
"down": true,
"key": "ArrowUp",
"repeat": false,
"code": "ArrowUp",
"altKey": false,
"ctrlKey": false,
"metaKey": false,
"shiftKey": false,
})).unwrap(),
InputEvent::Key(KeyEvent {
source: EventSource::Int(0),
down: true,
key: "ArrowUp".into(),
repeat: false,
code: "ArrowUp".into(),
alt_key: false,
ctrl_key: false,
meta_key: false,
shift_key: false,
})
);
}
Expand Down
14 changes: 12 additions & 2 deletions lighthouse-protocol/src/input/key_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ pub struct KeyEvent {
pub source: EventSource,
/// Whether the key was pressed.
pub down: bool,
/// The key pressed, see the docs on JS's `KeyboardEvent.key` for details.
pub key: String, // TODO: Extract stronger `Key` type
/// Whether the event is a repeat event.
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,
}