1 #include "io/input-key-acceptor.h"
2 #include "cmd-io/macro-util.h"
3 #include "core/stuff-handler.h"
4 #include "core/window-redrawer.h"
5 #include "game-option/input-options.h"
6 #include "game-option/map-screen-options.h"
7 #include "io/signal-handlers.h"
8 #include "term/gameterm.h"
9 #include "util/string-processor.h"
10 #include "world/world.h"
12 bool inkey_base; /* See the "inkey()" function */
13 bool inkey_xtra; /* See the "inkey()" function */
14 bool inkey_scan; /* See the "inkey()" function */
15 bool inkey_flag; /* See the "inkey()" function */
20 * This special pointer allows a sequence of keys to be "inserted" into
21 * the stream of keys returned by "inkey()". This key sequence will not
22 * trigger any macros, and cannot be bypassed by the Borg. It is used
23 * in Angband to handle "keymaps".
25 concptr inkey_next = NULL;
27 /* Save macro trigger string for use in inkey_special() */
28 static char inkey_macro_trigger_string[1024];
31 * Local variable -- we are inside a "macro action"
33 * Do not match any macros until "ascii 30" is found.
35 static bool parse_macro = FALSE;
38 * Local variable -- we are inside a "macro trigger"
40 * Strip all keypresses until a low ascii value is found.
42 static bool parse_under = FALSE;
45 * @brief 全てのウィンドウの再描画を行う
50 static void all_term_fresh(int x, int y)
52 p_ptr->window_flags |= PW_ALL;
55 term_activate(angband_term[0]);
61 * Cancel macro action on the queue
63 static void forget_macro_action(void)
70 if (term_inkey(&ch, FALSE, TRUE))
82 * Helper function called only from "inkey()"
84 * This function does almost all of the "macro" processing.
86 * We use the "term_key_push()" function to handle "failed" macros, as well
87 * as "extra" keys read in while choosing the proper macro, and also to hold
88 * the action for the macro, plus a special "ascii 30" character indicating
89 * that any macro action in progress is complete. Embedded macros are thus
90 * illegal, unless a macro action includes an explicit "ascii 30" character,
91 * which would probably be a massive hack, and might break things.
93 * Only 500 (0+1+2+...+29+30) milliseconds may elapse between each key in
94 * the macro trigger sequence. If a key sequence forms the "prefix" of a
95 * macro trigger, 500 milliseconds must pass before the key sequence is
96 * known not to be that macro trigger.
98 static char inkey_aux(void)
100 int k = 0, n, p = 0, w = 0;
102 char *buf = inkey_macro_trigger_string;
107 if (term_inkey(&ch, FALSE, TRUE)) {
111 (void)(term_inkey(&ch, TRUE, TRUE));
126 k = macro_find_check(buf);
131 k = macro_find_maybe(buf);
136 if (0 == term_inkey(&ch, FALSE, TRUE)) {
145 term_xtra(TERM_XTRA_DELAY, w);
149 k = macro_find_ready(buf);
152 if (term_key_push(buf[--p]))
156 (void)term_inkey(&ch, TRUE, TRUE);
160 concptr pat = macro__pat[k];
163 if (term_key_push(buf[--p]))
168 if (term_key_push(30))
171 concptr act = macro__act[k];
175 if (term_key_push(act[--n]))
183 * @brief キー入力を受け付けるメインルーチン / Get a keypress from the user.
191 term_type *old = Term;
193 if (inkey_next && *inkey_next && !inkey_xtra) {
195 inkey_base = inkey_xtra = inkey_flag = inkey_scan = FALSE;
207 (void)term_get_cursor(&v);
209 /* Show the cursor if waiting, except sometimes in "command" mode */
210 if (!inkey_scan && (!inkey_flag || hilite_player || current_world_ptr->character_icky_depth > 0)) {
211 (void)term_set_cursor(1);
214 term_activate(angband_term[0]);
215 auto y = angband_term[0]->scr->cy;
216 auto x = angband_term[0]->scr->cx;
219 if (!inkey_base && inkey_scan && (0 != term_inkey(&kk, FALSE, FALSE))) {
223 if (!done && (0 != term_inkey(&kk, FALSE, FALSE))) {
225 all_term_fresh(x, y);
226 current_world_ptr->character_saved = FALSE;
235 if (0 == term_inkey(&ch, TRUE, TRUE)) {
243 if (0 == term_inkey(&ch, FALSE, TRUE)) {
250 term_xtra(TERM_XTRA_DELAY, w);
263 if (parse_under && (ch <= 32)) {
270 } else if (ch == 31) {
273 } else if (parse_under) {
280 inkey_base = inkey_xtra = inkey_flag = inkey_scan = FALSE;
285 * Get a keypress from the user.
286 * And interpret special keys as internal code.
288 * This function is a Mega-Hack and depend on pref-xxx.prf's.
289 * Currently works on Linux(UNIX), Windows, and Macintosh only.
291 int inkey_special(bool numpad_cursor)
293 static const struct {
296 } modifier_key_list[] = {
297 { "shift-", SKEY_MOD_SHIFT },
298 { "control-", SKEY_MOD_CONTROL },
302 static const struct {
306 } special_key_list[] = {
307 { FALSE, "Down]", SKEY_DOWN },
308 { FALSE, "Left]", SKEY_LEFT },
309 { FALSE, "Right]", SKEY_RIGHT },
310 { FALSE, "Up]", SKEY_UP },
311 { FALSE, "Page_Up]", SKEY_PGUP },
312 { FALSE, "Page_Down]", SKEY_PGDOWN },
313 { FALSE, "Home]", SKEY_TOP },
314 { FALSE, "End]", SKEY_BOTTOM },
315 { TRUE, "KP_Down]", SKEY_DOWN },
316 { TRUE, "KP_Left]", SKEY_LEFT },
317 { TRUE, "KP_Right]", SKEY_RIGHT },
318 { TRUE, "KP_Up]", SKEY_UP },
319 { TRUE, "KP_Page_Up]", SKEY_PGUP },
320 { TRUE, "KP_Page_Down]", SKEY_PGDOWN },
321 { TRUE, "KP_Home]", SKEY_TOP },
322 { TRUE, "KP_End]", SKEY_BOTTOM },
323 { TRUE, "KP_2]", SKEY_DOWN },
324 { TRUE, "KP_4]", SKEY_LEFT },
325 { TRUE, "KP_6]", SKEY_RIGHT },
326 { TRUE, "KP_8]", SKEY_UP },
327 { TRUE, "KP_9]", SKEY_PGUP },
328 { TRUE, "KP_3]", SKEY_PGDOWN },
329 { TRUE, "KP_7]", SKEY_TOP },
330 { TRUE, "KP_1]", SKEY_BOTTOM },
334 static const struct {
337 } gcu_special_key_list[] = {
343 { "4~", SKEY_BOTTOM },
345 { "6~", SKEY_PGDOWN },
358 * Forget macro trigger ----
359 * It's important if we are already expanding macro action
361 inkey_macro_trigger_string[0] = '\0';
364 trig_len = strlen(inkey_macro_trigger_string);
366 return (int)((unsigned char)key);
367 if (trig_len == 1 && parse_macro) {
368 char c = inkey_macro_trigger_string[0];
369 forget_macro_action();
370 return (int)((unsigned char)c);
373 ascii_to_text(buf, inkey_macro_trigger_string);
374 if (prefix(str, "\\[")) {
377 for (i = 0; modifier_key_list[i].keyname; i++) {
378 if (prefix(str, modifier_key_list[i].keyname)) {
379 str += strlen(modifier_key_list[i].keyname);
380 modifier |= modifier_key_list[i].keyflag;
384 if (!modifier_key_list[i].keyname)
388 if (!numpad_as_cursorkey)
389 numpad_cursor = FALSE;
391 for (i = 0; special_key_list[i].keyname; i++) {
392 if ((!special_key_list[i].numpad || numpad_cursor) && streq(str, special_key_list[i].keyname)) {
393 skey = special_key_list[i].keycode;
399 forget_macro_action();
400 return (skey | modifier);
404 if (prefix(str, "\\e[")) {
407 for (i = 0; gcu_special_key_list[i].keyname; i++) {
408 if (streq(str, gcu_special_key_list[i].keyname)) {
409 return gcu_special_key_list[i].keycode;
414 inkey_macro_trigger_string[0] = '\0';
415 return (int)((unsigned char)key);
419 * @brief 全てのウィンドウの描画を止める
422 void stop_term_fresh(void)
424 for (int j = 0; j < 8; j++) {
426 angband_term[j]->never_fresh = TRUE;
431 * @brief 全てのウィンドウの描画を再開する
434 void start_term_fresh(void)
436 for (int j = 0; j < 8; j++) {
438 angband_term[j]->never_fresh = FALSE;
443 * @brief マクロ実行中かの判定関数
444 * @return 実行中であればtrue
446 bool macro_running(void)
448 /* マクロ展開中のみ詳細に判定する */
450 int diff = angband_term[0]->key_head - angband_term[0]->key_tail;
452 /* 最終入力を展開した直後はdiff==1となる */
456 /* 最終入力の処理中はまだtrueを返す */
457 if (inkey_next && *inkey_next && !inkey_xtra)