--- a/hedgewars/uKeyNames.pas Sat Apr 27 12:27:08 2019 +0200
+++ b/hedgewars/uKeyNames.pas Sat Apr 27 13:51:02 2019 +0200
@@ -27,238 +27,61 @@
implementation
+uses uPhysFSLayer, uUtils, uVariables, uTypes, uConsole;
+
procedure populateKeyNames(var KeyArray: TKeyNames);
+var f: PfsFile;
+ l, keyname, tmp: shortstring;
+ i, scancode: LongInt;
begin
(*
- This is a mapping from SDL scancodes to Hedgewars key identifiers.
+ KeyArray is a mapping from SDL scancodes to Hedgewars key identifiers.
Hedgewars key identifiers are strings with a maximum length of 15
and are used internally to identify keys in the engine and in settings.ini.
*)
- KeyArray[4] := 'a';
- KeyArray[5] := 'b';
- KeyArray[6] := 'c';
- KeyArray[7] := 'd';
- KeyArray[8] := 'e';
- KeyArray[9] := 'f';
- KeyArray[10] := 'g';
- KeyArray[11] := 'h';
- KeyArray[12] := 'i';
- KeyArray[13] := 'j';
- KeyArray[14] := 'k';
- KeyArray[15] := 'l';
- KeyArray[16] := 'm';
- KeyArray[17] := 'n';
- KeyArray[18] := 'o';
- KeyArray[19] := 'p';
- KeyArray[20] := 'q';
- KeyArray[21] := 'r';
- KeyArray[22] := 's';
- KeyArray[23] := 't';
- KeyArray[24] := 'u';
- KeyArray[25] := 'v';
- KeyArray[26] := 'w';
- KeyArray[27] := 'x';
- KeyArray[28] := 'y';
- KeyArray[29] := 'z';
- KeyArray[30] := '1';
- KeyArray[31] := '2';
- KeyArray[32] := '3';
- KeyArray[33] := '4';
- KeyArray[34] := '5';
- KeyArray[35] := '6';
- KeyArray[36] := '7';
- KeyArray[37] := '8';
- KeyArray[38] := '9';
- KeyArray[39] := '0';
- KeyArray[40] := 'return';
- KeyArray[41] := 'escape';
- KeyArray[42] := 'backspace';
- KeyArray[43] := 'tab';
- KeyArray[44] := 'space';
- KeyArray[45] := '-';
- KeyArray[46] := '=';
- KeyArray[47] := '[';
- KeyArray[48] := ']';
- KeyArray[49] := '\';
- KeyArray[50] := '#';
- KeyArray[51] := ';';
- KeyArray[52] := '''';
- KeyArray[53] := '`';
- KeyArray[54] := ',';
- KeyArray[55] := '.';
- KeyArray[56] := '/';
- KeyArray[57] := 'capslock';
- KeyArray[58] := 'f1';
- KeyArray[59] := 'f2';
- KeyArray[60] := 'f3';
- KeyArray[61] := 'f4';
- KeyArray[62] := 'f5';
- KeyArray[63] := 'f6';
- KeyArray[64] := 'f7';
- KeyArray[65] := 'f8';
- KeyArray[66] := 'f9';
- KeyArray[67] := 'f10';
- KeyArray[68] := 'f11';
- KeyArray[69] := 'f12';
- KeyArray[70] := 'printscreen';
- KeyArray[71] := 'scrolllock';
- KeyArray[72] := 'pause';
- KeyArray[73] := 'insert';
- KeyArray[74] := 'home';
- KeyArray[75] := 'pageup';
- KeyArray[76] := 'delete';
- KeyArray[77] := 'end';
- KeyArray[78] := 'pagedown';
- KeyArray[79] := 'right';
- KeyArray[80] := 'left';
- KeyArray[81] := 'down';
- KeyArray[82] := 'up';
- KeyArray[83] := 'numlock';
- KeyArray[84] := 'keypad_/';
- KeyArray[85] := 'keypad_*';
- KeyArray[86] := 'keypad_-';
- KeyArray[87] := 'keypad_+';
- KeyArray[88] := 'keypad_enter';
- KeyArray[89] := 'keypad_1';
- KeyArray[90] := 'keypad_2';
- KeyArray[91] := 'keypad_3';
- KeyArray[92] := 'keypad_4';
- KeyArray[93] := 'keypad_5';
- KeyArray[94] := 'keypad_6';
- KeyArray[95] := 'keypad_7';
- KeyArray[96] := 'keypad_8';
- KeyArray[97] := 'keypad_9';
- KeyArray[98] := 'keypad_0';
- KeyArray[99] := 'keypad_.';
- KeyArray[101] := 'menu';
- KeyArray[102] := 'power';
- KeyArray[103] := 'keypad_=';
- KeyArray[104] := 'f13';
- KeyArray[105] := 'f14';
- KeyArray[106] := 'f15';
- KeyArray[107] := 'f16';
- KeyArray[108] := 'f17';
- KeyArray[109] := 'f18';
- KeyArray[110] := 'f19';
- KeyArray[111] := 'f20';
- KeyArray[112] := 'f21';
- KeyArray[113] := 'f22';
- KeyArray[114] := 'f23';
- KeyArray[115] := 'f24';
- KeyArray[116] := 'execute';
- KeyArray[117] := 'help';
- KeyArray[118] := 'menu';
- KeyArray[119] := 'select';
- KeyArray[120] := 'stop';
- KeyArray[121] := 'again';
- KeyArray[122] := 'undo';
- KeyArray[123] := 'cut';
- KeyArray[124] := 'copy';
- KeyArray[125] := 'paste';
- KeyArray[126] := 'find';
- KeyArray[127] := 'mute';
- KeyArray[128] := 'volumeup';
- KeyArray[129] := 'volumedown';
- KeyArray[133] := 'keypad_,';
- KeyArray[134] := 'keypad_=_(as400';
- KeyArray[153] := 'alterase';
- KeyArray[154] := 'sysreq';
- KeyArray[155] := 'cancel';
- KeyArray[156] := 'clear';
- KeyArray[157] := 'prior';
- KeyArray[158] := 'return2';
- KeyArray[159] := 'separator';
- KeyArray[160] := 'out';
- KeyArray[161] := 'oper';
- KeyArray[162] := 'clear_/_again';
- KeyArray[163] := 'crsel';
- KeyArray[164] := 'exsel';
- KeyArray[176] := 'keypad_00';
- KeyArray[177] := 'keypad_000';
- KeyArray[178] := 'thousandssepara';
- KeyArray[179] := 'decimalseparato';
- KeyArray[180] := 'currencyunit';
- KeyArray[181] := 'currencysubunit';
- KeyArray[182] := 'keypad_(';
- KeyArray[183] := 'keypad_)';
- KeyArray[184] := 'keypad_{';
- KeyArray[185] := 'keypad_}';
- KeyArray[186] := 'keypad_tab';
- KeyArray[187] := 'keypad_backspac';
- KeyArray[188] := 'keypad_a';
- KeyArray[189] := 'keypad_b';
- KeyArray[190] := 'keypad_c';
- KeyArray[191] := 'keypad_d';
- KeyArray[192] := 'keypad_e';
- KeyArray[193] := 'keypad_f';
- KeyArray[194] := 'keypad_xor';
- KeyArray[195] := 'keypad_^';
- KeyArray[196] := 'keypad_%';
- KeyArray[197] := 'keypad_<';
- KeyArray[198] := 'keypad_>';
- KeyArray[199] := 'keypad_&';
- KeyArray[200] := 'keypad_&&';
- KeyArray[201] := 'keypad_|';
- KeyArray[202] := 'keypad_||';
- KeyArray[203] := 'keypad_:';
- KeyArray[204] := 'keypad_#';
- KeyArray[205] := 'keypad_space';
- KeyArray[206] := 'keypad_@';
- KeyArray[207] := 'keypad_!';
- KeyArray[208] := 'keypad_memstore';
- KeyArray[209] := 'keypad_memrecal';
- KeyArray[210] := 'keypad_memclear';
- KeyArray[211] := 'keypad_memadd';
- KeyArray[212] := 'keypad_memsubtr';
- KeyArray[213] := 'keypad_memmulti';
- KeyArray[214] := 'keypad_memdivid';
- KeyArray[215] := 'keypad_+/-';
- KeyArray[216] := 'keypad_clear';
- KeyArray[217] := 'keypad_clearent';
- KeyArray[218] := 'keypad_binary';
- KeyArray[219] := 'keypad_octal';
- KeyArray[220] := 'keypad_decimal';
- KeyArray[221] := 'keypad_hexadeci';
- KeyArray[224] := 'left_ctrl';
- KeyArray[225] := 'left_shift';
- KeyArray[226] := 'left_alt';
- KeyArray[227] := 'left_gui';
- KeyArray[228] := 'right_ctrl';
- KeyArray[229] := 'right_shift';
- KeyArray[230] := 'right_alt';
- KeyArray[231] := 'right_gui';
- KeyArray[257] := 'modeswitch';
- KeyArray[258] := 'audionext';
- KeyArray[259] := 'audioprev';
- KeyArray[260] := 'audiostop';
- KeyArray[261] := 'audioplay';
- KeyArray[262] := 'audiomute';
- KeyArray[263] := 'mediaselect';
- KeyArray[264] := 'www';
- KeyArray[265] := 'mail';
- KeyArray[266] := 'calculator';
- KeyArray[267] := 'computer';
- KeyArray[268] := 'ac_search';
- KeyArray[269] := 'ac_home';
- KeyArray[270] := 'ac_back';
- KeyArray[271] := 'ac_forward';
- KeyArray[272] := 'ac_stop';
- KeyArray[273] := 'ac_refresh';
- KeyArray[274] := 'ac_bookmarks';
- KeyArray[275] := 'brightnessdown';
- KeyArray[276] := 'brightnessup';
- KeyArray[277] := 'displayswitch';
- KeyArray[278] := 'kbdillumtoggle';
- KeyArray[279] := 'kbdillumdown';
- KeyArray[280] := 'kbdillumup';
- KeyArray[281] := 'eject';
- KeyArray[282] := 'sleep';
- KeyArray[283] := 'app1';
- KeyArray[284] := 'app2';
- KeyArray[285] := 'audiorewind';
- KeyArray[286] := 'audiofastforwar';
+
+(* Key identifiers are read from an RFC 4180-compliant CSV file.
+- 1st column: SDL scancode
+- 2nd column: Hedgewars key ID *)
+if pfsExists(cPathz[ptMisc]+'/keys.csv') then
+ begin
+ f:= pfsOpenRead(cPathz[ptMisc]+'/keys.csv');
+ l:= '';
+ pfsReadLn(f, l);
+ while (not pfsEOF(f)) and (l <> '') do
+ begin
+ tmp:= '';
+ i:= 1;
+ while (i <= length(l)) and (l[i] <> ',') do
+ begin
+ tmp:= tmp + l[i];
+ inc(i)
+ end;
+ scancode:= StrToInt(tmp);
- // generateKeyNames(); // DEBUG (see below)
+ if i < length(l) then
+ begin
+ keyname:= copy(l, i + 1, length(l) - i);
+ if (keyname[1] = '"') and (keyname[length(keyname)] = '"') then
+ keyname:= copy(keyname, 2, length(keyname) - 2)
+ else
+ keyname:= copy(keyname, 1, length(keyname) - 1);
+ end;
+
+ pfsReadLn(f, l);
+ KeyArray[scancode]:= keyname;
+ end;
+
+ pfsClose(f)
+ end
+else
+ begin
+ WriteLnToConsole('misc/keys.csv file not found');
+ AddFileLog('misc/keys.csv file not found');
+ halt(haltStartupError);
+ end;
+
+// generateKeyNames(); // DEBUG (see below)
end;
(*