+#define MAX_CHEAT_INPUT_LEN 32
+
+static void HandleKeysCheating(Key key)
+{
+ static char cheat_input[2 * MAX_CHEAT_INPUT_LEN + 1] = "";
+ char letter = getCharFromKey(key);
+ int cheat_input_len = strlen(cheat_input);
+ int i;
+
+ if (letter == 0)
+ return;
+
+ if (cheat_input_len >= 2 * MAX_CHEAT_INPUT_LEN)
+ {
+ for (i = 0; i < MAX_CHEAT_INPUT_LEN + 1; i++)
+ cheat_input[i] = cheat_input[MAX_CHEAT_INPUT_LEN + i];
+
+ cheat_input_len = MAX_CHEAT_INPUT_LEN;
+ }
+
+ cheat_input[cheat_input_len++] = letter;
+ cheat_input[cheat_input_len] = '\0';
+
+#if 0
+ printf("::: '%s' [%d]\n", cheat_input, cheat_input_len);
+#endif
+
+#if 1
+ if (is_string_suffix(cheat_input, ":insert solution tape"))
+ InsertSolutionTape();
+#else
+ if (is_string_suffix(cheat_input, ":ist"))
+ InsertSolutionTape();
+#endif
+
+#ifdef DEBUG
+ else if (is_string_suffix(cheat_input, ":dump tape"))
+ DumpTape(&tape);
+ else if (is_string_suffix(cheat_input, ".q"))
+ for (i = 0; i < MAX_INVENTORY_SIZE; i++)
+ if (local_player->inventory_size < MAX_INVENTORY_SIZE)
+ local_player->inventory_element[local_player->inventory_size++] =
+ EL_DYNAMITE;
+#endif
+}
+
+void HandleKey(Key key, int key_status)
+{
+ int joy = 0;
+ boolean anyTextGadgetActiveOrJustFinished = anyTextGadgetActive();
+ static struct SetupKeyboardInfo custom_key;
+ static struct
+ {
+ Key *key_custom;
+ Key key_default;
+ byte action;
+ } key_info[] =
+ {
+ { &custom_key.left, DEFAULT_KEY_LEFT, JOY_LEFT },
+ { &custom_key.right, DEFAULT_KEY_RIGHT, JOY_RIGHT },
+ { &custom_key.up, DEFAULT_KEY_UP, JOY_UP },
+ { &custom_key.down, DEFAULT_KEY_DOWN, JOY_DOWN },
+ { &custom_key.snap, DEFAULT_KEY_SNAP, JOY_BUTTON_1 },
+ { &custom_key.bomb, DEFAULT_KEY_BOMB, JOY_BUTTON_2 }
+ };
+
+ if (game_status == GAME_MODE_PLAYING)
+ {
+ /* only needed for single-step tape recording mode */
+ static boolean clear_button_2[MAX_PLAYERS] = { FALSE,FALSE,FALSE,FALSE };
+ static boolean bomb_placed[MAX_PLAYERS] = { FALSE,FALSE,FALSE,FALSE };
+ int pnr;
+
+ for (pnr = 0; pnr < MAX_PLAYERS; pnr++)
+ {
+ int i;
+ byte key_action = 0;
+
+ if (setup.input[pnr].use_joystick)
+ continue;
+
+ custom_key = setup.input[pnr].key;
+
+ for (i = 0; i < 6; i++)
+ if (key == *key_info[i].key_custom)
+ key_action |= key_info[i].action;
+
+ if (tape.single_step && clear_button_2[pnr])
+ {
+ stored_player[pnr].action &= ~KEY_BUTTON_2;
+ clear_button_2[pnr] = FALSE;
+ }
+
+ if (key_status == KEY_PRESSED)
+ stored_player[pnr].action |= key_action;
+ else
+ stored_player[pnr].action &= ~key_action;
+
+ if (tape.single_step && tape.recording && tape.pausing)
+ {
+ if (key_status == KEY_PRESSED &&
+ (key_action & (KEY_MOTION | KEY_BUTTON_1)))
+ {
+ TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
+
+ if (key_action & KEY_MOTION)
+ {
+ if (stored_player[pnr].action & KEY_BUTTON_2)
+ bomb_placed[pnr] = TRUE;
+ }
+ }
+ else if (key_status == KEY_RELEASED &&
+ (key_action & KEY_BUTTON_2))
+ {
+ if (!bomb_placed[pnr])
+ {
+ TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
+
+ stored_player[pnr].action |= KEY_BUTTON_2;
+ clear_button_2[pnr] = TRUE;
+ }
+
+ bomb_placed[pnr] = FALSE;
+ }
+ }
+ else if (tape.recording && tape.pausing && (key_action & KEY_ACTION))
+ TapeTogglePause(TAPE_TOGGLE_MANUAL);
+ }
+ }