|
|
1.1 ! root 1: /* ! 2: Hatari ! 3: ! 4: Key remapping functions ! 5: */ ! 6: ! 7: #include <stdio.h> ! 8: ! 9: #include "main.h" ! 10: #include "debug.h" ! 11: #include "keymap.h" ! 12: #include "memAlloc.h" ! 13: #include "misc.h" ! 14: ! 15: //----------------------------------------------------------------------- ! 16: /* ! 17: Remap table of Windows keys to ST Scan codes, -ve is invalid key(ie doesn't occur on ST) ! 18: ! 19: PC Keyboard:- ! 20: ! 21: Esc F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 Print Scroll Pause ! 22: ! 23: 1 59 60 61 62 63 64 65 66 67 68 87 88 70 69 ! 24: ! 25: ! 26: � ! " � $ % ^ & * ( ) _ + Page ! 27: ` 1 2 3 4 5 6 7 8 9 0 - = <- Ins Home Up ! 28: ! 29: 41 2 3 4 5 6 7 8 9 10 11 12 13 14 82 71 73 ! 30: -- -- -- ! 31: | ! 32: { } | Page ! 33: Tab Q W E R T Y U I O P [ ] <---- Del End Down ! 34: ! 35: 15 16 17 18 19 20 21 22 23 24 25 26 27 28 83 79 81 ! 36: -- -- -- ! 37: ! 38: : @ ~ ^ ! 39: Caps A S D F G H J K L ; ' # | ! 40: ! 41: 58 30 31 32 33 34 35 36 37 38 39 40 43 72 ! 42: -- ! 43: ! 44: ^ | < > ? ^ ! 45: | \ Z X C V B N M , . / | <- | -> ! 46: ! 47: 42 86 44 45 46 47 48 49 50 51 52 53 54 75 80 77 ! 48: -- -- -- ! 49: ! 50: Ctrl Alt SPACE Alt Gr Ctrl ! 51: ! 52: 29 56 57 56 29 ! 53: -- ! 54: ! 55: And:- ! 56: ! 57: Num ! 58: Lock / * - ! 59: ! 60: 69 53 55 74 ! 61: -- -- ! 62: ! 63: 7 8 9 + ! 64: Home ^ Pg Up ! 65: ! 66: 71 72 73 78 ! 67: ! 68: ! 69: 4 5 6 ! 70: <- -> ! 71: ! 72: 75 76 77 ! 73: ! 74: ! 75: 1 2 3 ! 76: End | Pg Dn Enter ! 77: ! 78: 79 70 81 28 ! 79: -- ! 80: ! 81: 0 . ! 82: Ins Del ! 83: ! 84: 82 83 ! 85: ! 86: ! 87: */ ! 88: ! 89: ! 90: /* SDL Key to ST scan code map table */ ! 91: char Default_KeyToSTScanCode[] = { ! 92: // ST Code PC Code ! 93: -1, /* 0 */ ! 94: -1, /* 1 */ ! 95: -1, /* 2 */ ! 96: -1, /* 3 */ ! 97: -1, /* 4 */ ! 98: -1, /* 5 */ ! 99: -1, /* 6 */ ! 100: -1, /* 7 */ ! 101: 0x0E, /* SDLK_BACKSPACE=8 */ ! 102: 0x0F, /* SDLK_TAB=9 */ ! 103: -1, /* 10 */ ! 104: -1, /* 11 */ ! 105: -1, /* SDLK_CLEAR = 12 */ ! 106: 0x1C, /* SDLK_RETURN = 13 */ ! 107: -1, /* 14 */ ! 108: -1, /* 15 */ ! 109: -1, /* 16 */ ! 110: -1, /* 17 */ ! 111: -1, /* 18 */ ! 112: -1, /* SDLK_PAUSE = 19 */ ! 113: -1, /* 20 */ ! 114: -1, /* 21 */ ! 115: -1, /* 22 */ ! 116: -1, /* 23 */ ! 117: -1, /* 24 */ ! 118: -1, /* 25 */ ! 119: -1, /* 26 */ ! 120: 0x01, /* SDLK_ESCAPE = 27 */ ! 121: -1, /* 28 */ ! 122: -1, /* 29 */ ! 123: -1, /* 30 */ ! 124: -1, /* 31 */ ! 125: 0x39, /* SDLK_SPACE = 32 */ ! 126: -1, /* SDLK_EXCLAIM = 33 */ ! 127: -1, /* SDLK_QUOTEDBL = 34 */ ! 128: -1, /* SDLK_HASH = 35 */ ! 129: -1, /* SDLK_DOLLAR = 36 */ ! 130: -1, /* 37 */ ! 131: -1, /* SDLK_AMPERSAND = 38 */ ! 132: -1, /* SDLK_QUOTE = 39 */ ! 133: 0x63, /* SDLK_LEFTPAREN = 40 */ ! 134: 0x64, /* SDLK_RIGHTPAREN = 41 */ ! 135: -1, /* SDLK_ASTERISK = 42 */ ! 136: 0x1B, /* SDLK_PLUS = 43 */ ! 137: 0x33, /* SDLK_COMMA = 44 */ ! 138: 0x35, /* SDLK_MINUS = 45 */ ! 139: 0x34, /* SDLK_PERIOD = 46 */ ! 140: -1, /* SDLK_SLASH = 47 */ ! 141: 0x0B, /* SDLK_0 = 48 */ ! 142: 0x02, /* SDLK_1 = 49 */ ! 143: 0x03, /* SDLK_2 = 50 */ ! 144: 0x04, /* SDLK_3 = 51 */ ! 145: 0x05, /* SDLK_4 = 52 */ ! 146: 0x06, /* SDLK_5 = 53 */ ! 147: 0x07, /* SDLK_6 = 54 */ ! 148: 0x08, /* SDLK_7 = 55 */ ! 149: 0x09, /* SDLK_8 = 56 */ ! 150: 0x0A, /* SDLK_9 = 57 */ ! 151: -1, /* SDLK_COLON = 58 */ ! 152: -1, /* SDLK_SEMICOLON = 59 */ ! 153: 0x60, /* SDLK_LESS = 60 */ ! 154: -1, /* SDLK_EQUALS = 61 */ ! 155: -1, /* SDLK_GREATER = 62 */ ! 156: -1, /* SDLK_QUESTION = 63 */ ! 157: -1, /* SDLK_AT = 64 */ ! 158: -1, /* 65 */ /* Skip uppercase letters */ ! 159: -1, /* 66 */ ! 160: -1, /* 67 */ ! 161: -1, /* 68 */ ! 162: -1, /* 69 */ ! 163: -1, /* 70 */ ! 164: -1, /* 71 */ ! 165: -1, /* 72 */ ! 166: -1, /* 73 */ ! 167: -1, /* 74 */ ! 168: -1, /* 75 */ ! 169: -1, /* 76 */ ! 170: -1, /* 77 */ ! 171: -1, /* 78 */ ! 172: -1, /* 79 */ ! 173: -1, /* 80 */ ! 174: -1, /* 81 */ ! 175: -1, /* 82 */ ! 176: -1, /* 83 */ ! 177: -1, /* 84 */ ! 178: -1, /* 85 */ ! 179: -1, /* 86 */ ! 180: -1, /* 87 */ ! 181: -1, /* 88 */ ! 182: -1, /* 89 */ ! 183: -1, /* 90 */ ! 184: -1, /* SDLK_LEFTBRACKET = 91 */ ! 185: -1, /* SDLK_BACKSLASH = 92 */ ! 186: -1, /* SDLK_RIGHTBRACKET = 93 */ ! 187: -1, /* SDLK_CARET = 94 */ ! 188: -1, /* SDLK_UNDERSCORE = 95 */ ! 189: -1, /* SDLK_BACKQUOTE = 96 */ ! 190: 0x1E, /* SDLK_a = 97 */ ! 191: 0x30, /* SDLK_b = 98 */ ! 192: 0x2E, /* SDLK_c = 99 */ ! 193: 0x20, /* SDLK_d = 100 */ ! 194: 0x12, /* SDLK_e = 101 */ ! 195: 0x21, /* SDLK_f = 102 */ ! 196: 0x22, /* SDLK_g = 103 */ ! 197: 0x23, /* SDLK_h = 104 */ ! 198: 0x17, /* SDLK_i = 105 */ ! 199: 0x24, /* SDLK_j = 106 */ ! 200: 0x25, /* SDLK_k = 107 */ ! 201: 0x26, /* SDLK_l = 108 */ ! 202: 0x32, /* SDLK_m = 109 */ ! 203: 0x31, /* SDLK_n = 110 */ ! 204: 0x18, /* SDLK_o = 111 */ ! 205: 0x19, /* SDLK_p = 112 */ ! 206: 0x10, /* SDLK_q = 113 */ ! 207: 0x13, /* SDLK_r = 114 */ ! 208: 0x1F, /* SDLK_s = 115 */ ! 209: 0x14, /* SDLK_t = 116 */ ! 210: 0x16, /* SDLK_u = 117 */ ! 211: 0x2F, /* SDLK_v = 118 */ ! 212: 0x11, /* SDLK_w = 119 */ ! 213: 0x2D, /* SDLK_x = 120 */ ! 214: 0x15, /* SDLK_y = 121 */ ! 215: 0x2C, /* SDLK_z = 122 */ ! 216: -1, /* 123 */ ! 217: -1, /* 124 */ ! 218: -1, /* 125 */ ! 219: -1, /* 126 */ ! 220: 0x53, /* SDLK_DELETE = 127 */ ! 221: /* End of ASCII mapped keysyms */ ! 222: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 128-143*/ ! 223: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 144-159*/ ! 224: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 160-175*/ ! 225: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 176-191*/ ! 226: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 192-207*/ ! 227: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 208-223*/ ! 228: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 224-239*/ ! 229: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 240-255*/ ! 230: /* Numeric keypad: */ ! 231: 0x70, /* SDLK_KP0 = 256 */ ! 232: 0x6D, /* SDLK_KP1 = 257 */ ! 233: 0x6E, /* SDLK_KP2 = 258 */ ! 234: 0x6F, /* SDLK_KP3 = 259 */ ! 235: 0x6A, /* SDLK_KP4 = 260 */ ! 236: 0x6B, /* SDLK_KP5 = 261 */ ! 237: 0x6C, /* SDLK_KP6 = 262 */ ! 238: 0x67, /* SDLK_KP7 = 263 */ ! 239: 0x68, /* SDLK_KP8 = 264 */ ! 240: 0x69, /* SDLK_KP9 = 265 */ ! 241: 0x71, /* SDLK_KP_PERIOD = 266 */ ! 242: 0x65, /* SDLK_KP_DIVIDE = 267 */ ! 243: 0x66, /* SDLK_KP_MULTIPLY = 268 */ ! 244: 0x4A, /* SDLK_KP_MINUS = 269 */ ! 245: 0x4E, /* SDLK_KP_PLUS = 270 */ ! 246: 0x72, /* SDLK_KP_ENTER = 271 */ ! 247: -1, /* SDLK_KP_EQUALS = 272 */ ! 248: /* Arrows + Home/End pad */ ! 249: 0x48, /* SDLK_UP = 273 */ ! 250: 0x50, /* SDLK_DOWN = 274 */ ! 251: 0x4D, /* SDLK_RIGHT = 275 */ ! 252: 0x4B, /* SDLK_LEFT = 276 */ ! 253: 0x52, /* SDLK_INSERT = 277 */ ! 254: 0x47, /* SDLK_HOME = 278 */ ! 255: 0x61, /* SDLK_END = 279 */ ! 256: 0x63, /* SDLK_PAGEUP = 280 */ ! 257: 0x64, /* SDLK_PAGEDOWN = 281 */ ! 258: /* Function keys */ ! 259: 0x3B, /* SDLK_F1 = 282 */ ! 260: 0x3C, /* SDLK_F2 = 283 */ ! 261: 0x3D, /* SDLK_F3 = 284 */ ! 262: 0x3E, /* SDLK_F4 = 285 */ ! 263: 0x3F, /* SDLK_F5 = 286 */ ! 264: 0x40, /* SDLK_F6 = 287 */ ! 265: 0x41, /* SDLK_F7 = 288 */ ! 266: 0x42, /* SDLK_F8 = 289 */ ! 267: 0x43, /* SDLK_F9 = 290 */ ! 268: 0x44, /* SDLK_F10 = 291 */ ! 269: -1, /* SDLK_F11 = 292 */ ! 270: -1, /* SDLK_F12 = 293 */ ! 271: -1, /* SDLK_F13 = 294 */ ! 272: -1, /* SDLK_F14 = 295 */ ! 273: -1, /* SDLK_F15 = 296 */ ! 274: -1, /* 297 */ ! 275: -1, /* 298 */ ! 276: -1, /* 299 */ ! 277: /* Key state modifier keys */ ! 278: -1, /* SDLK_NUMLOCK = 300 */ ! 279: 0x3A, /* SDLK_CAPSLOCK = 301 */ ! 280: 0x61, /* SDLK_SCROLLOCK = 302 */ ! 281: 0x36, /* SDLK_RSHIFT = 303 */ ! 282: 0x2A, /* SDLK_LSHIFT = 304 */ ! 283: 0x1D, /* SDLK_RCTRL = 305 */ ! 284: 0x1D, /* SDLK_LCTRL = 306 */ ! 285: 0x38, /* SDLK_RALT = 307 */ ! 286: 0x38, /* SDLK_LALT = 308 */ ! 287: -1, /* SDLK_RMETA = 309 */ ! 288: -1, /* SDLK_LMETA = 310 */ ! 289: -1, /* SDLK_LSUPER = 311 */ /* Left "Windows" key */ ! 290: -1, /* SDLK_RSUPER = 312 */ /* Right "Windows" key */ ! 291: -1, /* SDLK_MODE = 313 */ /* "Alt Gr" key */ ! 292: -1, /* SDLK_COMPOSE = 314 */ /* Multi-key compose key */ ! 293: /* Miscellaneous function keys */ ! 294: 0x62, /* SDLK_HELP = 315 */ ! 295: 0x63, /* SDLK_PRINT = 316 */ ! 296: -1, /* SDLK_SYSREQ = 317 */ ! 297: -1, /* SDLK_BREAK = 318 */ ! 298: -1, /* SDLK_MENU = 319 */ ! 299: }; ! 300: ! 301: ! 302: char Loaded_KeyToSTScanCode[256]; ! 303: BOOL bRemapKeyLoaded=FALSE; ! 304: ! 305: ! 306: //----------------------------------------------------------------------- ! 307: /* ! 308: Remap SDL Key to ST Scan code ! 309: */ ! 310: char Keymap_RemapKeyToSTScanCode(unsigned int Key) ! 311: { ! 312: if( Key > sizeof(Default_KeyToSTScanCode) ) return -1; /* Avoid illegal keys */ ! 313: /* Use default or loaded? */ ! 314: if (bRemapKeyLoaded) ! 315: return(Loaded_KeyToSTScanCode[Key]); ! 316: else ! 317: return(Default_KeyToSTScanCode[Key]); ! 318: } ! 319: ! 320: //----------------------------------------------------------------------- ! 321: /* ! 322: Load keyboard remap file ! 323: */ ! 324: void Keymap_LoadRemapFile(char *pszFileName) ! 325: { ! 326: char szString[1024]; ! 327: unsigned int STScanCode,PCScanCode; ! 328: FILE *in; ! 329: ! 330: // Default to not loaded ! 331: bRemapKeyLoaded = FALSE; ! 332: Memory_Set(Loaded_KeyToSTScanCode,-1,sizeof(Loaded_KeyToSTScanCode)); ! 333: ! 334: // Attempt to load file ! 335: if (strlen(pszFileName)>0) { ! 336: // Open file ! 337: in = fopen(pszFileName, "r"); ! 338: if (in) { ! 339: while(!feof(in)) { ! 340: // Read line from file ! 341: fgets(szString, 1024, in); ! 342: // Remove white-space from start of line ! 343: Misc_RemoveWhiteSpace(szString,sizeof(szString)); ! 344: if (strlen(szString)>0) { ! 345: // Is a comment? ! 346: if ( (szString[0]==';') || (szString[0]=='#') ) ! 347: continue; ! 348: // Read values ! 349: sscanf(szString,"%d,%d",&STScanCode,&PCScanCode); ! 350: // Store into remap table, check both value within range ! 351: if ( (PCScanCode>=0) && (PCScanCode<256) && (STScanCode>=0) && (STScanCode<256) ) ! 352: Loaded_KeyToSTScanCode[PCScanCode] = STScanCode; ! 353: } ! 354: } ! 355: // Loaded OK ! 356: bRemapKeyLoaded = TRUE; ! 357: ! 358: fclose(in); ! 359: } ! 360: } ! 361: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.