Skip to content

Add Dvorak layout #6

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

Merged
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ output directly).
## Supports:

* Scancode Set 1 and 2
* Dvorak 104-key layout
* US 104-key layout
* UK 105-key layout
* JIS 109-key layout
Expand Down
300 changes: 300 additions & 0 deletions src/layouts/dvorak104.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,300 @@
//! A Dvorak 101-key (or 104-key including Windows keys) keyboard.
//! Has a 1-row high Enter key, with Backslash above.

use crate::{DecodedKey, HandleControl, KeyCode, KeyboardLayout, Modifiers};

pub use super::us104::Us104Key;

pub struct Dvorak104Key;

impl KeyboardLayout for Dvorak104Key {
fn map_keycode(
keycode: KeyCode,
modifiers: &Modifiers,
handle_ctrl: HandleControl,
) -> DecodedKey {
let map_to_unicode = handle_ctrl == HandleControl::MapLettersToUnicode;
match keycode {
KeyCode::Minus => {
if modifiers.is_shifted() {
DecodedKey::Unicode('{')
} else {
DecodedKey::Unicode('[')
}
}
KeyCode::Equals => {
if modifiers.is_shifted() {
DecodedKey::Unicode('}')
} else {
DecodedKey::Unicode(']')
}
}
KeyCode::Q => {
if modifiers.is_shifted() {
DecodedKey::Unicode('"')
} else {
DecodedKey::Unicode('\'')
}
}
KeyCode::W => {
if modifiers.is_shifted() {
DecodedKey::Unicode('<')
} else {
DecodedKey::Unicode(',')
}
}
KeyCode::E => {
if modifiers.is_shifted() {
DecodedKey::Unicode('>')
} else {
DecodedKey::Unicode('.')
}
}
KeyCode::R => {
if map_to_unicode && modifiers.is_ctrl() {
DecodedKey::Unicode('\u{0010}')
} else if modifiers.is_caps() {
DecodedKey::Unicode('P')
} else {
DecodedKey::Unicode('p')
}
}
KeyCode::T => {
if map_to_unicode && modifiers.is_ctrl() {
DecodedKey::Unicode('\u{0019}')
} else if modifiers.is_caps() {
DecodedKey::Unicode('Y')
} else {
DecodedKey::Unicode('y')
}
}
KeyCode::Y => {
if map_to_unicode && modifiers.is_ctrl() {
DecodedKey::Unicode('\u{0006}')
} else if modifiers.is_caps() {
DecodedKey::Unicode('F')
} else {
DecodedKey::Unicode('f')
}
}
KeyCode::U => {
if map_to_unicode && modifiers.is_ctrl() {
DecodedKey::Unicode('\u{0007}')
} else if modifiers.is_caps() {
DecodedKey::Unicode('G')
} else {
DecodedKey::Unicode('g')
}
}
KeyCode::I => {
if map_to_unicode && modifiers.is_ctrl() {
DecodedKey::Unicode('\u{0003}')
} else if modifiers.is_caps() {
DecodedKey::Unicode('C')
} else {
DecodedKey::Unicode('c')
}
}
KeyCode::O => {
if map_to_unicode && modifiers.is_ctrl() {
DecodedKey::Unicode('\u{0012}')
} else if modifiers.is_caps() {
DecodedKey::Unicode('R')
} else {
DecodedKey::Unicode('r')
}
}
KeyCode::P => {
if map_to_unicode && modifiers.is_ctrl() {
DecodedKey::Unicode('\u{000C}')
} else if modifiers.is_caps() {
DecodedKey::Unicode('L')
} else {
DecodedKey::Unicode('l')
}
}
KeyCode::BracketSquareLeft => {
if modifiers.is_shifted() {
DecodedKey::Unicode('?')
} else {
DecodedKey::Unicode('/')
}
}
KeyCode::BracketSquareRight => {
if modifiers.is_shifted() {
DecodedKey::Unicode('+')
} else {
DecodedKey::Unicode('=')
}
}
KeyCode::S => {
if map_to_unicode && modifiers.is_ctrl() {
DecodedKey::Unicode('\u{000F}')
} else if modifiers.is_caps() {
DecodedKey::Unicode('O')
} else {
DecodedKey::Unicode('o')
}
}
KeyCode::D => {
if map_to_unicode && modifiers.is_ctrl() {
DecodedKey::Unicode('\u{0005}')
} else if modifiers.is_caps() {
DecodedKey::Unicode('E')
} else {
DecodedKey::Unicode('e')
}
}
KeyCode::F => {
if map_to_unicode && modifiers.is_ctrl() {
DecodedKey::Unicode('\u{0015}')
} else if modifiers.is_caps() {
DecodedKey::Unicode('U')
} else {
DecodedKey::Unicode('u')
}
}
KeyCode::G => {
if map_to_unicode && modifiers.is_ctrl() {
DecodedKey::Unicode('\u{0009}')
} else if modifiers.is_caps() {
DecodedKey::Unicode('I')
} else {
DecodedKey::Unicode('i')
}
}
KeyCode::H => {
if map_to_unicode && modifiers.is_ctrl() {
DecodedKey::Unicode('\u{0004}')
} else if modifiers.is_caps() {
DecodedKey::Unicode('D')
} else {
DecodedKey::Unicode('d')
}
}
KeyCode::J => {
if map_to_unicode && modifiers.is_ctrl() {
DecodedKey::Unicode('\u{0008}')
} else if modifiers.is_caps() {
DecodedKey::Unicode('H')
} else {
DecodedKey::Unicode('h')
}
}
KeyCode::K => {
if map_to_unicode && modifiers.is_ctrl() {
DecodedKey::Unicode('\u{0014}')
} else if modifiers.is_caps() {
DecodedKey::Unicode('T')
} else {
DecodedKey::Unicode('t')
}
}
KeyCode::L => {
if map_to_unicode && modifiers.is_ctrl() {
DecodedKey::Unicode('\u{000E}')
} else if modifiers.is_caps() {
DecodedKey::Unicode('N')
} else {
DecodedKey::Unicode('n')
}
}
KeyCode::SemiColon => {
if map_to_unicode && modifiers.is_ctrl() {
DecodedKey::Unicode('\u{0013}')
} else if modifiers.is_caps() {
DecodedKey::Unicode('S')
} else {
DecodedKey::Unicode('s')
}
}
KeyCode::Quote => {
if modifiers.is_shifted() {
DecodedKey::Unicode('_')
} else {
DecodedKey::Unicode('-')
}
}
KeyCode::Z => {
if modifiers.is_shifted() {
DecodedKey::Unicode(':')
} else {
DecodedKey::Unicode(';')
}
}
KeyCode::X => {
if map_to_unicode && modifiers.is_ctrl() {
DecodedKey::Unicode('\u{0011}')
} else if modifiers.is_caps() {
DecodedKey::Unicode('Q')
} else {
DecodedKey::Unicode('q')
}
}
KeyCode::C => {
if map_to_unicode && modifiers.is_ctrl() {
DecodedKey::Unicode('\u{000A}')
} else if modifiers.is_caps() {
DecodedKey::Unicode('J')
} else {
DecodedKey::Unicode('j')
}
}
KeyCode::V => {
if map_to_unicode && modifiers.is_ctrl() {
DecodedKey::Unicode('\u{000B}')
} else if modifiers.is_caps() {
DecodedKey::Unicode('K')
} else {
DecodedKey::Unicode('k')
}
}
KeyCode::B => {
if map_to_unicode && modifiers.is_ctrl() {
DecodedKey::Unicode('\u{0018}')
} else if modifiers.is_caps() {
DecodedKey::Unicode('X')
} else {
DecodedKey::Unicode('x')
}
}
KeyCode::N => {
if map_to_unicode && modifiers.is_ctrl() {
DecodedKey::Unicode('\u{0002}')
} else if modifiers.is_caps() {
DecodedKey::Unicode('B')
} else {
DecodedKey::Unicode('b')
}
}
KeyCode::Comma => {
if map_to_unicode && modifiers.is_ctrl() {
DecodedKey::Unicode('\u{0017}')
} else if modifiers.is_caps() {
DecodedKey::Unicode('W')
} else {
DecodedKey::Unicode('w')
}
}
KeyCode::Fullstop => {
if map_to_unicode && modifiers.is_ctrl() {
DecodedKey::Unicode('\u{0016}')
} else if modifiers.is_caps() {
DecodedKey::Unicode('V')
} else {
DecodedKey::Unicode('v')
}
}
KeyCode::Slash => {
if map_to_unicode && modifiers.is_ctrl() {
DecodedKey::Unicode('\u{001A}')
} else if modifiers.is_caps() {
DecodedKey::Unicode('Z')
} else {
DecodedKey::Unicode('z')
}
}
e => <super::Us104Key as KeyboardLayout>::map_keycode(e, modifiers, handle_ctrl),
}
}
}
5 changes: 4 additions & 1 deletion src/layouts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
//! handle all the 'different' keys first, and then jump to another handler -
//! see UK105 and US104 as an example of that.

mod dvorak104;
pub use self::dvorak104::Dvorak104Key;

mod us104;
pub use self::us104::Us104Key;

mod uk105;
pub use self::uk105::Uk105Key;

mod jis109;
pub use self::jis109::Jis109Key;
pub use self::jis109::Jis109Key;