summaryrefslogtreecommitdiff
path: root/src/keyboardconfig.cpp
blob: c746880c24ce6e46d0751db074b1681a6017e15b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
/*
 *  Custom keyboard shortcuts configuration
 *  Copyright (C) 2007  Joshua Langley <joshlangley@optusnet.com.au>
 *
 *  This file is part of The Mana Client.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "configuration.h"
#include "keyboardconfig.h"
#include "log.h"

#include "gui/sdlinput.h"
#include "gui/setup_keyboard.h"

#include "utils/gettext.h"
#include "utils/stringutils.h"

struct KeyData
{
    const char *configField;
    int defaultValue;
    std::string caption;
    int grp;
};

// keyData must be in same order as enum keyAction.
static KeyData const keyData[KeyboardConfig::KEY_TOTAL] = {
    {"keyMoveUp", SDLK_UP, N_("Move Up"), KeyboardConfig::GRP_DEFAULT},
    {"keyMoveDown", SDLK_DOWN, N_("Move Down"), KeyboardConfig::GRP_DEFAULT},
    {"keyMoveLeft", SDLK_LEFT, N_("Move Left"), KeyboardConfig::GRP_DEFAULT},
    {"keyMoveRight", SDLK_RIGHT, N_("Move Right"), KeyboardConfig::GRP_DEFAULT},
    {"keyAttack", SDLK_LCTRL, N_("Attack"), KeyboardConfig::GRP_DEFAULT},
    {"keyTargetAttack", SDLK_x, N_("Target & Attack"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyMoveToTarget", SDLK_v, N_("Move to Target"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyChangeMoveToTarget", SDLK_PERIOD, N_("Change Move to Target type"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyMoveToHome", SDLK_d, N_("Move to Home location"),
        KeyboardConfig::GRP_DEFAULT},
    {"keySetHome", SDLK_KP5, N_("Set home location"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyMoveToPoint", SDLK_RSHIFT, N_("Move to navigation point"),
        KeyboardConfig::GRP_DEFAULT},
    {"keySmilie", SDLK_LALT, N_("Smilie"), KeyboardConfig::GRP_DEFAULT},
    {"keyTalk", SDLK_t, N_("Talk"), KeyboardConfig::GRP_DEFAULT},
    {"keyTarget", SDLK_LSHIFT, N_("Stop Attack"), KeyboardConfig::GRP_DEFAULT},
    {"keyTargetClosest", SDLK_a, N_("Target Closest"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyTargetNPC", SDLK_n, N_("Target NPC"), KeyboardConfig::GRP_DEFAULT},
    {"keyTargetPlayer", SDLK_q, N_("Target Player"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyPickup", SDLK_z, N_("Pickup"), KeyboardConfig::GRP_DEFAULT},
    {"keyChangePickupType", SDLK_o, N_("Change Pickup Type"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyHideWindows", SDLK_h, N_("Hide Windows"), KeyboardConfig::GRP_DEFAULT},
    {"keyBeingSit", SDLK_s, N_("Sit"), KeyboardConfig::GRP_DEFAULT},
    {"keyScreenshot", SDLK_p, N_("Screenshot"), KeyboardConfig::GRP_DEFAULT},
    {"keyTrade", SDLK_r, N_("Enable/Disable Trading"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyPathfind", SDLK_f, N_("Change Map View Mode"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyShortcutsKey", SDLK_MENU, N_("Item Shortcuts Key"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyShortcut1", SDLK_1, strprintf(N_("Item Shortcut %d"), 1),
        KeyboardConfig::GRP_DEFAULT},
    {"keyShortcut2", SDLK_2, strprintf(N_("Item Shortcut %d"), 2),
        KeyboardConfig::GRP_DEFAULT},
    {"keyShortcut3", SDLK_3, strprintf(N_("Item Shortcut %d"), 3),
        KeyboardConfig::GRP_DEFAULT},
    {"keyShortcut4", SDLK_4, strprintf(N_("Item Shortcut %d"), 4),
        KeyboardConfig::GRP_DEFAULT},
    {"keyShortcut5", SDLK_5, strprintf(N_("Item Shortcut %d"), 5),
        KeyboardConfig::GRP_DEFAULT},
    {"keyShortcut6", SDLK_6, strprintf(N_("Item Shortcut %d"), 6),
        KeyboardConfig::GRP_DEFAULT},
    {"keyShortcut7", SDLK_7, strprintf(N_("Item Shortcut %d"), 7),
        KeyboardConfig::GRP_DEFAULT},
    {"keyShortcut8", SDLK_8, strprintf(N_("Item Shortcut %d"), 8),
        KeyboardConfig::GRP_DEFAULT},
    {"keyShortcut9", SDLK_9, strprintf(N_("Item Shortcut %d"), 9),
        KeyboardConfig::GRP_DEFAULT},
    {"keyShortcut10", SDLK_0, strprintf(N_("Item Shortcut %d"), 10),
        KeyboardConfig::GRP_DEFAULT},
    {"keyShortcut11", SDLK_MINUS, strprintf(N_("Item Shortcut %d"), 11),
        KeyboardConfig::GRP_DEFAULT},
    {"keyShortcut12", SDLK_EQUALS, strprintf(N_("Item Shortcut %d"), 12),
        KeyboardConfig::GRP_DEFAULT},
    {"keyShortcut13", SDLK_BACKSPACE, strprintf(N_("Item Shortcut %d"), 13),
        KeyboardConfig::GRP_DEFAULT},
    {"keyShortcut14", SDLK_INSERT, strprintf(N_("Item Shortcut %d"), 14),
        KeyboardConfig::GRP_DEFAULT},
    {"keyShortcut15", SDLK_HOME, strprintf(N_("Item Shortcut %d"), 15),
        KeyboardConfig::GRP_DEFAULT},
    {"keyShortcut16", KeyboardConfig::KEY_NO_VALUE,
        strprintf(N_("Item Shortcut %d"), 16), KeyboardConfig::GRP_DEFAULT},
    {"keyShortcut17", KeyboardConfig::KEY_NO_VALUE,
        strprintf(N_("Item Shortcut %d"), 17), KeyboardConfig::GRP_DEFAULT},
    {"keyShortcut18", KeyboardConfig::KEY_NO_VALUE,
        strprintf(N_("Item Shortcut %d"), 18), KeyboardConfig::GRP_DEFAULT},
    {"keyShortcut19", KeyboardConfig::KEY_NO_VALUE,
        strprintf(N_("Item Shortcut %d"), 19), KeyboardConfig::GRP_DEFAULT},
    {"keyShortcut20", KeyboardConfig::KEY_NO_VALUE,
        strprintf(N_("Item Shortcut %d"), 20), KeyboardConfig::GRP_DEFAULT},
    {"keyWindowHelp", SDLK_F1, N_("Help Window"), KeyboardConfig::GRP_DEFAULT},
    {"keyWindowStatus", SDLK_F2, N_("Status Window"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyWindowInventory", SDLK_F3, N_("Inventory Window"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyWindowEquipment", SDLK_F4, N_("Equipment Window"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyWindowSkill", SDLK_F5, N_("Skill Window"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyWindowMinimap", SDLK_F6, N_("Minimap Window"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyWindowChat", SDLK_F7, N_("Chat Window"), KeyboardConfig::GRP_DEFAULT},
    {"keyWindowShortcut", SDLK_F8, N_("Item Shortcut Window"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyWindowSetup", SDLK_F9, N_("Setup Window"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyWindowDebug", SDLK_F10, N_("Debug Window"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyWindowSocial", SDLK_F11, N_("Social Window"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyWindowEmoteBar", SDLK_F12, N_("Emote Shortcut Window"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyWindowOutfit", SDLK_BACKQUOTE, N_("Outfits Window"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyWindowShop", -1, N_("Shop Window"), KeyboardConfig::GRP_DEFAULT},
    {"keyWindowDrop", SDLK_w, N_("Quick drop Window"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyWindowKills", SDLK_e, N_("Kills Stats Window"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyWindowSpells", SDLK_j, N_("Commands Window"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyWindowBotChecker", SDLK_LEFTBRACKET, N_("Bot Checker Window"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyWindowOnline", KeyboardConfig::KEY_NO_VALUE,
        _("Who Is Online Window"), KeyboardConfig::GRP_DEFAULT},
    {"keySocialPrevTab", KeyboardConfig::KEY_NO_VALUE,
        _("Previous Social Tab"), KeyboardConfig::GRP_DEFAULT},
    {"keySocialNextTab", KeyboardConfig::KEY_NO_VALUE, N_("Next Social Tab"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyEmoteShortcut1", SDLK_1, strprintf(N_("Emote Shortcut %d"), 1),
        KeyboardConfig::GRP_EMOTION},
    {"keyEmoteShortcut2", SDLK_2, strprintf(N_("Emote Shortcut %d"), 2),
        KeyboardConfig::GRP_EMOTION},
    {"keyEmoteShortcut3", SDLK_3, strprintf(N_("Emote Shortcut %d"), 3),
        KeyboardConfig::GRP_EMOTION},
    {"keyEmoteShortcut4", SDLK_4, strprintf(N_("Emote Shortcut %d"), 4),
        KeyboardConfig::GRP_EMOTION},
    {"keyEmoteShortcut5", SDLK_5, strprintf(N_("Emote Shortcut %d"), 5),
        KeyboardConfig::GRP_EMOTION},
    {"keyEmoteShortcut6", SDLK_6, strprintf(N_("Emote Shortcut %d"), 6),
        KeyboardConfig::GRP_EMOTION},
    {"keyEmoteShortcut7", SDLK_7, strprintf(N_("Emote Shortcut %d"), 7),
        KeyboardConfig::GRP_EMOTION},
    {"keyEmoteShortcut8", SDLK_8, strprintf(N_("Emote Shortcut %d"), 8),
        KeyboardConfig::GRP_EMOTION},
    {"keyEmoteShortcut9", SDLK_9, strprintf(N_("Emote Shortcut %d"), 9),
        KeyboardConfig::GRP_EMOTION},
    {"keyEmoteShortcut10", SDLK_0, strprintf(N_("Emote Shortcut %d"), 10),
        KeyboardConfig::GRP_EMOTION},
    {"keyEmoteShortcut11", SDLK_MINUS, strprintf(N_("Emote Shortcut %d"), 11),
        KeyboardConfig::GRP_EMOTION},
    {"keyEmoteShortcut12", SDLK_EQUALS, strprintf(N_("Emote Shortcut %d"), 12),
        KeyboardConfig::GRP_EMOTION},
    {"keyEmoteShortcut13", SDLK_BACKSPACE,
        strprintf(N_("Emote Shortcut %d"), 13),
        KeyboardConfig::GRP_EMOTION},
    {"keyEmoteShortcut14", SDLK_INSERT, strprintf(N_("Emote Shortcut %d"), 14),
        KeyboardConfig::GRP_EMOTION},
    {"keyEmoteShortcut15", SDLK_HOME, strprintf(N_("Emote Shortcut %d"), 15),
        KeyboardConfig::GRP_EMOTION},
    {"keyEmoteShortcut16", SDLK_q, strprintf(N_("Emote Shortcut %d"), 16),
        KeyboardConfig::GRP_EMOTION},
    {"keyEmoteShortcut17", SDLK_w, strprintf(N_("Emote Shortcut %d"), 17),
        KeyboardConfig::GRP_EMOTION},
    {"keyEmoteShortcut18", SDLK_e, strprintf(N_("Emote Shortcut %d"), 18),
        KeyboardConfig::GRP_EMOTION},
    {"keyEmoteShortcut19", SDLK_r, strprintf(N_("Emote Shortcut %d"), 19),
        KeyboardConfig::GRP_EMOTION},
    {"keyEmoteShortcut20", SDLK_t, strprintf(N_("Emote Shortcut %d"), 20),
        KeyboardConfig::GRP_EMOTION},
    {"keyEmoteShortcut21", SDLK_y, strprintf(N_("Emote Shortcut %d"), 21),
        KeyboardConfig::GRP_EMOTION},
    {"keyEmoteShortcut22", SDLK_u, strprintf(N_("Emote Shortcut %d"), 22),
        KeyboardConfig::GRP_EMOTION},
    {"keyEmoteShortcut23", SDLK_i, strprintf(N_("Emote Shortcut %d"), 23),
        KeyboardConfig::GRP_EMOTION},
    {"keyEmoteShortcut24", SDLK_o, strprintf(N_("Emote Shortcut %d"), 24),
        KeyboardConfig::GRP_EMOTION},
    {"keyEmoteShortcut25", SDLK_p, strprintf(N_("Emote Shortcut %d"), 25),
        KeyboardConfig::GRP_EMOTION},
    {"keyEmoteShortcut26", SDLK_LEFTBRACKET,
        strprintf(N_("Emote Shortcut %d"), 26),
        KeyboardConfig::GRP_EMOTION},
    {"keyEmoteShortcut27", SDLK_RIGHTBRACKET,
        strprintf(N_("Emote Shortcut %d"), 27),
        KeyboardConfig::GRP_EMOTION},
    {"keyEmoteShortcut28", SDLK_BACKSLASH,
        strprintf(N_("Emote Shortcut %d"), 28),
        KeyboardConfig::GRP_EMOTION},
    {"keyEmoteShortcut29", SDLK_a, strprintf(N_("Emote Shortcut %d"), 29),
        KeyboardConfig::GRP_EMOTION},
    {"keyEmoteShortcut30", SDLK_s, strprintf(N_("Emote Shortcut %d"), 30),
        KeyboardConfig::GRP_EMOTION},
    {"keyEmoteShortcut31", SDLK_d, strprintf(N_("Emote Shortcut %d"), 31),
        KeyboardConfig::GRP_EMOTION},
    {"keyEmoteShortcut32", SDLK_f, strprintf(N_("Emote Shortcut %d"), 32),
        KeyboardConfig::GRP_EMOTION},
    {"keyEmoteShortcut33", SDLK_g, strprintf(N_("Emote Shortcut %d"), 33),
        KeyboardConfig::GRP_EMOTION},
    {"keyEmoteShortcut34", SDLK_h, strprintf(N_("Emote Shortcut %d"), 34),
        KeyboardConfig::GRP_EMOTION},
    {"keyEmoteShortcut35", SDLK_j, strprintf(N_("Emote Shortcut %d"), 35),
        KeyboardConfig::GRP_EMOTION},
    {"keyEmoteShortcut36", SDLK_k, strprintf(N_("Emote Shortcut %d"), 36),
        KeyboardConfig::GRP_EMOTION},
    {"keyEmoteShortcut37", SDLK_l, strprintf(N_("Emote Shortcut %d"), 37),
        KeyboardConfig::GRP_EMOTION},
    {"keyEmoteShortcut38", SDLK_SEMICOLON,
        strprintf(N_("Emote Shortcut %d"), 38),
        KeyboardConfig::GRP_EMOTION},
    {"keyEmoteShortcut39", SDLK_QUOTE, strprintf(N_("Emote Shortcut %d"), 39),
        KeyboardConfig::GRP_EMOTION},
    {"keyEmoteShortcut40", SDLK_z, strprintf(N_("Emote Shortcut %d"), 40),
        KeyboardConfig::GRP_EMOTION},
    {"keyEmoteShortcut41", SDLK_x, strprintf(N_("Emote Shortcut %d"), 41),
        KeyboardConfig::GRP_EMOTION},
    {"keyEmoteShortcut42", SDLK_c, strprintf(N_("Emote Shortcut %d"), 42),
        KeyboardConfig::GRP_EMOTION},
    {"keyEmoteShortcut43", SDLK_v, strprintf(N_("Emote Shortcut %d"), 43),
        KeyboardConfig::GRP_EMOTION},
    {"keyEmoteShortcut44", SDLK_b, strprintf(N_("Emote Shortcut %d"), 44),
        KeyboardConfig::GRP_EMOTION},
    {"keyWearOutfit", SDLK_RCTRL, N_("Wear Outfit"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyCopyOutfit", SDLK_RALT, N_("Copy Outfit"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyCopyEquipedOutfit", SDLK_RIGHTBRACKET, N_("Copy Equiped to Outfit"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyChat", SDLK_RETURN, N_("Toggle Chat"),
        KeyboardConfig::GRP_DEFAULT | KeyboardConfig::GRP_CHAT},
    {"keyChatScrollUp", SDLK_PAGEUP, N_("Scroll Chat Up"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyChatScrollDown", SDLK_PAGEDOWN, N_("Scroll Chat Down"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyChatPrevTab", SDLK_KP7, N_("Previous Chat Tab"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyChatNextTab", SDLK_KP9, N_("Next Chat Tab"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyChatPrevHistory", SDLK_KP7, N_("Previous chat tab line"),
        KeyboardConfig::GRP_CHAT},
    {"keyChatNextHistory", SDLK_KP9, N_("Next chat tab line"),
        KeyboardConfig::GRP_CHAT},
    {"keyAutoCompleteChat", SDLK_TAB, N_("Chat Auto Complete"),
        KeyboardConfig::GRP_CHAT},
    {"keyDeActivateChat", SDLK_ESCAPE, N_("Deactivate Chat Input"),
        KeyboardConfig::GRP_CHAT},
    {"keyOK", SDLK_SPACE, N_("Select OK"), KeyboardConfig::GRP_DEFAULT},
    {"keyQuit", SDLK_ESCAPE, N_("Quit"), KeyboardConfig::GRP_DEFAULT},
    {"keyIgnoreInput1", SDLK_LSUPER, N_("Ignore input 1"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyIgnoreInput2", SDLK_RSUPER, N_("Ignore input 2"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyDirectUp", SDLK_l, N_("Direct Up"), KeyboardConfig::GRP_DEFAULT},
    {"keyDirectDown", SDLK_SEMICOLON, N_("Direct Down"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyDirectLeft", SDLK_k, N_("Direct Left"), KeyboardConfig::GRP_DEFAULT},
    {"keyDirectRight", SDLK_QUOTE, N_("Direct Right"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyCrazyMoves", SDLK_SLASH, N_("Crazy moves"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyChangeCrazyMoveType", SDLK_BACKSLASH, N_("Change Crazy Move mode"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyQuickDrop", SDLK_y, N_("Quick Drop N Items from 0 slot"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyQuickDropN", SDLK_u, N_("Quick Drop N Items"),
        KeyboardConfig::GRP_DEFAULT},
    {"keySwitchQuickDrop", SDLK_i, N_("Switch Quick Drop Counter"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyMagicInma1", SDLK_c, N_("Quick heal target or self"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyMagicItenplz", SDLK_m, N_("Use #itenplz spell"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyMagicAttack", SDLK_b, N_("Use magic attack"),
        KeyboardConfig::GRP_DEFAULT},
    {"keySwitchMagicAttack", SDLK_COMMA, N_("Switch magic attack"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyInvertDirection", SDLK_KP0, N_("Change move type"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyChangeAttackWeaponType", SDLK_g, N_("Change Attack Weapon Type"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyChangeAttackType", SDLK_END, N_("Change Attack Type"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyChangeFollowMode", SDLK_KP1, N_("Change Follow mode"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyChangeImitationMode", SDLK_KP4, N_("Change Imitation mode"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyDisableGameModifiers", SDLK_KP8,
        _("Disbale / Enable Game modifier keys"), KeyboardConfig::GRP_DEFAULT},
    {"keyChangeAudio", SDLK_KP3, N_("On / Off audio"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyAway", SDLK_KP2, N_("Enable / Disable away mode"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyRightClick", SDLK_TAB, N_("Emulate right click from keyboard"),
        KeyboardConfig::GRP_DEFAULT},
    {"keyCameraMode", SDLK_KP_PLUS, N_("Toggle camera mode"),
        KeyboardConfig::GRP_DEFAULT}
};

void KeyboardConfig::init()
{
    for (int i = 0; i < KEY_TOTAL; i++)
    {
        mKey[i].configField = keyData[i].configField;
        mKey[i].defaultValue = keyData[i].defaultValue;
        mKey[i].caption = gettext(keyData[i].caption.c_str());
        mKey[i].value = KEY_NO_VALUE;
        mKey[i].grp = keyData[i].grp;
    }
    for (int i = KEY_EMOTE_1; i <= KEY_EMOTE_44; i ++)
    {
        mKey[i].caption = strprintf(
            _("Emote Shortcut %d"), i - KEY_EMOTE_1 + 1);
    }
    for (int i = KEY_SHORTCUT_1; i <= KEY_SHORTCUT_20; i ++)
    {
        mKey[i].caption = strprintf(
            _("Item Shortcut %d"), i - KEY_SHORTCUT_1 + 1);
    }

    mNewKeyIndex = KEY_NO_VALUE;
    mEnabled = true;

    retrieve();
}

void KeyboardConfig::retrieve()
{
    for (int i = 0; i < KEY_TOTAL; i++)
    {
        mKey[i].value = (int) config.getValue(
            mKey[i].configField, mKey[i].defaultValue);
    }
}

void KeyboardConfig::store()
{
    for (int i = 0; i < KEY_TOTAL; i++)
        config.setValue(mKey[i].configField, mKey[i].value);
}

void KeyboardConfig::makeDefault()
{
    for (int i = 0; i < KEY_TOTAL; i++)
        mKey[i].value = mKey[i].defaultValue;
}

bool KeyboardConfig::hasConflicts()
{
    int i, j;
    /**
     * No need to parse the square matrix: only check one triangle
     * that's enough to detect conflicts
     */
    for (i = 0; i < KEY_TOTAL; i++)
    {
        if (mKey[i].value == KEY_NO_VALUE)
            continue;

        for (j = i, j++; j < KEY_TOTAL; j++)
        {
            // Allow for item shortcut and emote keys to overlap
            // as well as emote and ignore keys, but no other keys
            if (mKey[j].value != KEY_NO_VALUE &&
                mKey[i].value == mKey[j].value &&
                ((mKey[i].grp & mKey[j].grp) != 0)
               )
            {
                mBindError = strprintf(_("Conflict \"%s\" and \"%s\" keys. "
                                       "Resolve them, or gameplay may result"
                                       " in strange behaviour."),
                                       mKey[i].caption.c_str(),
                                       mKey[j].caption.c_str());
                return true;
            }
        }
    }
    mBindError = "";
    return false;
}

