Skip to content

Commit c28896e

Browse files
authored
Merge pull request #33 from rust-embedded-community/moredocs
Add more docs
2 parents 93820bb + e0afc98 commit c28896e

File tree

11 files changed

+499
-52
lines changed

11 files changed

+499
-52
lines changed

README.md

+238
Large diffs are not rendered by default.

src/layouts/azerty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ mod test {
553553
);
554554
assert_eq!(
555555
k.process_keyevent(KeyEvent::new(KeyCode::NumpadLock, KeyState::Down)),
556-
None
556+
Some(DecodedKey::RawKey(KeyCode::NumpadLock))
557557
);
558558
assert_eq!(
559559
k.process_keyevent(KeyEvent::new(KeyCode::NumpadLock, KeyState::Up)),

src/layouts/colemak.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{DecodedKey, HandleControl, KeyCode, KeyboardLayout, Modifiers};
44

55
/// A Colemak 101-key (or 104-key including Windows keys) keyboard.
66
///
7-
/// Has a 1-row high Enter key, with Oem7 above (ANSI layout).
7+
/// Has a 1-row high Enter key, with Oem5 above (ANSI layout).
88
pub struct Colemak;
99

1010
impl KeyboardLayout for Colemak {

src/layouts/dvorak104.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{DecodedKey, HandleControl, KeyCode, KeyboardLayout, Modifiers};
44

55
/// A Dvorak 101-key (or 104-key including Windows keys) keyboard.
66
///
7-
/// Has a 1-row high Enter key, with Oem7 above (ANSI layout).
7+
/// Has a 1-row high Enter key, with Oem5 above (ANSI layout).
88
pub struct Dvorak104Key;
99

1010
impl KeyboardLayout for Dvorak104Key {

src/layouts/dvorak_programmer104.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{DecodedKey, HandleControl, KeyCode, KeyboardLayout, Modifiers};
44

55
/// A Dvorak Programmer 101-key (or 104-key including Windows keys) keyboard.
66
///
7-
/// Has a 1-row high Enter key, with Oem7 above (ANSI layout).
7+
/// Has a 1-row high Enter key, with Oem5 above (ANSI layout).
88
pub struct DVP104Key;
99

1010
impl KeyboardLayout for DVP104Key {

src/layouts/jis109.rs

+43-16
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ use crate::{DecodedKey, HandleControl, KeyCode, KeyboardLayout, Modifiers};
55
/// A standard Japan 106-key (or 109-key including Windows keys) keyboard.
66
///
77
/// Has a small space bar, to fit in extra keys.
8+
///
9+
/// We used <https://www.win.tue.nl/~aeb/linux/kbd/scancodes-8.html> as a
10+
/// reference.
811
pub struct Jis109Key;
912

1013
impl KeyboardLayout for Jis109Key {
@@ -16,11 +19,8 @@ impl KeyboardLayout for Jis109Key {
1619
) -> DecodedKey {
1720
match keycode {
1821
KeyCode::Oem8 => {
19-
if modifiers.is_shifted() {
20-
DecodedKey::Unicode('`')
21-
} else {
22-
DecodedKey::Unicode('@')
23-
}
22+
// hankaku/zenkaku/kanji
23+
DecodedKey::RawKey(KeyCode::Oem8)
2424
}
2525
KeyCode::Escape => DecodedKey::Unicode(0x1B.into()),
2626
KeyCode::Key1 => {
@@ -88,7 +88,7 @@ impl KeyboardLayout for Jis109Key {
8888
}
8989
KeyCode::Key0 => {
9090
if modifiers.is_shifted() {
91-
DecodedKey::Unicode(' ')
91+
DecodedKey::Unicode('~')
9292
} else {
9393
DecodedKey::Unicode('0')
9494
}
@@ -102,46 +102,73 @@ impl KeyboardLayout for Jis109Key {
102102
}
103103
KeyCode::OemPlus => {
104104
if modifiers.is_shifted() {
105-
DecodedKey::Unicode('+')
105+
DecodedKey::Unicode('¯')
106106
} else {
107-
DecodedKey::Unicode(';')
107+
DecodedKey::Unicode('^')
108108
}
109109
}
110110
KeyCode::Oem4 => {
111+
if modifiers.is_shifted() {
112+
DecodedKey::Unicode('`')
113+
} else {
114+
DecodedKey::Unicode('@')
115+
}
116+
}
117+
KeyCode::Oem6 => {
111118
if modifiers.is_shifted() {
112119
DecodedKey::Unicode('{')
113120
} else {
114121
DecodedKey::Unicode('[')
115122
}
116123
}
117-
KeyCode::Oem6 => {
124+
KeyCode::Oem7 => {
118125
if modifiers.is_shifted() {
119126
DecodedKey::Unicode('}')
120127
} else {
121128
DecodedKey::Unicode(']')
122129
}
123130
}
124-
KeyCode::Oem7 => {
131+
KeyCode::Oem1 => {
125132
if modifiers.is_shifted() {
126-
DecodedKey::Unicode('|')
133+
DecodedKey::Unicode('+')
127134
} else {
128-
DecodedKey::Unicode('\\')
135+
DecodedKey::Unicode(';')
129136
}
130137
}
131-
KeyCode::Oem1 => {
138+
KeyCode::Oem3 => {
132139
if modifiers.is_shifted() {
133140
DecodedKey::Unicode('*')
134141
} else {
135142
DecodedKey::Unicode(':')
136143
}
137144
}
138-
KeyCode::Oem3 => {
145+
KeyCode::Oem9 => {
146+
// Muhenkan
147+
DecodedKey::RawKey(keycode)
148+
}
149+
KeyCode::Oem10 => {
150+
// Henkan/Zenkouho
151+
DecodedKey::RawKey(keycode)
152+
}
153+
KeyCode::Oem11 => {
154+
// Hiragana/Katakana
155+
DecodedKey::RawKey(keycode)
156+
}
157+
KeyCode::Oem12 => {
139158
if modifiers.is_shifted() {
140-
DecodedKey::Unicode('~')
159+
DecodedKey::Unicode('_')
141160
} else {
142-
DecodedKey::Unicode('^')
161+
DecodedKey::Unicode('\\')
162+
}
163+
}
164+
KeyCode::Oem13 => {
165+
if modifiers.is_shifted() {
166+
DecodedKey::Unicode('|')
167+
} else {
168+
DecodedKey::Unicode('¥')
143169
}
144170
}
171+
145172
e => {
146173
let us = super::Us104Key;
147174
us.map_keycode(e, modifiers, handle_ctrl)

src/layouts/uk105.rs

+64-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,70 @@ impl KeyboardLayout for Uk105Key {
7979
#[cfg(test)]
8080
mod test {
8181
use super::*;
82-
use crate::{HandleControl, Keyboard, ScancodeSet2};
82+
use crate::{EventDecoder, HandleControl, Keyboard, ScancodeSet, ScancodeSet1, ScancodeSet2};
83+
84+
#[test]
85+
fn layout() {
86+
// Codes taken from https://kbdlayout.info/kbduk/overview+scancodes?arrangement=ISO105
87+
let mut s = ScancodeSet1::new();
88+
let mut dec = EventDecoder::new(Uk105Key, HandleControl::Ignore);
89+
let data = [
90+
(0x29, '`'),
91+
(0x02, '1'),
92+
(0x03, '2'),
93+
(0x04, '3'),
94+
(0x05, '4'),
95+
(0x06, '5'),
96+
(0x07, '6'),
97+
(0x08, '7'),
98+
(0x09, '8'),
99+
(0x0a, '9'),
100+
(0x0b, '0'),
101+
(0x0c, '-'),
102+
(0x0d, '='),
103+
(0x0f, '\t'),
104+
(0x10, 'q'),
105+
(0x11, 'w'),
106+
(0x12, 'e'),
107+
(0x13, 'r'),
108+
(0x14, 't'),
109+
(0x15, 'y'),
110+
(0x16, 'u'),
111+
(0x17, 'i'),
112+
(0x18, 'o'),
113+
(0x19, 'p'),
114+
(0x1a, '['),
115+
(0x1b, ']'),
116+
(0x1e, 'a'),
117+
(0x1f, 's'),
118+
(0x20, 'd'),
119+
(0x21, 'f'),
120+
(0x22, 'g'),
121+
(0x23, 'h'),
122+
(0x24, 'j'),
123+
(0x25, 'k'),
124+
(0x26, 'l'),
125+
(0x27, ';'),
126+
(0x28, '\''),
127+
(0x2B, '#'),
128+
(0x1c, '\n'),
129+
(0x56, '\\'),
130+
(0x2c, 'z'),
131+
(0x2d, 'x'),
132+
(0x2e, 'c'),
133+
(0x2f, 'v'),
134+
(0x30, 'b'),
135+
(0x31, 'n'),
136+
(0x32, 'm'),
137+
(0x33, ','),
138+
(0x34, '.'),
139+
(0x35, '/'),
140+
];
141+
for (code, unicode) in data {
142+
let ev = s.advance_state(code).unwrap().unwrap();
143+
assert_eq!(Some(DecodedKey::Unicode(unicode)), dec.process_keyevent(ev));
144+
}
145+
}
83146

84147
#[test]
85148
fn test_hash() {

src/layouts/us104.rs

+70-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{DecodedKey, HandleControl, KeyCode, KeyboardLayout, Modifiers};
44

55
/// A standard United States 101-key (or 104-key including Windows keys) keyboard.
66
///
7-
/// Has a 1-row high Enter key, with Oem7 above (ANSI layout).
7+
/// Has a 1-row high Enter key, with Oem5 above (ANSI layout).
88
pub struct Us104Key;
99

1010
impl KeyboardLayout for Us104Key {
@@ -214,7 +214,7 @@ impl KeyboardLayout for Us104Key {
214214
DecodedKey::Unicode(']')
215215
}
216216
}
217-
KeyCode::Oem7 => {
217+
KeyCode::Oem5 => {
218218
if modifiers.is_shifted() {
219219
DecodedKey::Unicode('|')
220220
} else {
@@ -484,3 +484,71 @@ impl KeyboardLayout for Us104Key {
484484
}
485485
}
486486
}
487+
488+
#[cfg(test)]
489+
mod test {
490+
use super::*;
491+
use crate::{EventDecoder, ScancodeSet, ScancodeSet1};
492+
493+
#[test]
494+
fn layout() {
495+
// Codes taken from https://kbdlayout.info/kbdus/overview+scancodes?arrangement=ANSI104
496+
let mut s = ScancodeSet1::new();
497+
let mut dec = EventDecoder::new(Us104Key, HandleControl::Ignore);
498+
let data = [
499+
(0x29, '`'),
500+
(0x02, '1'),
501+
(0x03, '2'),
502+
(0x04, '3'),
503+
(0x05, '4'),
504+
(0x06, '5'),
505+
(0x07, '6'),
506+
(0x08, '7'),
507+
(0x09, '8'),
508+
(0x0a, '9'),
509+
(0x0b, '0'),
510+
(0x0c, '-'),
511+
(0x0d, '='),
512+
(0x0f, '\t'),
513+
(0x10, 'q'),
514+
(0x11, 'w'),
515+
(0x12, 'e'),
516+
(0x13, 'r'),
517+
(0x14, 't'),
518+
(0x15, 'y'),
519+
(0x16, 'u'),
520+
(0x17, 'i'),
521+
(0x18, 'o'),
522+
(0x19, 'p'),
523+
(0x1a, '['),
524+
(0x1b, ']'),
525+
(0x56, '\\'),
526+
(0x1e, 'a'),
527+
(0x1f, 's'),
528+
(0x20, 'd'),
529+
(0x21, 'f'),
530+
(0x22, 'g'),
531+
(0x23, 'h'),
532+
(0x24, 'j'),
533+
(0x25, 'k'),
534+
(0x26, 'l'),
535+
(0x27, ';'),
536+
(0x28, '\''),
537+
(0x1c, '\n'),
538+
(0x2c, 'z'),
539+
(0x2d, 'x'),
540+
(0x2e, 'c'),
541+
(0x2f, 'v'),
542+
(0x30, 'b'),
543+
(0x31, 'n'),
544+
(0x32, 'm'),
545+
(0x33, ','),
546+
(0x34, '.'),
547+
(0x35, '/'),
548+
];
549+
for (code, unicode) in data {
550+
let ev = s.advance_state(code).unwrap().unwrap();
551+
assert_eq!(Some(DecodedKey::Unicode(unicode)), dec.process_keyevent(ev));
552+
}
553+
}
554+
}

0 commit comments

Comments
 (0)