|
| 1 | +// Keyboard type mappings for different keyboard layouts |
| 2 | +// This file contains the character mappings for QWERTY, Dvorak, and Colemak layouts |
| 3 | + |
| 4 | +export type KeyboardLayoutType = 'qwerty' | 'dvorak' | 'colemak'; |
| 5 | + |
| 6 | +// Define interfaces for our key mappings |
| 7 | +interface KeyMapping { |
| 8 | + primary: string; |
| 9 | + secondary?: string; |
| 10 | +} |
| 11 | + |
| 12 | +// Type for our mapping objects |
| 13 | +export type KeyboardTypeMapping = Record<string, KeyMapping>; |
| 14 | + |
| 15 | +// QWERTY layout (default) - this is just for reference as we'll keep the original labels for QWERTY |
| 16 | +export const qwertyMapping: KeyboardTypeMapping = { |
| 17 | + // We don't need to define anything here as QWERTY is the default |
| 18 | + // This is just for reference |
| 19 | +}; |
| 20 | + |
| 21 | +// Dvorak layout |
| 22 | +export const dvorakMapping: KeyboardTypeMapping = { |
| 23 | + // Number row remains the same |
| 24 | + // Top row |
| 25 | + 'Q': { primary: "'", secondary: '"' }, |
| 26 | + 'W': { primary: ',', secondary: '<' }, |
| 27 | + 'E': { primary: '.', secondary: '>' }, |
| 28 | + 'R': { primary: 'P', secondary: undefined }, |
| 29 | + 'T': { primary: 'Y', secondary: undefined }, |
| 30 | + 'Y': { primary: 'F', secondary: undefined }, |
| 31 | + 'U': { primary: 'G', secondary: undefined }, |
| 32 | + 'I': { primary: 'C', secondary: undefined }, |
| 33 | + 'O': { primary: 'R', secondary: undefined }, |
| 34 | + 'P': { primary: 'L', secondary: undefined }, |
| 35 | + '[': { primary: '/', secondary: '?' }, |
| 36 | + ']': { primary: '=', secondary: '+' }, |
| 37 | + |
| 38 | + // Middle row |
| 39 | + 'A': { primary: 'A', secondary: undefined }, |
| 40 | + 'S': { primary: 'O', secondary: undefined }, |
| 41 | + 'D': { primary: 'E', secondary: undefined }, |
| 42 | + 'F': { primary: 'U', secondary: undefined }, |
| 43 | + 'G': { primary: 'I', secondary: undefined }, |
| 44 | + 'H': { primary: 'D', secondary: undefined }, |
| 45 | + 'J': { primary: 'H', secondary: undefined }, |
| 46 | + 'K': { primary: 'T', secondary: undefined }, |
| 47 | + 'L': { primary: 'N', secondary: undefined }, |
| 48 | + ';': { primary: 'S', secondary: undefined }, |
| 49 | + "'": { primary: '-', secondary: '_' }, |
| 50 | + |
| 51 | + // Bottom row |
| 52 | + 'Z': { primary: ';', secondary: ':' }, |
| 53 | + 'X': { primary: 'Q', secondary: undefined }, |
| 54 | + 'C': { primary: 'J', secondary: undefined }, |
| 55 | + 'V': { primary: 'K', secondary: undefined }, |
| 56 | + 'B': { primary: 'X', secondary: undefined }, |
| 57 | + 'N': { primary: 'B', secondary: undefined }, |
| 58 | + 'M': { primary: 'M', secondary: undefined }, |
| 59 | + ',': { primary: 'W', secondary: undefined }, |
| 60 | + '.': { primary: 'V', secondary: undefined }, |
| 61 | + '/': { primary: 'Z', secondary: undefined } |
| 62 | +}; |
| 63 | + |
| 64 | +// Colemak layout |
| 65 | +export const colemakMapping: KeyboardTypeMapping = { |
| 66 | + // Number row remains the same |
| 67 | + // Top row |
| 68 | + 'Q': { primary: 'Q', secondary: undefined }, |
| 69 | + 'W': { primary: 'W', secondary: undefined }, |
| 70 | + 'E': { primary: 'F', secondary: undefined }, |
| 71 | + 'R': { primary: 'P', secondary: undefined }, |
| 72 | + 'T': { primary: 'G', secondary: undefined }, |
| 73 | + 'Y': { primary: 'J', secondary: undefined }, |
| 74 | + 'U': { primary: 'L', secondary: undefined }, |
| 75 | + 'I': { primary: 'U', secondary: undefined }, |
| 76 | + 'O': { primary: 'Y', secondary: undefined }, |
| 77 | + 'P': { primary: ';', secondary: ':' }, |
| 78 | + |
| 79 | + // Middle row |
| 80 | + 'A': { primary: 'A', secondary: undefined }, |
| 81 | + 'S': { primary: 'R', secondary: undefined }, |
| 82 | + 'D': { primary: 'S', secondary: undefined }, |
| 83 | + 'F': { primary: 'T', secondary: undefined }, |
| 84 | + 'G': { primary: 'D', secondary: undefined }, |
| 85 | + 'H': { primary: 'H', secondary: undefined }, |
| 86 | + 'J': { primary: 'N', secondary: undefined }, |
| 87 | + 'K': { primary: 'E', secondary: undefined }, |
| 88 | + 'L': { primary: 'I', secondary: undefined }, |
| 89 | + ';': { primary: 'O', secondary: undefined }, |
| 90 | + |
| 91 | + // Bottom row |
| 92 | + 'Z': { primary: 'Z', secondary: undefined }, |
| 93 | + 'X': { primary: 'X', secondary: undefined }, |
| 94 | + 'C': { primary: 'C', secondary: undefined }, |
| 95 | + 'V': { primary: 'V', secondary: undefined }, |
| 96 | + 'B': { primary: 'B', secondary: undefined }, |
| 97 | + 'N': { primary: 'K', secondary: undefined }, |
| 98 | + 'M': { primary: 'M', secondary: undefined } |
| 99 | +}; |
| 100 | + |
| 101 | +// Function to get the appropriate mapping based on the keyboard type |
| 102 | +export const getKeyMapping = (type: KeyboardLayoutType, key: string, defaultMapping: KeyMapping): KeyMapping => { |
| 103 | + switch (type) { |
| 104 | + case 'dvorak': |
| 105 | + return dvorakMapping[key] || defaultMapping; |
| 106 | + case 'colemak': |
| 107 | + return colemakMapping[key] || defaultMapping; |
| 108 | + case 'qwerty': |
| 109 | + default: |
| 110 | + return defaultMapping; |
| 111 | + } |
| 112 | +}; |
0 commit comments