|
| 1 | +use crate::{DecodedKey, HandleControl, KeyCode, KeyboardLayout, Modifiers}; |
| 2 | + |
| 3 | +pub use super::us104::Us104Key; |
| 4 | + |
| 5 | +pub struct De104Key; |
| 6 | + |
| 7 | +impl KeyboardLayout for De104Key { |
| 8 | + fn map_keycode( |
| 9 | + keycode: KeyCode, |
| 10 | + modifiers: &Modifiers, |
| 11 | + handle_ctrl: HandleControl, |
| 12 | + ) -> DecodedKey { |
| 13 | + let map_to_unicode = handle_ctrl == HandleControl::MapLettersToUnicode; |
| 14 | + match keycode { |
| 15 | + KeyCode::Escape => DecodedKey::Unicode(0x1B.into()), |
| 16 | + KeyCode::BackTick => { |
| 17 | + if modifiers.is_shifted() { |
| 18 | + DecodedKey::Unicode('°') |
| 19 | + } else { |
| 20 | + DecodedKey::Unicode('^') |
| 21 | + } |
| 22 | + } |
| 23 | + KeyCode::Key1 => { |
| 24 | + if modifiers.is_shifted() { |
| 25 | + DecodedKey::Unicode('!') |
| 26 | + } else { |
| 27 | + DecodedKey::Unicode('1') |
| 28 | + } |
| 29 | + } |
| 30 | + KeyCode::Key2 => { |
| 31 | + if modifiers.is_shifted() { |
| 32 | + DecodedKey::Unicode('"') |
| 33 | + } else { |
| 34 | + DecodedKey::Unicode('2') |
| 35 | + } |
| 36 | + } |
| 37 | + KeyCode::Key3 => { |
| 38 | + if modifiers.is_shifted() { |
| 39 | + DecodedKey::Unicode('§') |
| 40 | + } else { |
| 41 | + DecodedKey::Unicode('3') |
| 42 | + } |
| 43 | + } |
| 44 | + KeyCode::Key4 => { |
| 45 | + if modifiers.is_shifted() { |
| 46 | + DecodedKey::Unicode('$') |
| 47 | + } else { |
| 48 | + DecodedKey::Unicode('4') |
| 49 | + } |
| 50 | + } |
| 51 | + KeyCode::Key5 => { |
| 52 | + if modifiers.is_shifted() { |
| 53 | + DecodedKey::Unicode('%') |
| 54 | + } else { |
| 55 | + DecodedKey::Unicode('5') |
| 56 | + } |
| 57 | + } |
| 58 | + KeyCode::Key6 => { |
| 59 | + if modifiers.is_shifted() { |
| 60 | + DecodedKey::Unicode('&') |
| 61 | + } else { |
| 62 | + DecodedKey::Unicode('6') |
| 63 | + } |
| 64 | + } |
| 65 | + KeyCode::Key7 => { |
| 66 | + if modifiers.is_shifted() { |
| 67 | + DecodedKey::Unicode('/') |
| 68 | + } else { |
| 69 | + DecodedKey::Unicode('7') |
| 70 | + } |
| 71 | + } |
| 72 | + KeyCode::Key8 => { |
| 73 | + if modifiers.is_shifted() { |
| 74 | + DecodedKey::Unicode('(') |
| 75 | + } else { |
| 76 | + DecodedKey::Unicode('8') |
| 77 | + } |
| 78 | + } |
| 79 | + KeyCode::Key9 => { |
| 80 | + if modifiers.is_shifted() { |
| 81 | + DecodedKey::Unicode(')') |
| 82 | + } else { |
| 83 | + DecodedKey::Unicode('9') |
| 84 | + } |
| 85 | + } |
| 86 | + KeyCode::Key0 => { |
| 87 | + if modifiers.is_shifted() { |
| 88 | + DecodedKey::Unicode('=') |
| 89 | + } else { |
| 90 | + DecodedKey::Unicode('0') |
| 91 | + } |
| 92 | + } |
| 93 | + KeyCode::Minus => { |
| 94 | + if modifiers.is_shifted() { |
| 95 | + DecodedKey::Unicode('?') |
| 96 | + } else { |
| 97 | + DecodedKey::Unicode('ß') |
| 98 | + } |
| 99 | + } |
| 100 | + KeyCode::Equals => { |
| 101 | + if modifiers.is_shifted() { |
| 102 | + DecodedKey::Unicode('`') |
| 103 | + } else { |
| 104 | + DecodedKey::Unicode('´') |
| 105 | + } |
| 106 | + } |
| 107 | + KeyCode::Backspace => DecodedKey::Unicode(0x08.into()), |
| 108 | + KeyCode::Tab => DecodedKey::Unicode(0x09.into()), |
| 109 | + KeyCode::Q => { |
| 110 | + if map_to_unicode && modifiers.is_ctrl() { |
| 111 | + DecodedKey::Unicode('\u{0011}') |
| 112 | + } else if modifiers.alt_gr { |
| 113 | + DecodedKey::Unicode('@') |
| 114 | + } else if modifiers.is_caps() { |
| 115 | + DecodedKey::Unicode('Q') |
| 116 | + } else { |
| 117 | + DecodedKey::Unicode('q') |
| 118 | + } |
| 119 | + } |
| 120 | + KeyCode::E => { |
| 121 | + if map_to_unicode && modifiers.is_ctrl() { |
| 122 | + DecodedKey::Unicode('\u{0005}') |
| 123 | + } else if modifiers.alt_gr { |
| 124 | + DecodedKey::Unicode('€') |
| 125 | + } else if modifiers.is_caps() { |
| 126 | + DecodedKey::Unicode('E') |
| 127 | + } else { |
| 128 | + DecodedKey::Unicode('e') |
| 129 | + } |
| 130 | + } |
| 131 | + KeyCode::Y => { |
| 132 | + if map_to_unicode && modifiers.is_ctrl() { |
| 133 | + DecodedKey::Unicode('\u{0014}') |
| 134 | + } else if modifiers.is_caps() { |
| 135 | + DecodedKey::Unicode('Z') |
| 136 | + } else { |
| 137 | + DecodedKey::Unicode('z') |
| 138 | + } |
| 139 | + } |
| 140 | + KeyCode::BracketSquareLeft => { |
| 141 | + if modifiers.is_caps() { |
| 142 | + DecodedKey::Unicode('Ü') |
| 143 | + } else { |
| 144 | + DecodedKey::Unicode('ü') |
| 145 | + } |
| 146 | + } |
| 147 | + KeyCode::BracketSquareRight => { |
| 148 | + if modifiers.alt_gr { |
| 149 | + DecodedKey::Unicode('~') |
| 150 | + } else if modifiers.is_caps() { |
| 151 | + DecodedKey::Unicode('*') |
| 152 | + } else { |
| 153 | + DecodedKey::Unicode('+') |
| 154 | + } |
| 155 | + } |
| 156 | + KeyCode::Enter => DecodedKey::Unicode(10.into()), |
| 157 | + KeyCode::BackSlash => { |
| 158 | + if modifiers.is_shifted() { |
| 159 | + DecodedKey::Unicode('\'') |
| 160 | + } else { |
| 161 | + DecodedKey::Unicode('#') |
| 162 | + } |
| 163 | + } |
| 164 | + KeyCode::SemiColon => { |
| 165 | + if modifiers.is_shifted() { |
| 166 | + DecodedKey::Unicode('Ö') |
| 167 | + } else { |
| 168 | + DecodedKey::Unicode('ö') |
| 169 | + } |
| 170 | + } |
| 171 | + KeyCode::Quote => { |
| 172 | + if modifiers.is_shifted() { |
| 173 | + DecodedKey::Unicode('Ä') |
| 174 | + } else { |
| 175 | + DecodedKey::Unicode('ä') |
| 176 | + } |
| 177 | + } |
| 178 | + KeyCode::Z => { |
| 179 | + if map_to_unicode && modifiers.is_ctrl() { |
| 180 | + DecodedKey::Unicode('\u{001A}') |
| 181 | + } else if modifiers.is_caps() { |
| 182 | + DecodedKey::Unicode('Y') |
| 183 | + } else { |
| 184 | + DecodedKey::Unicode('y') |
| 185 | + } |
| 186 | + } |
| 187 | + KeyCode::Comma => { |
| 188 | + if modifiers.is_shifted() { |
| 189 | + DecodedKey::Unicode(';') |
| 190 | + } else { |
| 191 | + DecodedKey::Unicode(',') |
| 192 | + } |
| 193 | + } |
| 194 | + KeyCode::Fullstop => { |
| 195 | + if modifiers.is_shifted() { |
| 196 | + DecodedKey::Unicode(':') |
| 197 | + } else { |
| 198 | + DecodedKey::Unicode('.') |
| 199 | + } |
| 200 | + } |
| 201 | + KeyCode::Slash => { |
| 202 | + if modifiers.is_shifted() { |
| 203 | + DecodedKey::Unicode('_') |
| 204 | + } else { |
| 205 | + DecodedKey::Unicode('-') |
| 206 | + } |
| 207 | + } |
| 208 | + KeyCode::Oem102 => { |
| 209 | + if modifiers.is_shifted() { |
| 210 | + DecodedKey::Unicode('>') |
| 211 | + } else if modifiers.alt_gr { |
| 212 | + DecodedKey::Unicode('|') |
| 213 | + } else { |
| 214 | + DecodedKey::Unicode('<') |
| 215 | + } |
| 216 | + } |
| 217 | + |
| 218 | + e => <super::Us104Key as KeyboardLayout>::map_keycode(e, modifiers, handle_ctrl), |
| 219 | + } |
| 220 | + } |
| 221 | +} |
0 commit comments