diff --git a/lighthouse-client/examples/snake.rs b/lighthouse-client/examples/snake.rs index 2bbce6e..49bce22 100644 --- a/lighthouse-client/examples/snake.rs +++ b/lighthouse-client/examples/snake.rs @@ -145,9 +145,9 @@ async fn run_updater(lh: Lighthouse, shared_state: Arc>> + Unpin, shared_state: Arc>) -> 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::::LEFT), "ArrowUp" => Some(Delta::::UP), "ArrowRight" => Some(Delta::::RIGHT), diff --git a/lighthouse-protocol/src/input/input_event.rs b/lighthouse-protocol/src/input/input_event.rs index 7e6f8c2..759b13a 100644 --- a/lighthouse-protocol/src/input/input_event.rs +++ b/lighthouse-protocol/src/input/input_event.rs @@ -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, }) ); } diff --git a/lighthouse-protocol/src/input/key_event.rs b/lighthouse-protocol/src/input/key_event.rs index 647b3ec..d3f0117 100644 --- a/lighthouse-protocol/src/input/key_event.rs +++ b/lighthouse-protocol/src/input/key_event.rs @@ -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, }