|
| 1 | +//! Finnish/Swedish keyboard support |
| 2 | +
|
| 3 | +use crate::{DecodedKey, HandleControl, KeyCode, KeyboardLayout, Modifiers}; |
| 4 | + |
| 5 | +/// A standard Finnish/Swedish 102-key (or 105-key including Windows keys) keyboard. |
| 6 | +/// |
| 7 | +/// Has a 2-row high Enter key, with Oem5 next to the left shift (ISO format). |
| 8 | +pub struct FiSe105Key; |
| 9 | + |
| 10 | +impl KeyboardLayout for FiSe105Key { |
| 11 | + fn map_keycode( |
| 12 | + &self, |
| 13 | + keycode: KeyCode, |
| 14 | + modifiers: &Modifiers, |
| 15 | + handle_ctrl: HandleControl, |
| 16 | + ) -> DecodedKey { |
| 17 | + let map_to_unicode = handle_ctrl == HandleControl::MapLettersToUnicode; |
| 18 | + let fallback = super::Us104Key; |
| 19 | + match keycode { |
| 20 | + // ========= Row 2 (the numbers) ========= |
| 21 | + KeyCode::Oem8 => { |
| 22 | + if modifiers.is_shifted() { |
| 23 | + DecodedKey::Unicode('½') |
| 24 | + } else { |
| 25 | + DecodedKey::Unicode('§') |
| 26 | + } |
| 27 | + } |
| 28 | + KeyCode::Key2 => { |
| 29 | + if modifiers.is_shifted() { |
| 30 | + DecodedKey::Unicode('"') |
| 31 | + } else if modifiers.is_altgr() { |
| 32 | + DecodedKey::Unicode('@') |
| 33 | + } else { |
| 34 | + DecodedKey::Unicode('2') |
| 35 | + } |
| 36 | + } |
| 37 | + KeyCode::Key3 => { |
| 38 | + if modifiers.is_shifted() { |
| 39 | + DecodedKey::Unicode('#') |
| 40 | + } else if modifiers.is_altgr() { |
| 41 | + DecodedKey::Unicode('£') |
| 42 | + } else { |
| 43 | + DecodedKey::Unicode('3') |
| 44 | + } |
| 45 | + } |
| 46 | + KeyCode::Key4 => { |
| 47 | + if modifiers.is_shifted() { |
| 48 | + DecodedKey::Unicode('¤') |
| 49 | + } else if modifiers.is_altgr() { |
| 50 | + DecodedKey::Unicode('$') |
| 51 | + } else { |
| 52 | + DecodedKey::Unicode('4') |
| 53 | + } |
| 54 | + } |
| 55 | + KeyCode::Key5 => { |
| 56 | + if modifiers.is_shifted() { |
| 57 | + DecodedKey::Unicode('%') |
| 58 | + } else if modifiers.is_altgr() { |
| 59 | + DecodedKey::Unicode('€') |
| 60 | + } else { |
| 61 | + DecodedKey::Unicode('5') |
| 62 | + } |
| 63 | + } |
| 64 | + KeyCode::Key6 => { |
| 65 | + if modifiers.is_shifted() { |
| 66 | + DecodedKey::Unicode('&') |
| 67 | + } else { |
| 68 | + DecodedKey::Unicode('6') |
| 69 | + } |
| 70 | + } |
| 71 | + KeyCode::Key7 => { |
| 72 | + if modifiers.is_shifted() { |
| 73 | + DecodedKey::Unicode('/') |
| 74 | + } else if modifiers.is_altgr() { |
| 75 | + DecodedKey::Unicode('{') |
| 76 | + } else { |
| 77 | + DecodedKey::Unicode('7') |
| 78 | + } |
| 79 | + } |
| 80 | + KeyCode::Key8 => { |
| 81 | + if modifiers.is_shifted() { |
| 82 | + DecodedKey::Unicode('(') |
| 83 | + } else if modifiers.is_altgr() { |
| 84 | + DecodedKey::Unicode('[') |
| 85 | + } else { |
| 86 | + DecodedKey::Unicode('8') |
| 87 | + } |
| 88 | + } |
| 89 | + KeyCode::Key9 => { |
| 90 | + if modifiers.is_shifted() { |
| 91 | + DecodedKey::Unicode(')') |
| 92 | + } else if modifiers.is_altgr() { |
| 93 | + DecodedKey::Unicode(']') |
| 94 | + } else { |
| 95 | + DecodedKey::Unicode('9') |
| 96 | + } |
| 97 | + } |
| 98 | + KeyCode::Key0 => { |
| 99 | + if modifiers.is_shifted() { |
| 100 | + DecodedKey::Unicode('=') |
| 101 | + } else if modifiers.is_altgr() { |
| 102 | + DecodedKey::Unicode('}') |
| 103 | + } else { |
| 104 | + DecodedKey::Unicode('0') |
| 105 | + } |
| 106 | + } |
| 107 | + KeyCode::OemMinus => { |
| 108 | + if modifiers.is_shifted() { |
| 109 | + DecodedKey::Unicode('?') |
| 110 | + } else if modifiers.is_altgr() { |
| 111 | + DecodedKey::Unicode('\\') |
| 112 | + } else { |
| 113 | + DecodedKey::Unicode('+') |
| 114 | + } |
| 115 | + } |
| 116 | + KeyCode::OemPlus => { |
| 117 | + if modifiers.is_shifted() { |
| 118 | + DecodedKey::Unicode('`') |
| 119 | + } else { |
| 120 | + DecodedKey::Unicode('´') |
| 121 | + } |
| 122 | + } |
| 123 | + // ========= Row 3 (QWERTY) ========= |
| 124 | + KeyCode::E => { |
| 125 | + if map_to_unicode && modifiers.is_ctrl() { |
| 126 | + DecodedKey::Unicode('\u{0005}') |
| 127 | + } else if modifiers.is_altgr() { |
| 128 | + DecodedKey::Unicode('€') |
| 129 | + } else if modifiers.is_caps() { |
| 130 | + DecodedKey::Unicode('E') |
| 131 | + } else { |
| 132 | + DecodedKey::Unicode('e') |
| 133 | + } |
| 134 | + } |
| 135 | + KeyCode::Oem4 => { |
| 136 | + if modifiers.is_caps() { |
| 137 | + DecodedKey::Unicode('Å') |
| 138 | + } else { |
| 139 | + DecodedKey::Unicode('å') |
| 140 | + } |
| 141 | + } |
| 142 | + KeyCode::Oem6 => { |
| 143 | + if modifiers.is_shifted() { |
| 144 | + DecodedKey::Unicode('^') |
| 145 | + } else if modifiers.is_altgr() { |
| 146 | + DecodedKey::Unicode('~') |
| 147 | + } else { |
| 148 | + DecodedKey::Unicode('¨') |
| 149 | + } |
| 150 | + } |
| 151 | + // ========= Row 4 (ASDF) ========= |
| 152 | + KeyCode::Oem1 => { |
| 153 | + if modifiers.is_caps() { |
| 154 | + DecodedKey::Unicode('Ö') |
| 155 | + } else { |
| 156 | + DecodedKey::Unicode('ö') |
| 157 | + } |
| 158 | + } |
| 159 | + KeyCode::Oem3 => { |
| 160 | + if modifiers.is_caps() { |
| 161 | + DecodedKey::Unicode('Ä') |
| 162 | + } else { |
| 163 | + DecodedKey::Unicode('ä') |
| 164 | + } |
| 165 | + } |
| 166 | + KeyCode::Oem7 => { |
| 167 | + if modifiers.is_shifted() { |
| 168 | + DecodedKey::Unicode('*') |
| 169 | + } else { |
| 170 | + DecodedKey::Unicode('\'') |
| 171 | + } |
| 172 | + } |
| 173 | + // ========= Row 5 (ZXCV) ========= |
| 174 | + KeyCode::Oem5 => { |
| 175 | + if modifiers.is_shifted() { |
| 176 | + DecodedKey::Unicode('>') |
| 177 | + } else if modifiers.is_altgr() { |
| 178 | + DecodedKey::Unicode('|') |
| 179 | + } else { |
| 180 | + DecodedKey::Unicode('<') |
| 181 | + } |
| 182 | + } |
| 183 | + KeyCode::M => { |
| 184 | + if map_to_unicode && modifiers.is_ctrl() { |
| 185 | + DecodedKey::Unicode('\u{000D}') |
| 186 | + } else if modifiers.is_altgr() { |
| 187 | + DecodedKey::Unicode('µ') |
| 188 | + } else if modifiers.is_caps() { |
| 189 | + DecodedKey::Unicode('M') |
| 190 | + } else { |
| 191 | + DecodedKey::Unicode('m') |
| 192 | + } |
| 193 | + } |
| 194 | + KeyCode::OemComma => { |
| 195 | + if modifiers.is_shifted() { |
| 196 | + DecodedKey::Unicode(';') |
| 197 | + } else { |
| 198 | + DecodedKey::Unicode(',') |
| 199 | + } |
| 200 | + } |
| 201 | + KeyCode::OemPeriod => { |
| 202 | + if modifiers.is_shifted() { |
| 203 | + DecodedKey::Unicode(':') |
| 204 | + } else { |
| 205 | + DecodedKey::Unicode('.') |
| 206 | + } |
| 207 | + } |
| 208 | + KeyCode::Oem2 => { |
| 209 | + if modifiers.is_shifted() { |
| 210 | + DecodedKey::Unicode('_') |
| 211 | + } else { |
| 212 | + DecodedKey::Unicode('-') |
| 213 | + } |
| 214 | + } |
| 215 | + // ========= Row 6 (modifers and space bar) ========= |
| 216 | + KeyCode::NumpadPeriod => { |
| 217 | + if modifiers.numlock { |
| 218 | + DecodedKey::Unicode(',') |
| 219 | + } else { |
| 220 | + fallback.map_keycode(keycode, modifiers, handle_ctrl) |
| 221 | + } |
| 222 | + } |
| 223 | + e => { |
| 224 | + let us = super::Us104Key; |
| 225 | + us.map_keycode(e, modifiers, handle_ctrl) |
| 226 | + } |
| 227 | + } |
| 228 | + } |
| 229 | +} |
0 commit comments