@@ -24,25 +24,29 @@ pub struct KeyboardInput {
24
24
///
25
25
/// ## Differences
26
26
///
27
- /// The main difference between the [`KeyboardInput`] event and the [`Input<KeyCode>`] resource is that
28
- /// the latter has convenient functions like [`Input::pressed`], [`Input::just_pressed`] and [`Input::just_released`].
27
+ /// The main difference between the [`KeyboardInput`] event and the [`Input<KeyCode>`] or [`Input<ScanCode>`] resources is that
28
+ /// the latter have convenient functions such as [`Input::pressed`], [`Input::just_pressed`] and [`Input::just_released`].
29
29
pub fn keyboard_input_system (
30
- mut keyboard_input : ResMut < Input < KeyCode > > ,
30
+ mut scan_input : ResMut < Input < ScanCode > > ,
31
+ mut key_input : ResMut < Input < KeyCode > > ,
31
32
mut keyboard_input_events : EventReader < KeyboardInput > ,
32
33
) {
33
- keyboard_input. clear ( ) ;
34
+ scan_input. clear ( ) ;
35
+ key_input. clear ( ) ;
34
36
for event in keyboard_input_events. iter ( ) {
35
- if let KeyboardInput {
36
- key_code : Some ( key_code) ,
37
- state,
38
- ..
39
- } = event
40
- {
37
+ let KeyboardInput {
38
+ scan_code, state, ..
39
+ } = event;
40
+ if let Some ( key_code) = event. key_code {
41
41
match state {
42
- ButtonState :: Pressed => keyboard_input . press ( * key_code) ,
43
- ButtonState :: Released => keyboard_input . release ( * key_code) ,
42
+ ButtonState :: Pressed => key_input . press ( key_code) ,
43
+ ButtonState :: Released => key_input . release ( key_code) ,
44
44
}
45
45
}
46
+ match state {
47
+ ButtonState :: Pressed => scan_input. press ( ScanCode ( * scan_code) ) ,
48
+ ButtonState :: Released => scan_input. release ( ScanCode ( * scan_code) ) ,
49
+ }
46
50
}
47
51
}
48
52
@@ -51,7 +55,7 @@ pub fn keyboard_input_system(
51
55
/// ## Usage
52
56
///
53
57
/// It is used as the generic `T` value of an [`Input`](crate::Input) to create a `Res<Input<KeyCode>>`.
54
- /// The resource stores the data of the buttons of a keyboard and can be accessed inside of a system .
58
+ /// The resource values are mapped to the current layout of the keyboard and correlate to an [`ScanCode`](ScanCode) .
55
59
///
56
60
/// ## Updating
57
61
///
@@ -407,3 +411,17 @@ pub enum KeyCode {
407
411
/// The `Cut` key.
408
412
Cut ,
409
413
}
414
+
415
+ /// The scan code of a [`KeyboardInput`](crate::keyboard::KeyboardInput).
416
+ ///
417
+ /// ## Usage
418
+ ///
419
+ /// It is used as the generic <T> value of an [`Input`](crate::Input) to create a `Res<Input<ScanCode>>`.
420
+ /// The resource values are mapped to the physical location of a key on the keyboard and correlate to an [`KeyCode`](KeyCode)
421
+ ///
422
+ /// ## Updating
423
+ ///
424
+ /// The resource is updated inside of the [`keyboard_input_system`](crate::keyboard::keyboard_input_system).
425
+ #[ derive( Debug , Hash , Ord , PartialOrd , PartialEq , Eq , Clone , Copy ) ]
426
+ #[ cfg_attr( feature = "serialize" , derive( serde:: Serialize , serde:: Deserialize ) ) ]
427
+ pub struct ScanCode ( pub u32 ) ;
0 commit comments