1
- use super :: { DecodedKey , KeyCode , KeyboardLayout , Modifiers } ;
1
+ use super :: { DecodedKey , KeyCode , KeyboardLayout , Modifiers , HandleControlPlusLetter } ;
2
2
3
3
/// A standard United States 101-key (or 104-key including Windows keys) keyboard.
4
4
/// Has a 1-row high Enter key, with Backslash above.
@@ -9,7 +9,8 @@ pub struct Us104Key;
9
9
pub struct Uk105Key ;
10
10
11
11
impl KeyboardLayout for Us104Key {
12
- fn map_keycode ( keycode : KeyCode , modifiers : & Modifiers ) -> DecodedKey {
12
+ fn map_keycode ( keycode : KeyCode , modifiers : & Modifiers , handle_ctrl : HandleControlPlusLetter ) -> DecodedKey {
13
+ let map_to_unicode = handle_ctrl == HandleControlPlusLetter :: MapToUnicode ;
13
14
match keycode {
14
15
KeyCode :: BackTick => {
15
16
if modifiers. is_shifted ( ) {
@@ -106,70 +107,90 @@ impl KeyboardLayout for Us104Key {
106
107
KeyCode :: Backspace => DecodedKey :: Unicode ( 0x08 . into ( ) ) ,
107
108
KeyCode :: Tab => DecodedKey :: Unicode ( 0x09 . into ( ) ) ,
108
109
KeyCode :: Q => {
109
- if modifiers. is_shifted ( ) {
110
+ if map_to_unicode && modifiers. is_ctrl ( ) {
111
+ DecodedKey :: Unicode ( '\u{0011}' )
112
+ } else if modifiers. is_caps ( ) {
110
113
DecodedKey :: Unicode ( 'Q' )
111
114
} else {
112
115
DecodedKey :: Unicode ( 'q' )
113
116
}
114
117
}
115
118
KeyCode :: W => {
116
- if modifiers. is_shifted ( ) {
119
+ if map_to_unicode && modifiers. is_ctrl ( ) {
120
+ DecodedKey :: Unicode ( '\u{0017}' )
121
+ } else if modifiers. is_caps ( ) {
117
122
DecodedKey :: Unicode ( 'W' )
118
123
} else {
119
124
DecodedKey :: Unicode ( 'w' )
120
125
}
121
126
}
122
127
KeyCode :: E => {
123
- if modifiers. is_shifted ( ) {
128
+ if map_to_unicode && modifiers. is_ctrl ( ) {
129
+ DecodedKey :: Unicode ( '\u{0005}' )
130
+ } else if modifiers. is_caps ( ) {
124
131
DecodedKey :: Unicode ( 'E' )
125
132
} else {
126
133
DecodedKey :: Unicode ( 'e' )
127
134
}
128
135
}
129
136
KeyCode :: R => {
130
- if modifiers. is_shifted ( ) {
137
+ if map_to_unicode && modifiers. is_ctrl ( ) {
138
+ DecodedKey :: Unicode ( '\u{0012}' )
139
+ } else if modifiers. is_caps ( ) {
131
140
DecodedKey :: Unicode ( 'R' )
132
141
} else {
133
142
DecodedKey :: Unicode ( 'r' )
134
143
}
135
144
}
136
145
KeyCode :: T => {
137
- if modifiers. is_shifted ( ) {
146
+ if map_to_unicode && modifiers. is_ctrl ( ) {
147
+ DecodedKey :: Unicode ( '\u{0014}' )
148
+ } else if modifiers. is_caps ( ) {
138
149
DecodedKey :: Unicode ( 'T' )
139
150
} else {
140
151
DecodedKey :: Unicode ( 't' )
141
152
}
142
153
}
143
154
KeyCode :: Y => {
144
- if modifiers. is_shifted ( ) {
155
+ if map_to_unicode && modifiers. is_ctrl ( ) {
156
+ DecodedKey :: Unicode ( '\u{0019}' )
157
+ } else if modifiers. is_caps ( ) {
145
158
DecodedKey :: Unicode ( 'Y' )
146
159
} else {
147
160
DecodedKey :: Unicode ( 'y' )
148
161
}
149
162
}
150
163
KeyCode :: U => {
151
- if modifiers. is_shifted ( ) {
164
+ if map_to_unicode && modifiers. is_ctrl ( ) {
165
+ DecodedKey :: Unicode ( '\u{0015}' )
166
+ } else if modifiers. is_caps ( ) {
152
167
DecodedKey :: Unicode ( 'U' )
153
168
} else {
154
169
DecodedKey :: Unicode ( 'u' )
155
170
}
156
171
}
157
172
KeyCode :: I => {
158
- if modifiers. is_shifted ( ) {
173
+ if map_to_unicode && modifiers. is_ctrl ( ) {
174
+ DecodedKey :: Unicode ( '\u{0009}' )
175
+ } else if modifiers. is_caps ( ) {
159
176
DecodedKey :: Unicode ( 'I' )
160
177
} else {
161
178
DecodedKey :: Unicode ( 'i' )
162
179
}
163
180
}
164
181
KeyCode :: O => {
165
- if modifiers. is_shifted ( ) {
182
+ if map_to_unicode && modifiers. is_ctrl ( ) {
183
+ DecodedKey :: Unicode ( '\u{000F}' )
184
+ } else if modifiers. is_caps ( ) {
166
185
DecodedKey :: Unicode ( 'O' )
167
186
} else {
168
187
DecodedKey :: Unicode ( 'o' )
169
188
}
170
189
}
171
190
KeyCode :: P => {
172
- if modifiers. is_shifted ( ) {
191
+ if map_to_unicode && modifiers. is_ctrl ( ) {
192
+ DecodedKey :: Unicode ( '\u{0010}' )
193
+ } else if modifiers. is_caps ( ) {
173
194
DecodedKey :: Unicode ( 'P' )
174
195
} else {
175
196
DecodedKey :: Unicode ( 'p' )
@@ -197,63 +218,81 @@ impl KeyboardLayout for Us104Key {
197
218
}
198
219
}
199
220
KeyCode :: A => {
200
- if modifiers. is_shifted ( ) {
221
+ if map_to_unicode && modifiers. is_ctrl ( ) {
222
+ DecodedKey :: Unicode ( '\u{0001}' )
223
+ } else if modifiers. is_caps ( ) {
201
224
DecodedKey :: Unicode ( 'A' )
202
225
} else {
203
226
DecodedKey :: Unicode ( 'a' )
204
227
}
205
228
}
206
229
KeyCode :: S => {
207
- if modifiers. is_shifted ( ) {
230
+ if map_to_unicode && modifiers. is_ctrl ( ) {
231
+ DecodedKey :: Unicode ( '\u{0013}' )
232
+ } else if modifiers. is_caps ( ) {
208
233
DecodedKey :: Unicode ( 'S' )
209
234
} else {
210
235
DecodedKey :: Unicode ( 's' )
211
236
}
212
237
}
213
238
KeyCode :: D => {
214
- if modifiers. is_shifted ( ) {
239
+ if map_to_unicode && modifiers. is_ctrl ( ) {
240
+ DecodedKey :: Unicode ( '\u{0004}' )
241
+ } else if modifiers. is_caps ( ) {
215
242
DecodedKey :: Unicode ( 'D' )
216
243
} else {
217
244
DecodedKey :: Unicode ( 'd' )
218
245
}
219
246
}
220
247
KeyCode :: F => {
221
- if modifiers. is_shifted ( ) {
248
+ if map_to_unicode && modifiers. is_ctrl ( ) {
249
+ DecodedKey :: Unicode ( '\u{0006}' )
250
+ } else if modifiers. is_caps ( ) {
222
251
DecodedKey :: Unicode ( 'F' )
223
252
} else {
224
253
DecodedKey :: Unicode ( 'f' )
225
254
}
226
255
}
227
256
KeyCode :: G => {
228
- if modifiers. is_shifted ( ) {
257
+ if map_to_unicode && modifiers. is_ctrl ( ) {
258
+ DecodedKey :: Unicode ( '\u{0007}' )
259
+ } else if modifiers. is_caps ( ) {
229
260
DecodedKey :: Unicode ( 'G' )
230
261
} else {
231
262
DecodedKey :: Unicode ( 'g' )
232
263
}
233
264
}
234
265
KeyCode :: H => {
235
- if modifiers. is_shifted ( ) {
266
+ if map_to_unicode && modifiers. is_ctrl ( ) {
267
+ DecodedKey :: Unicode ( '\u{0008}' )
268
+ } else if modifiers. is_caps ( ) {
236
269
DecodedKey :: Unicode ( 'H' )
237
270
} else {
238
271
DecodedKey :: Unicode ( 'h' )
239
272
}
240
273
}
241
274
KeyCode :: J => {
242
- if modifiers. is_shifted ( ) {
275
+ if map_to_unicode && modifiers. is_ctrl ( ) {
276
+ DecodedKey :: Unicode ( '\u{000A}' )
277
+ } else if modifiers. is_caps ( ) {
243
278
DecodedKey :: Unicode ( 'J' )
244
279
} else {
245
280
DecodedKey :: Unicode ( 'j' )
246
281
}
247
282
}
248
283
KeyCode :: K => {
249
- if modifiers. is_shifted ( ) {
284
+ if map_to_unicode && modifiers. is_ctrl ( ) {
285
+ DecodedKey :: Unicode ( '\u{000B}' )
286
+ } else if modifiers. is_caps ( ) {
250
287
DecodedKey :: Unicode ( 'K' )
251
288
} else {
252
289
DecodedKey :: Unicode ( 'k' )
253
290
}
254
291
}
255
292
KeyCode :: L => {
256
- if modifiers. is_shifted ( ) {
293
+ if map_to_unicode && modifiers. is_ctrl ( ) {
294
+ DecodedKey :: Unicode ( '\u{000C}' )
295
+ } else if modifiers. is_caps ( ) {
257
296
DecodedKey :: Unicode ( 'L' )
258
297
} else {
259
298
DecodedKey :: Unicode ( 'l' )
@@ -276,49 +315,63 @@ impl KeyboardLayout for Us104Key {
276
315
// Enter gives LF, not CRLF or CR
277
316
KeyCode :: Enter => DecodedKey :: Unicode ( 10 . into ( ) ) ,
278
317
KeyCode :: Z => {
279
- if modifiers. is_shifted ( ) {
318
+ if map_to_unicode && modifiers. is_ctrl ( ) {
319
+ DecodedKey :: Unicode ( '\u{001A}' )
320
+ } else if modifiers. is_caps ( ) {
280
321
DecodedKey :: Unicode ( 'Z' )
281
322
} else {
282
323
DecodedKey :: Unicode ( 'z' )
283
324
}
284
325
}
285
326
KeyCode :: X => {
286
- if modifiers. is_shifted ( ) {
327
+ if map_to_unicode && modifiers. is_ctrl ( ) {
328
+ DecodedKey :: Unicode ( '\u{0018}' )
329
+ } else if modifiers. is_caps ( ) {
287
330
DecodedKey :: Unicode ( 'X' )
288
331
} else {
289
332
DecodedKey :: Unicode ( 'x' )
290
333
}
291
334
}
292
335
KeyCode :: C => {
293
- if modifiers. is_shifted ( ) {
336
+ if map_to_unicode && modifiers. is_ctrl ( ) {
337
+ DecodedKey :: Unicode ( '\u{0003}' )
338
+ } else if modifiers. is_caps ( ) {
294
339
DecodedKey :: Unicode ( 'C' )
295
340
} else {
296
341
DecodedKey :: Unicode ( 'c' )
297
342
}
298
343
}
299
344
KeyCode :: V => {
300
- if modifiers. is_shifted ( ) {
345
+ if map_to_unicode && modifiers. is_ctrl ( ) {
346
+ DecodedKey :: Unicode ( '\u{0016}' )
347
+ } else if modifiers. is_caps ( ) {
301
348
DecodedKey :: Unicode ( 'V' )
302
349
} else {
303
350
DecodedKey :: Unicode ( 'v' )
304
351
}
305
352
}
306
353
KeyCode :: B => {
307
- if modifiers. is_shifted ( ) {
354
+ if map_to_unicode && modifiers. is_ctrl ( ) {
355
+ DecodedKey :: Unicode ( '\u{0002}' )
356
+ } else if modifiers. is_caps ( ) {
308
357
DecodedKey :: Unicode ( 'B' )
309
358
} else {
310
359
DecodedKey :: Unicode ( 'b' )
311
360
}
312
361
}
313
362
KeyCode :: N => {
314
- if modifiers. is_shifted ( ) {
363
+ if map_to_unicode && modifiers. is_ctrl ( ) {
364
+ DecodedKey :: Unicode ( '\u{000E}' )
365
+ } else if modifiers. is_caps ( ) {
315
366
DecodedKey :: Unicode ( 'N' )
316
367
} else {
317
368
DecodedKey :: Unicode ( 'n' )
318
369
}
319
370
}
320
371
KeyCode :: M => {
321
- if modifiers. is_shifted ( ) {
372
+ if map_to_unicode && modifiers. is_ctrl ( ) {
373
+ DecodedKey :: Unicode ( '\u{000D}' )
374
+ } else if modifiers. is_caps ( ) {
322
375
DecodedKey :: Unicode ( 'M' )
323
376
} else {
324
377
DecodedKey :: Unicode ( 'm' )
@@ -429,7 +482,7 @@ impl KeyboardLayout for Us104Key {
429
482
}
430
483
431
484
impl KeyboardLayout for Uk105Key {
432
- fn map_keycode ( keycode : KeyCode , modifiers : & Modifiers ) -> DecodedKey {
485
+ fn map_keycode ( keycode : KeyCode , modifiers : & Modifiers , handle_ctrl : HandleControlPlusLetter ) -> DecodedKey {
433
486
match keycode {
434
487
KeyCode :: BackTick => {
435
488
if modifiers. alt_gr {
@@ -477,7 +530,7 @@ impl KeyboardLayout for Uk105Key {
477
530
DecodedKey :: Unicode ( '#' )
478
531
}
479
532
}
480
- e => <Us104Key as KeyboardLayout >:: map_keycode ( e, modifiers) ,
533
+ e => <Us104Key as KeyboardLayout >:: map_keycode ( e, modifiers, handle_ctrl ) ,
481
534
}
482
535
}
483
536
}
0 commit comments