|
1 | 1 | //! Norwegian keyboard support
|
2 | 2 |
|
3 |
| -use crate::{DecodedKey, HandleControl, KeyCode, KeyboardLayout, Modifiers, PhysicalKeyboard}; |
| 3 | +use crate::{ |
| 4 | + DecodedKey, HandleControl, KeyCode, KeyboardLayout, Modifiers, PhysicalKeyboard, QUO, SLS, |
| 5 | +}; |
4 | 6 |
|
5 | 7 | /// A standard Norwegian 102-key (or 105-key including Windows keys) keyboard.
|
6 | 8 | ///
|
7 | 9 | /// Has a 2-row high Enter key, with Oem5 next to the left shift (ISO format).
|
8 | 10 | pub struct No105Key;
|
9 | 11 |
|
10 | 12 | impl KeyboardLayout for No105Key {
|
| 13 | + #[rustfmt::skip] |
11 | 14 | fn map_keycode(
|
12 | 15 | &self,
|
13 | 16 | keycode: KeyCode,
|
14 | 17 | modifiers: &Modifiers,
|
15 | 18 | handle_ctrl: HandleControl,
|
16 | 19 | ) -> DecodedKey {
|
17 |
| - let map_to_unicode = handle_ctrl == HandleControl::MapLettersToUnicode; |
18 | 20 | match keycode {
|
19 |
| - KeyCode::Escape => DecodedKey::Unicode('\u{001B}'), |
20 |
| - KeyCode::Oem8 => { |
21 |
| - if modifiers.is_shifted() { |
22 |
| - DecodedKey::Unicode('§') |
23 |
| - } else { |
24 |
| - DecodedKey::Unicode('|') |
25 |
| - } |
26 |
| - } |
27 |
| - KeyCode::Key1 => { |
28 |
| - if modifiers.is_shifted() { |
29 |
| - DecodedKey::Unicode('!') |
30 |
| - } else { |
31 |
| - DecodedKey::Unicode('1') |
32 |
| - } |
33 |
| - } |
34 |
| - KeyCode::Key2 => { |
35 |
| - if modifiers.is_shifted() { |
36 |
| - DecodedKey::Unicode('"') |
37 |
| - } else if modifiers.is_altgr() { |
38 |
| - DecodedKey::Unicode('@') |
39 |
| - } else { |
40 |
| - DecodedKey::Unicode('2') |
41 |
| - } |
42 |
| - } |
43 |
| - KeyCode::Key3 => { |
44 |
| - if modifiers.is_shifted() { |
45 |
| - DecodedKey::Unicode('#') |
46 |
| - } else if modifiers.is_altgr() { |
47 |
| - DecodedKey::Unicode('£') |
48 |
| - } else { |
49 |
| - DecodedKey::Unicode('3') |
50 |
| - } |
51 |
| - } |
52 |
| - KeyCode::Key4 => { |
53 |
| - if modifiers.is_shifted() { |
54 |
| - DecodedKey::Unicode('¤') |
55 |
| - } else if modifiers.is_altgr() { |
56 |
| - DecodedKey::Unicode('$') |
57 |
| - } else { |
58 |
| - DecodedKey::Unicode('4') |
59 |
| - } |
60 |
| - } |
61 |
| - KeyCode::Key5 => { |
62 |
| - if modifiers.is_shifted() { |
63 |
| - DecodedKey::Unicode('%') |
64 |
| - } else if modifiers.is_altgr() { |
65 |
| - DecodedKey::Unicode('€') |
66 |
| - } else { |
67 |
| - DecodedKey::Unicode('5') |
68 |
| - } |
69 |
| - } |
70 |
| - KeyCode::Key6 => { |
71 |
| - if modifiers.is_shifted() { |
72 |
| - DecodedKey::Unicode('&') |
73 |
| - } else { |
74 |
| - DecodedKey::Unicode('6') |
75 |
| - } |
76 |
| - } |
77 |
| - KeyCode::Key7 => { |
78 |
| - if modifiers.is_shifted() { |
79 |
| - DecodedKey::Unicode('/') |
80 |
| - } else if modifiers.is_altgr() { |
81 |
| - DecodedKey::Unicode('{') |
82 |
| - } else { |
83 |
| - DecodedKey::Unicode('7') |
84 |
| - } |
85 |
| - } |
86 |
| - KeyCode::Key8 => { |
87 |
| - if modifiers.is_shifted() { |
88 |
| - DecodedKey::Unicode('(') |
89 |
| - } else if modifiers.is_altgr() { |
90 |
| - DecodedKey::Unicode('[') |
91 |
| - } else { |
92 |
| - DecodedKey::Unicode('8') |
93 |
| - } |
94 |
| - } |
95 |
| - KeyCode::Key9 => { |
96 |
| - if modifiers.is_shifted() { |
97 |
| - DecodedKey::Unicode(')') |
98 |
| - } else if modifiers.is_altgr() { |
99 |
| - DecodedKey::Unicode(']') |
100 |
| - } else { |
101 |
| - DecodedKey::Unicode('9') |
102 |
| - } |
103 |
| - } |
104 |
| - KeyCode::Key0 => { |
105 |
| - if modifiers.is_shifted() { |
106 |
| - DecodedKey::Unicode('=') |
107 |
| - } else if modifiers.is_altgr() { |
108 |
| - DecodedKey::Unicode('}') |
109 |
| - } else { |
110 |
| - DecodedKey::Unicode('0') |
111 |
| - } |
112 |
| - } |
113 |
| - KeyCode::OemMinus => { |
114 |
| - if modifiers.is_shifted() { |
115 |
| - DecodedKey::Unicode('?') |
116 |
| - } else { |
117 |
| - DecodedKey::Unicode('+') |
118 |
| - } |
119 |
| - } |
120 |
| - KeyCode::OemPlus => { |
121 |
| - if modifiers.is_shifted() { |
122 |
| - DecodedKey::Unicode('`') |
123 |
| - } else if modifiers.is_altgr() { |
124 |
| - DecodedKey::Unicode('´') |
125 |
| - } else { |
126 |
| - DecodedKey::Unicode('\\') |
127 |
| - } |
128 |
| - } |
129 |
| - KeyCode::Backspace => DecodedKey::Unicode('\u{0008}'), |
130 |
| - KeyCode::Tab => DecodedKey::Unicode('\u{0009}'), |
131 |
| - KeyCode::E => { |
132 |
| - if map_to_unicode && modifiers.is_ctrl() { |
133 |
| - DecodedKey::Unicode('\u{0005}') |
134 |
| - } else if modifiers.is_altgr() { |
135 |
| - DecodedKey::Unicode('€') |
136 |
| - } else if modifiers.is_caps() { |
137 |
| - DecodedKey::Unicode('E') |
138 |
| - } else { |
139 |
| - DecodedKey::Unicode('e') |
140 |
| - } |
141 |
| - } |
142 |
| - KeyCode::Oem4 => { |
143 |
| - if modifiers.is_caps() { |
144 |
| - DecodedKey::Unicode('Å') |
145 |
| - } else { |
146 |
| - DecodedKey::Unicode('å') |
147 |
| - } |
148 |
| - } |
149 |
| - KeyCode::Oem6 => { |
150 |
| - if modifiers.is_altgr() { |
151 |
| - DecodedKey::Unicode('~') |
152 |
| - } else if modifiers.is_shifted() { |
153 |
| - DecodedKey::Unicode('^') |
154 |
| - } else { |
155 |
| - DecodedKey::Unicode('¨') |
156 |
| - } |
157 |
| - } |
158 |
| - KeyCode::Return => DecodedKey::Unicode('\u{000A}'), |
159 |
| - KeyCode::Oem7 => { |
160 |
| - if modifiers.is_shifted() { |
161 |
| - DecodedKey::Unicode('*') |
162 |
| - } else { |
163 |
| - DecodedKey::Unicode('\'') |
164 |
| - } |
165 |
| - } |
166 |
| - KeyCode::Oem1 => { |
167 |
| - if modifiers.is_caps() { |
168 |
| - DecodedKey::Unicode('Ø') |
169 |
| - } else { |
170 |
| - DecodedKey::Unicode('ø') |
171 |
| - } |
172 |
| - } |
173 |
| - KeyCode::Oem3 => { |
174 |
| - if modifiers.is_caps() { |
175 |
| - DecodedKey::Unicode('Æ') |
176 |
| - } else { |
177 |
| - DecodedKey::Unicode('æ') |
178 |
| - } |
179 |
| - } |
180 |
| - KeyCode::M => { |
181 |
| - if map_to_unicode && modifiers.is_ctrl() { |
182 |
| - DecodedKey::Unicode('\u{000D}') |
183 |
| - } else if modifiers.is_altgr() { |
184 |
| - DecodedKey::Unicode('µ') |
185 |
| - } else if modifiers.is_caps() { |
186 |
| - DecodedKey::Unicode('M') |
187 |
| - } else { |
188 |
| - DecodedKey::Unicode('m') |
189 |
| - } |
190 |
| - } |
191 |
| - KeyCode::OemComma => { |
192 |
| - if modifiers.is_shifted() { |
193 |
| - DecodedKey::Unicode(';') |
194 |
| - } else { |
195 |
| - DecodedKey::Unicode(',') |
196 |
| - } |
197 |
| - } |
198 |
| - KeyCode::OemPeriod => { |
199 |
| - if modifiers.is_shifted() { |
200 |
| - DecodedKey::Unicode(':') |
201 |
| - } else { |
202 |
| - DecodedKey::Unicode('.') |
203 |
| - } |
204 |
| - } |
205 |
| - KeyCode::Oem2 => { |
206 |
| - if modifiers.is_shifted() { |
207 |
| - DecodedKey::Unicode('_') |
208 |
| - } else { |
209 |
| - DecodedKey::Unicode('-') |
210 |
| - } |
211 |
| - } |
212 |
| - KeyCode::Oem5 => { |
213 |
| - if modifiers.is_shifted() { |
214 |
| - DecodedKey::Unicode('>') |
215 |
| - } else { |
216 |
| - DecodedKey::Unicode('<') |
217 |
| - } |
218 |
| - } |
219 |
| - KeyCode::NumpadPeriod => { |
220 |
| - if modifiers.numlock { |
221 |
| - DecodedKey::Unicode(',') |
222 |
| - } else { |
223 |
| - DecodedKey::Unicode('\u{007F}') |
224 |
| - } |
225 |
| - } |
226 |
| - e => { |
227 |
| - let us = super::Us104Key; |
228 |
| - us.map_keycode(e, modifiers, handle_ctrl) |
229 |
| - } |
| 21 | + // ========= Row 2 (the numbers) ========= |
| 22 | + KeyCode::Oem8 => modifiers.handle_shift('|', '§'), |
| 23 | + KeyCode::Key2 => modifiers.handle_altsh('2', '"', '@'), |
| 24 | + KeyCode::Key3 => modifiers.handle_altsh('3', '#', '£'), |
| 25 | + KeyCode::Key4 => modifiers.handle_altsh('4', '¤', '$'), |
| 26 | + KeyCode::Key5 => modifiers.handle_shift('5', '%'), |
| 27 | + KeyCode::Key6 => modifiers.handle_shift('6', '&'), |
| 28 | + KeyCode::Key7 => modifiers.handle_altsh('7', '/', '{'), |
| 29 | + KeyCode::Key8 => modifiers.handle_altsh('8', '(', '['), |
| 30 | + KeyCode::Key9 => modifiers.handle_altsh('9', ')', ']'), |
| 31 | + KeyCode::Key0 => modifiers.handle_altsh('0', '=', '}'), |
| 32 | + KeyCode::OemMinus => modifiers.handle_shift('+', '?'), |
| 33 | + KeyCode::OemPlus => modifiers.handle_altsh(SLS, '`', '´'), |
| 34 | + // ========= Row 3 (QWERTY) ========= |
| 35 | + KeyCode::E => modifiers.handle_alalt('E', '€', '€', handle_ctrl), |
| 36 | + KeyCode::Oem4 => modifiers.handle_accen('å', 'Å'), |
| 37 | + KeyCode::Oem6 => modifiers.handle_altsh('¨', '^', '~'), |
| 38 | + // ========= Row 4 (ASDF) ========= |
| 39 | + KeyCode::Oem7 => modifiers.handle_shift(QUO, '*'), |
| 40 | + KeyCode::Oem1 => modifiers.handle_accen('ø', 'Ø'), |
| 41 | + KeyCode::Oem3 => modifiers.handle_accen('æ', 'Æ'), |
| 42 | + // ========= Row 5 (ZXCV) ========= |
| 43 | + KeyCode::Oem5 => modifiers.handle_shift('<', '>'), |
| 44 | + KeyCode::M => modifiers.handle_alalt('M', 'µ', 'µ', handle_ctrl), |
| 45 | + KeyCode::OemComma => modifiers.handle_shift(',', ';'), |
| 46 | + KeyCode::OemPeriod => modifiers.handle_shift('.', ':'), |
| 47 | + KeyCode::Oem2 => modifiers.handle_shift('-', '_'), |
| 48 | + KeyCode::NumpadPeriod if modifiers.numlock => DecodedKey::Unicode(','), |
| 49 | + // ========= Row 6 (modifers and space bar) ========= |
| 50 | + e => super::Us104Key.map_keycode(e, modifiers, handle_ctrl), |
230 | 51 | }
|
231 | 52 | }
|
232 | 53 |
|
|
0 commit comments