void KeyboardConfig::callbackNewKey()
{
    mSetupKey->newKeyCallback(mNewKeyIndex);
}

int KeyboardConfig::getKeyIndex(int keyValue, int grp) const
{
    for (int i = 0; i < KEY_TOTAL; i++)
    {
        if (keyValue == mKey[i].value &&
            (grp & mKey[i].grp) != 0)
        {
            return i;
        }
    }
    return KEY_NO_VALUE;
}


int KeyboardConfig::getKeyEmoteOffset(int keyValue) const
{
    for (int i = KEY_EMOTE_1; i <= KEY_EMOTE_44; i++)
    {
        if (keyValue == mKey[i].value)
            return 1 + i - KEY_EMOTE_1;
    }
    return 0;
}

bool KeyboardConfig::isKeyActive(int index) const
{
    if (!mActiveKeys)
        return false;
    return mActiveKeys[mKey[index].value];
}

void KeyboardConfig::refreshActiveKeys()
{
    mActiveKeys = SDL_GetKeyState(NULL);
}

std::string KeyboardConfig::getKeyValueString(int index) const
{
    std::string key = SDL_GetKeyName(
        (SDLKey) getKeyValue(index));

    return getKeyShortString(key);
}

std::string KeyboardConfig::getKeyShortString(const std::string &key) const
{
    if (key == "backspace")
        return "bksp";
    else if (key == "unknown key")
        return "u key";
    return key;
}