Skip to content

Commit 549d49e

Browse files
authored
Fix UK Hash and Backslash mixup (#27)
1 parent 8e3fe24 commit 549d49e

14 files changed

+1595
-1076
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
* Changed ordering of `enum KeyCode` and names of several of the keys
6+
* Support the mysterious 'Right Control 2' and 'Right Alt 2' so that Pause/Break
7+
and Print Screen do the right thing.
8+
* Fix the Backslash/Tilde swap on the UK Layout.
9+
310
## v0.6.1 (20 October 2022)
411

512
* Fix Control-Letter codes on AZERTY

src/layouts/azerty.rs

+69-18
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ impl KeyboardLayout for Azerty {
1111
let map_to_unicode = handle_ctrl == HandleControl::MapLettersToUnicode;
1212
match keycode {
1313
KeyCode::Escape => DecodedKey::Unicode(0x1B.into()),
14-
KeyCode::BackTick => DecodedKey::Unicode('²'),
15-
KeyCode::HashTilde => {
14+
KeyCode::Oem8 => DecodedKey::Unicode('²'),
15+
KeyCode::Oem5 => {
1616
if modifiers.is_shifted() {
1717
DecodedKey::Unicode('*')
1818
} else {
@@ -107,7 +107,7 @@ impl KeyboardLayout for Azerty {
107107
DecodedKey::Unicode('à')
108108
}
109109
}
110-
KeyCode::Minus => {
110+
KeyCode::OemMinus => {
111111
if modifiers.is_shifted() {
112112
DecodedKey::Unicode('°')
113113
} else if modifiers.alt_gr {
@@ -116,7 +116,7 @@ impl KeyboardLayout for Azerty {
116116
DecodedKey::Unicode(')')
117117
}
118118
}
119-
KeyCode::Equals => {
119+
KeyCode::OemPlus => {
120120
if modifiers.is_shifted() {
121121
DecodedKey::Unicode('+')
122122
} else if modifiers.alt_gr {
@@ -217,7 +217,7 @@ impl KeyboardLayout for Azerty {
217217
DecodedKey::Unicode('p')
218218
}
219219
}
220-
KeyCode::BracketSquareLeft => {
220+
KeyCode::Oem4 => {
221221
if modifiers.is_shifted() {
222222
DecodedKey::Unicode('¨')
223223
} else if modifiers.alt_gr {
@@ -226,7 +226,7 @@ impl KeyboardLayout for Azerty {
226226
DecodedKey::Unicode('^')
227227
}
228228
}
229-
KeyCode::BracketSquareRight => {
229+
KeyCode::Oem6 => {
230230
if modifiers.is_shifted() {
231231
DecodedKey::Unicode('£')
232232
} else if modifiers.alt_gr {
@@ -235,7 +235,7 @@ impl KeyboardLayout for Azerty {
235235
DecodedKey::Unicode('$')
236236
}
237237
}
238-
KeyCode::BackSlash => {
238+
KeyCode::Oem7 => {
239239
if modifiers.is_shifted() {
240240
DecodedKey::Unicode('µ')
241241
} else {
@@ -323,7 +323,7 @@ impl KeyboardLayout for Azerty {
323323
DecodedKey::Unicode('l')
324324
}
325325
}
326-
KeyCode::SemiColon => {
326+
KeyCode::Oem1 => {
327327
if map_to_unicode && modifiers.is_ctrl() {
328328
DecodedKey::Unicode('\u{000D}')
329329
} else if modifiers.is_caps() {
@@ -332,15 +332,15 @@ impl KeyboardLayout for Azerty {
332332
DecodedKey::Unicode('m')
333333
}
334334
}
335-
KeyCode::Quote => {
335+
KeyCode::Oem3 => {
336336
if modifiers.is_shifted() {
337337
DecodedKey::Unicode('%')
338338
} else {
339339
DecodedKey::Unicode('ù')
340340
}
341341
}
342342
// Enter gives LF, not CRLF or CR
343-
KeyCode::Enter => DecodedKey::Unicode(10.into()),
343+
KeyCode::Return => DecodedKey::Unicode(10.into()),
344344
KeyCode::Z => {
345345
if map_to_unicode && modifiers.is_ctrl() {
346346
DecodedKey::Unicode('\u{0017}')
@@ -402,21 +402,21 @@ impl KeyboardLayout for Azerty {
402402
DecodedKey::Unicode(',')
403403
}
404404
}
405-
KeyCode::Comma => {
405+
KeyCode::OemComma => {
406406
if modifiers.is_shifted() {
407407
DecodedKey::Unicode('.')
408408
} else {
409409
DecodedKey::Unicode(';')
410410
}
411411
}
412-
KeyCode::Fullstop => {
412+
KeyCode::OemPeriod => {
413413
if modifiers.is_shifted() {
414414
DecodedKey::Unicode('/')
415415
} else {
416416
DecodedKey::Unicode(':')
417417
}
418418
}
419-
KeyCode::Slash => {
419+
KeyCode::Oem2 => {
420420
if modifiers.is_shifted() {
421421
DecodedKey::Unicode('§')
422422
} else {
@@ -425,9 +425,9 @@ impl KeyboardLayout for Azerty {
425425
}
426426
KeyCode::Spacebar => DecodedKey::Unicode(' '),
427427
KeyCode::Delete => DecodedKey::Unicode(127.into()),
428-
KeyCode::NumpadSlash => DecodedKey::Unicode('/'),
429-
KeyCode::NumpadStar => DecodedKey::Unicode('*'),
430-
KeyCode::NumpadMinus => DecodedKey::Unicode('-'),
428+
KeyCode::NumpadDivide => DecodedKey::Unicode('/'),
429+
KeyCode::NumpadMultiply => DecodedKey::Unicode('*'),
430+
KeyCode::NumpadSubtract => DecodedKey::Unicode('-'),
431431
KeyCode::Numpad7 => {
432432
if modifiers.numlock {
433433
DecodedKey::Unicode('7')
@@ -449,7 +449,7 @@ impl KeyboardLayout for Azerty {
449449
DecodedKey::RawKey(KeyCode::PageUp)
450450
}
451451
}
452-
KeyCode::NumpadPlus => DecodedKey::Unicode('+'),
452+
KeyCode::NumpadAdd => DecodedKey::Unicode('+'),
453453
KeyCode::Numpad4 => {
454454
if modifiers.numlock {
455455
DecodedKey::Unicode('4')
@@ -501,8 +501,59 @@ impl KeyboardLayout for Azerty {
501501
}
502502
}
503503
KeyCode::NumpadEnter => DecodedKey::Unicode(10.into()),
504-
KeyCode::ShiftLeft => DecodedKey::Unicode('<'),
504+
KeyCode::LShift => DecodedKey::Unicode('<'),
505505
k => DecodedKey::RawKey(k),
506506
}
507507
}
508508
}
509+
510+
#[cfg(test)]
511+
mod test {
512+
use super::*;
513+
use crate::{KeyCode, KeyEvent, KeyState, Keyboard, ScancodeSet2};
514+
515+
#[test]
516+
fn test_frazert() {
517+
let mut k = Keyboard::<Azerty, ScancodeSet2>::new(HandleControl::MapLettersToUnicode);
518+
assert_eq!(
519+
k.process_keyevent(KeyEvent::new(KeyCode::NumpadDivide, KeyState::Down)),
520+
Some(DecodedKey::Unicode('/'))
521+
);
522+
assert_eq!(
523+
k.process_keyevent(KeyEvent::new(KeyCode::NumpadMultiply, KeyState::Down)),
524+
Some(DecodedKey::Unicode('*'))
525+
);
526+
assert_eq!(
527+
k.process_keyevent(KeyEvent::new(KeyCode::A, KeyState::Down)),
528+
Some(DecodedKey::Unicode('q'))
529+
);
530+
assert_eq!(
531+
k.process_keyevent(KeyEvent::new(KeyCode::Key4, KeyState::Down)),
532+
Some(DecodedKey::Unicode('\''))
533+
);
534+
assert_eq!(
535+
k.process_keyevent(KeyEvent::new(KeyCode::Oem7, KeyState::Down)),
536+
Some(DecodedKey::Unicode('*'))
537+
);
538+
assert_eq!(
539+
k.process_keyevent(KeyEvent::new(KeyCode::Numpad0, KeyState::Up)),
540+
None
541+
);
542+
assert_eq!(
543+
k.process_keyevent(KeyEvent::new(KeyCode::NumpadLock, KeyState::Down)),
544+
None
545+
);
546+
assert_eq!(
547+
k.process_keyevent(KeyEvent::new(KeyCode::NumpadLock, KeyState::Up)),
548+
None
549+
);
550+
assert_eq!(
551+
k.process_keyevent(KeyEvent::new(KeyCode::Numpad0, KeyState::Down)),
552+
Some(DecodedKey::RawKey(KeyCode::Insert))
553+
);
554+
assert_eq!(
555+
k.process_keyevent(KeyEvent::new(KeyCode::Numpad0, KeyState::Up)),
556+
None
557+
);
558+
}
559+
}

src/layouts/colemak.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ impl KeyboardLayout for Colemak {
1313
) -> DecodedKey {
1414
let map_to_unicode = handle_ctrl == HandleControl::MapLettersToUnicode;
1515
match keycode {
16-
KeyCode::BackTick => {
16+
KeyCode::Oem8 => {
1717
if modifiers.is_shifted() {
1818
DecodedKey::Unicode('~')
1919
} else {
@@ -91,14 +91,14 @@ impl KeyboardLayout for Colemak {
9191
DecodedKey::Unicode('0')
9292
}
9393
}
94-
KeyCode::Minus => {
94+
KeyCode::OemMinus => {
9595
if modifiers.is_shifted() {
9696
DecodedKey::Unicode('_')
9797
} else {
9898
DecodedKey::Unicode('-')
9999
}
100100
}
101-
KeyCode::Equals => {
101+
KeyCode::OemPlus => {
102102
if modifiers.is_shifted() {
103103
DecodedKey::Unicode('+')
104104
} else {
@@ -195,21 +195,21 @@ impl KeyboardLayout for Colemak {
195195
DecodedKey::Unicode(';')
196196
}
197197
}
198-
KeyCode::BracketSquareLeft => {
198+
KeyCode::Oem4 => {
199199
if modifiers.is_shifted() {
200200
DecodedKey::Unicode('{')
201201
} else {
202202
DecodedKey::Unicode('[')
203203
}
204204
}
205-
KeyCode::BracketSquareRight => {
205+
KeyCode::Oem6 => {
206206
if modifiers.is_shifted() {
207207
DecodedKey::Unicode('}')
208208
} else {
209209
DecodedKey::Unicode(']')
210210
}
211211
}
212-
KeyCode::BackSlash => {
212+
KeyCode::Oem7 => {
213213
if modifiers.is_shifted() {
214214
DecodedKey::Unicode('|')
215215
} else {
@@ -297,7 +297,7 @@ impl KeyboardLayout for Colemak {
297297
DecodedKey::Unicode('i')
298298
}
299299
}
300-
KeyCode::SemiColon => {
300+
KeyCode::Oem1 => {
301301
if map_to_unicode && modifiers.is_ctrl() {
302302
DecodedKey::Unicode('\u{000F}')
303303
} else if modifiers.is_shifted() {
@@ -306,15 +306,15 @@ impl KeyboardLayout for Colemak {
306306
DecodedKey::Unicode('o')
307307
}
308308
}
309-
KeyCode::Quote => {
309+
KeyCode::Oem3 => {
310310
if modifiers.is_shifted() {
311311
DecodedKey::Unicode('"')
312312
} else {
313313
DecodedKey::Unicode('\'')
314314
}
315315
}
316316
// Enter gives LF, not CRLF or CR
317-
KeyCode::Enter => DecodedKey::Unicode(10.into()),
317+
KeyCode::Return => DecodedKey::Unicode(10.into()),
318318
KeyCode::Z => {
319319
if map_to_unicode && modifiers.is_ctrl() {
320320
DecodedKey::Unicode('\u{001A}')
@@ -378,21 +378,21 @@ impl KeyboardLayout for Colemak {
378378
DecodedKey::Unicode('m')
379379
}
380380
}
381-
KeyCode::Comma => {
381+
KeyCode::OemComma => {
382382
if modifiers.is_shifted() {
383383
DecodedKey::Unicode('<')
384384
} else {
385385
DecodedKey::Unicode(',')
386386
}
387387
}
388-
KeyCode::Fullstop => {
388+
KeyCode::OemPeriod => {
389389
if modifiers.is_shifted() {
390390
DecodedKey::Unicode('>')
391391
} else {
392392
DecodedKey::Unicode('.')
393393
}
394394
}
395-
KeyCode::Slash => {
395+
KeyCode::Oem2 => {
396396
if modifiers.is_shifted() {
397397
DecodedKey::Unicode('?')
398398
} else {
@@ -401,9 +401,9 @@ impl KeyboardLayout for Colemak {
401401
}
402402
KeyCode::Spacebar => DecodedKey::Unicode(' '),
403403
KeyCode::Delete => DecodedKey::Unicode(127.into()),
404-
KeyCode::NumpadSlash => DecodedKey::Unicode('/'),
405-
KeyCode::NumpadStar => DecodedKey::Unicode('*'),
406-
KeyCode::NumpadMinus => DecodedKey::Unicode('-'),
404+
KeyCode::NumpadDivide => DecodedKey::Unicode('/'),
405+
KeyCode::NumpadMultiply => DecodedKey::Unicode('*'),
406+
KeyCode::NumpadSubtract => DecodedKey::Unicode('-'),
407407
KeyCode::Numpad7 => {
408408
if modifiers.numlock {
409409
DecodedKey::Unicode('7')
@@ -425,7 +425,7 @@ impl KeyboardLayout for Colemak {
425425
DecodedKey::RawKey(KeyCode::PageUp)
426426
}
427427
}
428-
KeyCode::NumpadPlus => DecodedKey::Unicode('+'),
428+
KeyCode::NumpadAdd => DecodedKey::Unicode('+'),
429429
KeyCode::Numpad4 => {
430430
if modifiers.numlock {
431431
DecodedKey::Unicode('4')

0 commit comments

Comments
 (0)