Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix UK Hash and Backslash mixup #27

Merged
merged 6 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## Unreleased

* Changed ordering of `enum KeyCode` and names of several of the keys
* Support the mysterious 'Right Control 2' and 'Right Alt 2' so that Pause/Break
and Print Screen do the right thing.
* Fix the Backslash/Tilde swap on the UK Layout.

## v0.6.1 (20 October 2022)

* Fix Control-Letter codes on AZERTY
Expand Down
87 changes: 69 additions & 18 deletions src/layouts/azerty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ impl KeyboardLayout for Azerty {
let map_to_unicode = handle_ctrl == HandleControl::MapLettersToUnicode;
match keycode {
KeyCode::Escape => DecodedKey::Unicode(0x1B.into()),
KeyCode::BackTick => DecodedKey::Unicode('²'),
KeyCode::HashTilde => {
KeyCode::Oem8 => DecodedKey::Unicode('²'),
KeyCode::Oem5 => {
if modifiers.is_shifted() {
DecodedKey::Unicode('*')
} else {
Expand Down Expand Up @@ -107,7 +107,7 @@ impl KeyboardLayout for Azerty {
DecodedKey::Unicode('à')
}
}
KeyCode::Minus => {
KeyCode::OemMinus => {
if modifiers.is_shifted() {
DecodedKey::Unicode('°')
} else if modifiers.alt_gr {
Expand All @@ -116,7 +116,7 @@ impl KeyboardLayout for Azerty {
DecodedKey::Unicode(')')
}
}
KeyCode::Equals => {
KeyCode::OemPlus => {
if modifiers.is_shifted() {
DecodedKey::Unicode('+')
} else if modifiers.alt_gr {
Expand Down Expand Up @@ -217,7 +217,7 @@ impl KeyboardLayout for Azerty {
DecodedKey::Unicode('p')
}
}
KeyCode::BracketSquareLeft => {
KeyCode::Oem4 => {
if modifiers.is_shifted() {
DecodedKey::Unicode('¨')
} else if modifiers.alt_gr {
Expand All @@ -226,7 +226,7 @@ impl KeyboardLayout for Azerty {
DecodedKey::Unicode('^')
}
}
KeyCode::BracketSquareRight => {
KeyCode::Oem6 => {
if modifiers.is_shifted() {
DecodedKey::Unicode('£')
} else if modifiers.alt_gr {
Expand All @@ -235,7 +235,7 @@ impl KeyboardLayout for Azerty {
DecodedKey::Unicode('$')
}
}
KeyCode::BackSlash => {
KeyCode::Oem7 => {
if modifiers.is_shifted() {
DecodedKey::Unicode('µ')
} else {
Expand Down Expand Up @@ -323,7 +323,7 @@ impl KeyboardLayout for Azerty {
DecodedKey::Unicode('l')
}
}
KeyCode::SemiColon => {
KeyCode::Oem1 => {
if map_to_unicode && modifiers.is_ctrl() {
DecodedKey::Unicode('\u{000D}')
} else if modifiers.is_caps() {
Expand All @@ -332,15 +332,15 @@ impl KeyboardLayout for Azerty {
DecodedKey::Unicode('m')
}
}
KeyCode::Quote => {
KeyCode::Oem3 => {
if modifiers.is_shifted() {
DecodedKey::Unicode('%')
} else {
DecodedKey::Unicode('ù')
}
}
// Enter gives LF, not CRLF or CR
KeyCode::Enter => DecodedKey::Unicode(10.into()),
KeyCode::Return => DecodedKey::Unicode(10.into()),
KeyCode::Z => {
if map_to_unicode && modifiers.is_ctrl() {
DecodedKey::Unicode('\u{0017}')
Expand Down Expand Up @@ -402,21 +402,21 @@ impl KeyboardLayout for Azerty {
DecodedKey::Unicode(',')
}
}
KeyCode::Comma => {
KeyCode::OemComma => {
if modifiers.is_shifted() {
DecodedKey::Unicode('.')
} else {
DecodedKey::Unicode(';')
}
}
KeyCode::Fullstop => {
KeyCode::OemPeriod => {
if modifiers.is_shifted() {
DecodedKey::Unicode('/')
} else {
DecodedKey::Unicode(':')
}
}
KeyCode::Slash => {
KeyCode::Oem2 => {
if modifiers.is_shifted() {
DecodedKey::Unicode('§')
} else {
Expand All @@ -425,9 +425,9 @@ impl KeyboardLayout for Azerty {
}
KeyCode::Spacebar => DecodedKey::Unicode(' '),
KeyCode::Delete => DecodedKey::Unicode(127.into()),
KeyCode::NumpadSlash => DecodedKey::Unicode('/'),
KeyCode::NumpadStar => DecodedKey::Unicode('*'),
KeyCode::NumpadMinus => DecodedKey::Unicode('-'),
KeyCode::NumpadDivide => DecodedKey::Unicode('/'),
KeyCode::NumpadMultiply => DecodedKey::Unicode('*'),
KeyCode::NumpadSubtract => DecodedKey::Unicode('-'),
KeyCode::Numpad7 => {
if modifiers.numlock {
DecodedKey::Unicode('7')
Expand All @@ -449,7 +449,7 @@ impl KeyboardLayout for Azerty {
DecodedKey::RawKey(KeyCode::PageUp)
}
}
KeyCode::NumpadPlus => DecodedKey::Unicode('+'),
KeyCode::NumpadAdd => DecodedKey::Unicode('+'),
KeyCode::Numpad4 => {
if modifiers.numlock {
DecodedKey::Unicode('4')
Expand Down Expand Up @@ -501,8 +501,59 @@ impl KeyboardLayout for Azerty {
}
}
KeyCode::NumpadEnter => DecodedKey::Unicode(10.into()),
KeyCode::ShiftLeft => DecodedKey::Unicode('<'),
KeyCode::LShift => DecodedKey::Unicode('<'),
k => DecodedKey::RawKey(k),
}
}
}

#[cfg(test)]
mod test {
use super::*;
use crate::{KeyCode, KeyEvent, KeyState, Keyboard, ScancodeSet2};

#[test]
fn test_frazert() {
let mut k = Keyboard::<Azerty, ScancodeSet2>::new(HandleControl::MapLettersToUnicode);
assert_eq!(
k.process_keyevent(KeyEvent::new(KeyCode::NumpadDivide, KeyState::Down)),
Some(DecodedKey::Unicode('/'))
);
assert_eq!(
k.process_keyevent(KeyEvent::new(KeyCode::NumpadMultiply, KeyState::Down)),
Some(DecodedKey::Unicode('*'))
);
assert_eq!(
k.process_keyevent(KeyEvent::new(KeyCode::A, KeyState::Down)),
Some(DecodedKey::Unicode('q'))
);
assert_eq!(
k.process_keyevent(KeyEvent::new(KeyCode::Key4, KeyState::Down)),
Some(DecodedKey::Unicode('\''))
);
assert_eq!(
k.process_keyevent(KeyEvent::new(KeyCode::Oem7, KeyState::Down)),
Some(DecodedKey::Unicode('*'))
);
assert_eq!(
k.process_keyevent(KeyEvent::new(KeyCode::Numpad0, KeyState::Up)),
None
);
assert_eq!(
k.process_keyevent(KeyEvent::new(KeyCode::NumpadLock, KeyState::Down)),
None
);
assert_eq!(
k.process_keyevent(KeyEvent::new(KeyCode::NumpadLock, KeyState::Up)),
None
);
assert_eq!(
k.process_keyevent(KeyEvent::new(KeyCode::Numpad0, KeyState::Down)),
Some(DecodedKey::RawKey(KeyCode::Insert))
);
assert_eq!(
k.process_keyevent(KeyEvent::new(KeyCode::Numpad0, KeyState::Up)),
None
);
}
}
32 changes: 16 additions & 16 deletions src/layouts/colemak.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl KeyboardLayout for Colemak {
) -> DecodedKey {
let map_to_unicode = handle_ctrl == HandleControl::MapLettersToUnicode;
match keycode {
KeyCode::BackTick => {
KeyCode::Oem8 => {
if modifiers.is_shifted() {
DecodedKey::Unicode('~')
} else {
Expand Down Expand Up @@ -91,14 +91,14 @@ impl KeyboardLayout for Colemak {
DecodedKey::Unicode('0')
}
}
KeyCode::Minus => {
KeyCode::OemMinus => {
if modifiers.is_shifted() {
DecodedKey::Unicode('_')
} else {
DecodedKey::Unicode('-')
}
}
KeyCode::Equals => {
KeyCode::OemPlus => {
if modifiers.is_shifted() {
DecodedKey::Unicode('+')
} else {
Expand Down Expand Up @@ -195,21 +195,21 @@ impl KeyboardLayout for Colemak {
DecodedKey::Unicode(';')
}
}
KeyCode::BracketSquareLeft => {
KeyCode::Oem4 => {
if modifiers.is_shifted() {
DecodedKey::Unicode('{')
} else {
DecodedKey::Unicode('[')
}
}
KeyCode::BracketSquareRight => {
KeyCode::Oem6 => {
if modifiers.is_shifted() {
DecodedKey::Unicode('}')
} else {
DecodedKey::Unicode(']')
}
}
KeyCode::BackSlash => {
KeyCode::Oem7 => {
if modifiers.is_shifted() {
DecodedKey::Unicode('|')
} else {
Expand Down Expand Up @@ -297,7 +297,7 @@ impl KeyboardLayout for Colemak {
DecodedKey::Unicode('i')
}
}
KeyCode::SemiColon => {
KeyCode::Oem1 => {
if map_to_unicode && modifiers.is_ctrl() {
DecodedKey::Unicode('\u{000F}')
} else if modifiers.is_shifted() {
Expand All @@ -306,15 +306,15 @@ impl KeyboardLayout for Colemak {
DecodedKey::Unicode('o')
}
}
KeyCode::Quote => {
KeyCode::Oem3 => {
if modifiers.is_shifted() {
DecodedKey::Unicode('"')
} else {
DecodedKey::Unicode('\'')
}
}
// Enter gives LF, not CRLF or CR
KeyCode::Enter => DecodedKey::Unicode(10.into()),
KeyCode::Return => DecodedKey::Unicode(10.into()),
KeyCode::Z => {
if map_to_unicode && modifiers.is_ctrl() {
DecodedKey::Unicode('\u{001A}')
Expand Down Expand Up @@ -378,21 +378,21 @@ impl KeyboardLayout for Colemak {
DecodedKey::Unicode('m')
}
}
KeyCode::Comma => {
KeyCode::OemComma => {
if modifiers.is_shifted() {
DecodedKey::Unicode('<')
} else {
DecodedKey::Unicode(',')
}
}
KeyCode::Fullstop => {
KeyCode::OemPeriod => {
if modifiers.is_shifted() {
DecodedKey::Unicode('>')
} else {
DecodedKey::Unicode('.')
}
}
KeyCode::Slash => {
KeyCode::Oem2 => {
if modifiers.is_shifted() {
DecodedKey::Unicode('?')
} else {
Expand All @@ -401,9 +401,9 @@ impl KeyboardLayout for Colemak {
}
KeyCode::Spacebar => DecodedKey::Unicode(' '),
KeyCode::Delete => DecodedKey::Unicode(127.into()),
KeyCode::NumpadSlash => DecodedKey::Unicode('/'),
KeyCode::NumpadStar => DecodedKey::Unicode('*'),
KeyCode::NumpadMinus => DecodedKey::Unicode('-'),
KeyCode::NumpadDivide => DecodedKey::Unicode('/'),
KeyCode::NumpadMultiply => DecodedKey::Unicode('*'),
KeyCode::NumpadSubtract => DecodedKey::Unicode('-'),
KeyCode::Numpad7 => {
if modifiers.numlock {
DecodedKey::Unicode('7')
Expand All @@ -425,7 +425,7 @@ impl KeyboardLayout for Colemak {
DecodedKey::RawKey(KeyCode::PageUp)
}
}
KeyCode::NumpadPlus => DecodedKey::Unicode('+'),
KeyCode::NumpadAdd => DecodedKey::Unicode('+'),
KeyCode::Numpad4 => {
if modifiers.numlock {
DecodedKey::Unicode('4')
Expand Down
Loading