Skip to content

Commit c0faeb3

Browse files
authored
Merge pull request #19 from ProjectLighthouseCAU/update-key-api
Update key API to new code and modifier fields
2 parents d6af805 + 3d444e4 commit c0faeb3

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

lighthouse-client/examples/snake.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ async fn run_updater(lh: Lighthouse<TokioWebSocket>, shared_state: Arc<Mutex<Sta
145145
async fn run_controller(mut stream: impl Stream<Item = Result<ServerMessage<InputEvent>>> + Unpin, shared_state: Arc<Mutex<State>>) -> Result<()> {
146146
while let Some(msg) = stream.next().await {
147147
match msg?.payload {
148-
InputEvent::Key(KeyEvent { key, down, .. }) if down => {
148+
InputEvent::Key(KeyEvent { code, down, .. }) if down => {
149149
// Map the key code to a direction vector
150-
let opt_dir = match key.as_str() {
150+
let opt_dir = match code.as_str() {
151151
"ArrowLeft" => Some(Delta::<i32>::LEFT),
152152
"ArrowUp" => Some(Delta::<i32>::UP),
153153
"ArrowRight" => Some(Delta::<i32>::RIGHT),

lighthouse-protocol/src/input/input_event.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,22 @@ mod tests {
2424
"type": "key",
2525
"source": 0,
2626
"down": true,
27-
"key": "ArrowUp",
27+
"repeat": false,
28+
"code": "ArrowUp",
29+
"altKey": false,
30+
"ctrlKey": false,
31+
"metaKey": false,
32+
"shiftKey": false,
2833
})).unwrap(),
2934
InputEvent::Key(KeyEvent {
3035
source: EventSource::Int(0),
3136
down: true,
32-
key: "ArrowUp".into(),
37+
repeat: false,
38+
code: "ArrowUp".into(),
39+
alt_key: false,
40+
ctrl_key: false,
41+
meta_key: false,
42+
shift_key: false,
3343
})
3444
);
3545
}

lighthouse-protocol/src/input/key_event.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ pub struct KeyEvent {
1010
pub source: EventSource,
1111
/// Whether the key was pressed.
1212
pub down: bool,
13-
/// The key pressed, see the docs on JS's `KeyboardEvent.key` for details.
14-
pub key: String, // TODO: Extract stronger `Key` type
13+
/// Whether the event is a repeat event.
14+
pub repeat: bool,
15+
/// The key pressed, see the docs on JS's `KeyboardEvent.code` for details.
16+
pub code: String, // TODO: Extract stronger `Key` type
17+
/// Whether the alt key is held.
18+
pub alt_key: bool,
19+
/// Whether the ctrl key is held.
20+
pub ctrl_key: bool,
21+
/// Whether the meta key is held.
22+
pub meta_key: bool,
23+
/// Whether the shiftKey key is held.
24+
pub shift_key: bool,
1525
}

0 commit comments

Comments
 (0)