|
| 1 | +//! A Dvorak 101-key (or 104-key including Windows keys) keyboard. |
| 2 | +//! Has a 1-row high Enter key, with Backslash above. |
| 3 | +
|
| 4 | +use crate::{DecodedKey, HandleControl, KeyCode, KeyboardLayout, Modifiers}; |
| 5 | + |
| 6 | +pub use super::us104::Us104Key; |
| 7 | + |
| 8 | +pub struct Dvorak104Key; |
| 9 | + |
| 10 | +impl KeyboardLayout for Dvorak104Key { |
| 11 | + fn map_keycode( |
| 12 | + keycode: KeyCode, |
| 13 | + modifiers: &Modifiers, |
| 14 | + handle_ctrl: HandleControl, |
| 15 | + ) -> DecodedKey { |
| 16 | + let map_to_unicode = handle_ctrl == HandleControl::MapLettersToUnicode; |
| 17 | + match keycode { |
| 18 | + KeyCode::Minus => { |
| 19 | + if modifiers.is_shifted() { |
| 20 | + DecodedKey::Unicode('{') |
| 21 | + } else { |
| 22 | + DecodedKey::Unicode('[') |
| 23 | + } |
| 24 | + } |
| 25 | + KeyCode::Equals => { |
| 26 | + if modifiers.is_shifted() { |
| 27 | + DecodedKey::Unicode('}') |
| 28 | + } else { |
| 29 | + DecodedKey::Unicode(']') |
| 30 | + } |
| 31 | + } |
| 32 | + KeyCode::Q => { |
| 33 | + if modifiers.is_shifted() { |
| 34 | + DecodedKey::Unicode('"') |
| 35 | + } else { |
| 36 | + DecodedKey::Unicode('\'') |
| 37 | + } |
| 38 | + } |
| 39 | + KeyCode::W => { |
| 40 | + if modifiers.is_shifted() { |
| 41 | + DecodedKey::Unicode('<') |
| 42 | + } else { |
| 43 | + DecodedKey::Unicode(',') |
| 44 | + } |
| 45 | + } |
| 46 | + KeyCode::E => { |
| 47 | + if modifiers.is_shifted() { |
| 48 | + DecodedKey::Unicode('>') |
| 49 | + } else { |
| 50 | + DecodedKey::Unicode('.') |
| 51 | + } |
| 52 | + } |
| 53 | + KeyCode::R => { |
| 54 | + if map_to_unicode && modifiers.is_ctrl() { |
| 55 | + DecodedKey::Unicode('\u{0010}') |
| 56 | + } else if modifiers.is_caps() { |
| 57 | + DecodedKey::Unicode('P') |
| 58 | + } else { |
| 59 | + DecodedKey::Unicode('p') |
| 60 | + } |
| 61 | + } |
| 62 | + KeyCode::T => { |
| 63 | + if map_to_unicode && modifiers.is_ctrl() { |
| 64 | + DecodedKey::Unicode('\u{0019}') |
| 65 | + } else if modifiers.is_caps() { |
| 66 | + DecodedKey::Unicode('Y') |
| 67 | + } else { |
| 68 | + DecodedKey::Unicode('y') |
| 69 | + } |
| 70 | + } |
| 71 | + KeyCode::Y => { |
| 72 | + if map_to_unicode && modifiers.is_ctrl() { |
| 73 | + DecodedKey::Unicode('\u{0006}') |
| 74 | + } else if modifiers.is_caps() { |
| 75 | + DecodedKey::Unicode('F') |
| 76 | + } else { |
| 77 | + DecodedKey::Unicode('f') |
| 78 | + } |
| 79 | + } |
| 80 | + KeyCode::U => { |
| 81 | + if map_to_unicode && modifiers.is_ctrl() { |
| 82 | + DecodedKey::Unicode('\u{0007}') |
| 83 | + } else if modifiers.is_caps() { |
| 84 | + DecodedKey::Unicode('G') |
| 85 | + } else { |
| 86 | + DecodedKey::Unicode('g') |
| 87 | + } |
| 88 | + } |
| 89 | + KeyCode::I => { |
| 90 | + if map_to_unicode && modifiers.is_ctrl() { |
| 91 | + DecodedKey::Unicode('\u{0003}') |
| 92 | + } else if modifiers.is_caps() { |
| 93 | + DecodedKey::Unicode('C') |
| 94 | + } else { |
| 95 | + DecodedKey::Unicode('c') |
| 96 | + } |
| 97 | + } |
| 98 | + KeyCode::O => { |
| 99 | + if map_to_unicode && modifiers.is_ctrl() { |
| 100 | + DecodedKey::Unicode('\u{0012}') |
| 101 | + } else if modifiers.is_caps() { |
| 102 | + DecodedKey::Unicode('R') |
| 103 | + } else { |
| 104 | + DecodedKey::Unicode('r') |
| 105 | + } |
| 106 | + } |
| 107 | + KeyCode::P => { |
| 108 | + if map_to_unicode && modifiers.is_ctrl() { |
| 109 | + DecodedKey::Unicode('\u{000C}') |
| 110 | + } else if modifiers.is_caps() { |
| 111 | + DecodedKey::Unicode('L') |
| 112 | + } else { |
| 113 | + DecodedKey::Unicode('l') |
| 114 | + } |
| 115 | + } |
| 116 | + KeyCode::BracketSquareLeft => { |
| 117 | + if modifiers.is_shifted() { |
| 118 | + DecodedKey::Unicode('?') |
| 119 | + } else { |
| 120 | + DecodedKey::Unicode('/') |
| 121 | + } |
| 122 | + } |
| 123 | + KeyCode::BracketSquareRight => { |
| 124 | + if modifiers.is_shifted() { |
| 125 | + DecodedKey::Unicode('+') |
| 126 | + } else { |
| 127 | + DecodedKey::Unicode('=') |
| 128 | + } |
| 129 | + } |
| 130 | + KeyCode::S => { |
| 131 | + if map_to_unicode && modifiers.is_ctrl() { |
| 132 | + DecodedKey::Unicode('\u{000F}') |
| 133 | + } else if modifiers.is_caps() { |
| 134 | + DecodedKey::Unicode('O') |
| 135 | + } else { |
| 136 | + DecodedKey::Unicode('o') |
| 137 | + } |
| 138 | + } |
| 139 | + KeyCode::D => { |
| 140 | + if map_to_unicode && modifiers.is_ctrl() { |
| 141 | + DecodedKey::Unicode('\u{0005}') |
| 142 | + } else if modifiers.is_caps() { |
| 143 | + DecodedKey::Unicode('E') |
| 144 | + } else { |
| 145 | + DecodedKey::Unicode('e') |
| 146 | + } |
| 147 | + } |
| 148 | + KeyCode::F => { |
| 149 | + if map_to_unicode && modifiers.is_ctrl() { |
| 150 | + DecodedKey::Unicode('\u{0015}') |
| 151 | + } else if modifiers.is_caps() { |
| 152 | + DecodedKey::Unicode('U') |
| 153 | + } else { |
| 154 | + DecodedKey::Unicode('u') |
| 155 | + } |
| 156 | + } |
| 157 | + KeyCode::G => { |
| 158 | + if map_to_unicode && modifiers.is_ctrl() { |
| 159 | + DecodedKey::Unicode('\u{0009}') |
| 160 | + } else if modifiers.is_caps() { |
| 161 | + DecodedKey::Unicode('I') |
| 162 | + } else { |
| 163 | + DecodedKey::Unicode('i') |
| 164 | + } |
| 165 | + } |
| 166 | + KeyCode::H => { |
| 167 | + if map_to_unicode && modifiers.is_ctrl() { |
| 168 | + DecodedKey::Unicode('\u{0004}') |
| 169 | + } else if modifiers.is_caps() { |
| 170 | + DecodedKey::Unicode('D') |
| 171 | + } else { |
| 172 | + DecodedKey::Unicode('d') |
| 173 | + } |
| 174 | + } |
| 175 | + KeyCode::J => { |
| 176 | + if map_to_unicode && modifiers.is_ctrl() { |
| 177 | + DecodedKey::Unicode('\u{0008}') |
| 178 | + } else if modifiers.is_caps() { |
| 179 | + DecodedKey::Unicode('H') |
| 180 | + } else { |
| 181 | + DecodedKey::Unicode('h') |
| 182 | + } |
| 183 | + } |
| 184 | + KeyCode::K => { |
| 185 | + if map_to_unicode && modifiers.is_ctrl() { |
| 186 | + DecodedKey::Unicode('\u{0014}') |
| 187 | + } else if modifiers.is_caps() { |
| 188 | + DecodedKey::Unicode('T') |
| 189 | + } else { |
| 190 | + DecodedKey::Unicode('t') |
| 191 | + } |
| 192 | + } |
| 193 | + KeyCode::L => { |
| 194 | + if map_to_unicode && modifiers.is_ctrl() { |
| 195 | + DecodedKey::Unicode('\u{000E}') |
| 196 | + } else if modifiers.is_caps() { |
| 197 | + DecodedKey::Unicode('N') |
| 198 | + } else { |
| 199 | + DecodedKey::Unicode('n') |
| 200 | + } |
| 201 | + } |
| 202 | + KeyCode::SemiColon => { |
| 203 | + if map_to_unicode && modifiers.is_ctrl() { |
| 204 | + DecodedKey::Unicode('\u{0013}') |
| 205 | + } else if modifiers.is_caps() { |
| 206 | + DecodedKey::Unicode('S') |
| 207 | + } else { |
| 208 | + DecodedKey::Unicode('s') |
| 209 | + } |
| 210 | + } |
| 211 | + KeyCode::Quote => { |
| 212 | + if modifiers.is_shifted() { |
| 213 | + DecodedKey::Unicode('_') |
| 214 | + } else { |
| 215 | + DecodedKey::Unicode('-') |
| 216 | + } |
| 217 | + } |
| 218 | + KeyCode::Z => { |
| 219 | + if modifiers.is_shifted() { |
| 220 | + DecodedKey::Unicode(':') |
| 221 | + } else { |
| 222 | + DecodedKey::Unicode(';') |
| 223 | + } |
| 224 | + } |
| 225 | + KeyCode::X => { |
| 226 | + if map_to_unicode && modifiers.is_ctrl() { |
| 227 | + DecodedKey::Unicode('\u{0011}') |
| 228 | + } else if modifiers.is_caps() { |
| 229 | + DecodedKey::Unicode('Q') |
| 230 | + } else { |
| 231 | + DecodedKey::Unicode('q') |
| 232 | + } |
| 233 | + } |
| 234 | + KeyCode::C => { |
| 235 | + if map_to_unicode && modifiers.is_ctrl() { |
| 236 | + DecodedKey::Unicode('\u{000A}') |
| 237 | + } else if modifiers.is_caps() { |
| 238 | + DecodedKey::Unicode('J') |
| 239 | + } else { |
| 240 | + DecodedKey::Unicode('j') |
| 241 | + } |
| 242 | + } |
| 243 | + KeyCode::V => { |
| 244 | + if map_to_unicode && modifiers.is_ctrl() { |
| 245 | + DecodedKey::Unicode('\u{000B}') |
| 246 | + } else if modifiers.is_caps() { |
| 247 | + DecodedKey::Unicode('K') |
| 248 | + } else { |
| 249 | + DecodedKey::Unicode('k') |
| 250 | + } |
| 251 | + } |
| 252 | + KeyCode::B => { |
| 253 | + if map_to_unicode && modifiers.is_ctrl() { |
| 254 | + DecodedKey::Unicode('\u{0018}') |
| 255 | + } else if modifiers.is_caps() { |
| 256 | + DecodedKey::Unicode('X') |
| 257 | + } else { |
| 258 | + DecodedKey::Unicode('x') |
| 259 | + } |
| 260 | + } |
| 261 | + KeyCode::N => { |
| 262 | + if map_to_unicode && modifiers.is_ctrl() { |
| 263 | + DecodedKey::Unicode('\u{0002}') |
| 264 | + } else if modifiers.is_caps() { |
| 265 | + DecodedKey::Unicode('B') |
| 266 | + } else { |
| 267 | + DecodedKey::Unicode('b') |
| 268 | + } |
| 269 | + } |
| 270 | + KeyCode::Comma => { |
| 271 | + if map_to_unicode && modifiers.is_ctrl() { |
| 272 | + DecodedKey::Unicode('\u{0017}') |
| 273 | + } else if modifiers.is_caps() { |
| 274 | + DecodedKey::Unicode('W') |
| 275 | + } else { |
| 276 | + DecodedKey::Unicode('w') |
| 277 | + } |
| 278 | + } |
| 279 | + KeyCode::Fullstop => { |
| 280 | + if map_to_unicode && modifiers.is_ctrl() { |
| 281 | + DecodedKey::Unicode('\u{0016}') |
| 282 | + } else if modifiers.is_caps() { |
| 283 | + DecodedKey::Unicode('V') |
| 284 | + } else { |
| 285 | + DecodedKey::Unicode('v') |
| 286 | + } |
| 287 | + } |
| 288 | + KeyCode::Slash => { |
| 289 | + if map_to_unicode && modifiers.is_ctrl() { |
| 290 | + DecodedKey::Unicode('\u{001A}') |
| 291 | + } else if modifiers.is_caps() { |
| 292 | + DecodedKey::Unicode('Z') |
| 293 | + } else { |
| 294 | + DecodedKey::Unicode('z') |
| 295 | + } |
| 296 | + } |
| 297 | + e => <super::Us104Key as KeyboardLayout>::map_keycode(e, modifiers, handle_ctrl), |
| 298 | + } |
| 299 | + } |
| 300 | +} |
0 commit comments