OSDN Git Service

自動拾いエディタで使っていたカーソル移動キーを読み取るHackを一般化して、
authormogami <mogami@0568b783-4c39-0410-ac80-bf13821ea2a2>
Mon, 13 Oct 2003 01:39:48 +0000 (01:39 +0000)
committermogami <mogami@0568b783-4c39-0410-ac80-bf13821ea2a2>
Mon, 13 Oct 2003 01:39:48 +0000 (01:39 +0000)
関数inkey_special()にまとめて、通常の文字列入力と生い立ち入力に応用した。

src/autopick.c
src/birth.c
src/defines.h
src/externs.h
src/util.c
src/variable.c

index 478a381..9ed9d60 100644 (file)
@@ -3098,10 +3098,11 @@ static byte get_destroyed_object_for_search(object_type **o_handle, cptr *search
 static byte get_string_for_search(object_type **o_handle, cptr *search_strp)
 {
        int pos = 0;
+       byte color = TERM_YELLOW;
        char buf[MAX_NLEN+20];
+       const size_t len = 80;
 
 #ifdef JP
-       int k_flag[MAX_NLEN+20];
        char prompt[] = "¸¡º÷(^I:»ý¤Áʪ ^L:Ç˲õ¤µ¤ì¤¿Êª): ";
 #else
        char prompt[] = "Search key(^I:inven ^L:destroyed): ";
@@ -3114,47 +3115,76 @@ static byte get_string_for_search(object_type **o_handle, cptr *search_strp)
        /* Display prompt */
        prt(prompt, 0, 0);
 
-       /* Display the default answer */
-       Term_erase(col, 0, 255);
-       Term_putstr(col, 0, -1, TERM_YELLOW, buf);
 
        /* Process input */
-       while (1)
+       while (TRUE)
        {
                bool back = FALSE;
-               int key;
-               size_t trig_len;
+               int skey;
+
+               /* Display the string */
+               Term_erase(col, 0, 255);
+               Term_putstr(col, 0, -1, color, buf);
 
                /* Place cursor */
                Term_gotoxy(col + pos, 0);
 
-               /* Get a key */
-               key = inkey();
+               /* Get a special key code */
+               skey = inkey_special();
 
-               /* Count length of macro trigger which induced this key */
-               trig_len = strlen(inkey_macro_trigger_string);
+               /* Analyze the key */
+               switch (skey)
+               {
+               case SKEY_LEFT:
+               case KTRL('b'):
+               {
+                       int i = 0;
+
+                       /* No effect at biggining of line */
+                       if (0 == pos) break;
+
+                       while (TRUE)
+                       {
+                               int next_pos = i + 1;
 
-               /* HACK -- ignore macro defined on ASCII keys */
 #ifdef JP
-               if (trig_len == 1 && !iskanji(inkey_macro_trigger_string[0]))
-#else
-               if (trig_len == 1)
+                               if (iskanji(buf[next_pos])) next_pos++;
 #endif
-               {
-                       /* Get original key */
-                       key = inkey_macro_trigger_string[0];
 
-                       /* Kill further macro expansion */
-                       flush();
+                               /* Is there the cursor at next position? */ 
+                               if (next_pos >= pos) break;
+
+                               /* Move to next */
+                               i = next_pos;
+                       }
+
+                       /* Get previous position */
+                       pos = i;
+
+                       /* Now on insert mode */
+                       color = TERM_WHITE;
+
+                       break;
                }
 
-               /* Delete key */
-               if (key == 0x7F) key = KTRL('d');
+               case SKEY_RIGHT:
+               case KTRL('f'):
+                       /* No effect at end of line */
+                       if ('\0' == buf[pos]) break;
 
+#ifdef JP
+                       /* Move right */
+                       if (iskanji(buf[pos])) pos += 2;
+                       else pos++;
+#else
+                       pos++;
+#endif
+
+                       /* Now on insert mode */
+                       color = TERM_WHITE;
+
+                       break;
 
-               /* Analyze the key */
-               switch (key)
-               {
                case ESCAPE:
                        return 0;
 
@@ -3181,57 +3211,112 @@ static byte get_string_for_search(object_type **o_handle, cptr *search_strp)
                                return 1;
                        break;
 
-               case 0x7F:
                case '\010':
+                       /* Backspace */
+
+                       /* No effect at biggining of line */
+                       if (!pos) break;
+
+                       /* Go left 1 unit */
+                       pos--;
+
+                       /* Fall through to 'Delete key' */
+
+               case 0x7F:
+               case KTRL('d'):
+                       /* Delete key */
+               {
+
+                       int dst = pos;
+
+                       /* Position of next character */
+                       int src = pos + 1;
+
 #ifdef JP
-                       if (pos > 0)
-                       {
-                               pos--;
-                               if (k_flag[pos]) pos--;
-                       }
-#else
-                       if (pos > 0) pos--;
+                       /* Next character is one more byte away */
+                       if (iskanji(src)) src++;
 #endif
+
+                       /* Move characters at src to dst */
+                       while ('\0' != (buf[dst++] = buf[src++]))
+                               /* loop */;
+
                        break;
+               }
 
                default:
+               {
+                       /* Insert a character */
+
+                       char tmp[100];
+                       char c;
+
+                       /* Ignore special keys */
+                       if (skey & SKEY_MASK) break;
+
+                       /* Get a character code */
+                       c = (char)skey;
+
+                       if (color == TERM_YELLOW)
+                       {
+                               /* Overwrite default string */
+                               buf[0] = '\0';
+
+                               /* Go to insert mode */
+                               color = TERM_WHITE;
+                       }
+
+                       /* Save right part of string */
+                       strcpy(tmp, buf + pos);
 #ifdef JP
-                       if (iskanji(key))
+                       if (iskanji(c))
                        {
-                               int next;
+                               char next;
 
+                               /* Bypass macro processing */
                                inkey_base = TRUE;
-                               next = inkey ();
-                               if (pos + 1 < MAX_NLEN)
+                               next = inkey();
+
+                               if (pos + 1 < len)
                                {
-                                       buf[pos++] = key;
-                                       buf[pos] = next;
-                                       k_flag[pos++] = 1;
+                                       buf[pos++] = c;
+                                       buf[pos++] = next;
+                               }
+                               else
+                               {
+                                       bell();
                                }
-                               else bell();
                        }
-                       else if (pos < MAX_NLEN && isprint(key))
+                       else
+#endif
                        {
-                               buf[pos] = key;
-                               k_flag[pos++] = 0;
-                       }
-                       else bell();
+#ifdef SJIS
+                               if (pos < len &&
+                                   (isprint(c) || (0xa0 <= c && c <= 0xdf)))
 #else
-                       if (pos < MAX_NLEN && isprint(key)) buf[pos++] = key;
-                       else bell();
+                               if (pos < len && isprint(c))
 #endif
-                       break;
-               }
+                               {
+                                       buf[pos++] = c;
+                               }
+                               else
+                               {
+                                       bell();
+                               }
+                       }
 
-               /* Terminate */
-               buf[pos] = '\0';
+                       /* Terminate */
+                       buf[pos] = '\0';
 
-               /* Update the entry */
-               Term_erase(col, 0, 255);
-               Term_putstr(col, 0, -1, TERM_WHITE, buf);
-       }
+                       /* Write back the left part of string */
+                       my_strcat(buf, tmp, len + 1);
 
-       /* Never reached */
+                       break;
+               } /* default: */
+
+               }
+
+       } /* while (TRUE) */
 }
 
 
@@ -3665,6 +3750,8 @@ command_menu_type menu_data[] =
        {MN_CL_QUERY, 1, -1, EC_CL_QUERY},
        {MN_CL_NO_DISP, 1, -1, EC_CL_NO_DISP},
 
+       {MN_DELETE_CHAR, -1, 0x7F, EC_DELETE_CHAR},
+
        {NULL, -1, -1, 0}
 };
 
@@ -5371,76 +5458,34 @@ static void insert_single_letter(text_body_type *tb, int key)
 
 
 /*
- * Mega-Hack:
- * Get macro trigger string directly and translate it to the command id.
+ * Check special key code and get a movement command id
  */
-static int analyze_move_key(text_body_type *tb)
+static int analyze_move_key(text_body_type *tb, int skey)
 {
-       static const struct {
-               cptr keyname;
-               int com_id;
-       } move_key_list[] = {
-               {"Down]", EC_DOWN},
-               {"Left]", EC_LEFT},
-               {"Right]", EC_RIGHT},
-               {"Up]", EC_UP},
-               {"Page_Up]", EC_PGUP},
-               {"Page_Down]", EC_PGDOWN},
-               {"Home]", EC_TOP},
-               {"End]", EC_BOTTOM},
-               {"KP_Down]", EC_DOWN},
-               {"KP_Left]", EC_LEFT},
-               {"KP_Right]", EC_RIGHT},
-               {"KP_Up]", EC_UP},
-               {"KP_Page_Up]", EC_PGUP},
-               {"KP_Page_Down]", EC_PGDOWN},
-               {"KP_Home]", EC_TOP},
-               {"KP_End]", EC_BOTTOM},
-               {"KP_2]", EC_DOWN},
-               {"KP_4]", EC_LEFT},
-               {"KP_6]", EC_RIGHT},
-               {"KP_8]", EC_UP},
-               {"KP_9]", EC_PGUP},
-               {"KP_3]", EC_PGDOWN},
-               {"KP_7]", EC_TOP},
-               {"KP_1]", EC_BOTTOM},
-               {NULL, 0},
-       };
-
-       static const char shiftstr[] = "shift-";
-       bool shifted = FALSE;
-       char buf[1024];
-       cptr str = buf;
-       int com_id = 0;
-       int i;
-
-       /* Get ascii form */
-       ascii_to_text(buf, inkey_macro_trigger_string);
+       int com_id;
 
-       /* Skip "\[" */
-       str += 2;
+       /* Not a special key */
+       if (!(skey & SKEY_MASK)) return 0;
 
-       if (prefix(str, shiftstr))
+       /* Convert from a special key code to an editor command */
+       switch(skey & ~SKEY_MOD_MASK)
        {
-               str += sizeof(shiftstr) - 1;
-               shifted = TRUE;
-       }
+       case SKEY_DOWN:   com_id = EC_DOWN;   break;
+       case SKEY_LEFT:   com_id = EC_LEFT;   break;
+       case SKEY_RIGHT:  com_id = EC_RIGHT;  break;
+       case SKEY_UP:     com_id = EC_UP;     break;
+       case SKEY_PGUP:   com_id = EC_PGUP;   break;
+       case SKEY_PGDOWN: com_id = EC_PGDOWN; break;
+       case SKEY_TOP:    com_id = EC_TOP;    break;
+       case SKEY_BOTTOM: com_id = EC_BOTTOM; break;
 
-       for (i = 0; move_key_list[i].keyname; i++)
-       {
-               if (streq(str, move_key_list[i].keyname))
-               {
-                       com_id = move_key_list[i].com_id;
-                       break;
-               }
+       default:
+               /* Not a special movement key */
+               return 0;
        }
 
-       if (!com_id) return 0;
-
-       /* Kill further macro expansion */
-       flush();
-
-       if (!shifted)
+       /* Without shift modifier */
+       if (!(skey & SKEY_MOD_SHIFT))
        {
                /*
                 * Un-shifted cursor keys cancells
@@ -5454,6 +5499,8 @@ static int analyze_move_key(text_body_type *tb)
                        tb->dirty_flags |= DIRTY_ALL;
                }
        }
+
+       /* With shift modifier */
        else
        {
                /* Start selection by shift + cursor keys */
@@ -5561,7 +5608,6 @@ void do_cmd_edit_autopick(void)
        while (!quit)
        {
                int com_id = 0;
-               size_t trig_len;
 
                /* Draw_everythig */
                draw_text_editor(tb);
@@ -5598,35 +5644,13 @@ void do_cmd_edit_autopick(void)
                tb->old_hgt = tb->hgt;
 
                /* Get a command */
-               key = inkey();
-
-               /* Count length of macro trigger which induced this key */
-               trig_len = strlen(inkey_macro_trigger_string);
-
-               /* HACK -- ignore macro defined on ASCII keys */
-#ifdef JP
-               if (trig_len == 1 && !iskanji(inkey_macro_trigger_string[0]))
-#else
-               if (trig_len == 1)
-#endif
-               {
-                       /* Get original key */
-                       key = inkey_macro_trigger_string[0];
-
-                       /* Kill further macro expansion */
-                       flush();
-               }
-
-               /* Delete key */
-               if (key == 0x7F) key = KTRL('d');
-
-
-               /* Movement special keys */
-               if (trig_len > 1) com_id = analyze_move_key(tb);
+               key = inkey_special();
 
-               if (com_id)
+               /* Special keys */
+               if (key & SKEY_MASK)
                {
-                       /* Already done */
+                       /* Get a movement command */
+                       com_id = analyze_move_key(tb, key);
                }
 
                /* Open the menu */
index ac77a92..4c840ac 100644 (file)
@@ -5351,7 +5351,6 @@ static bool do_cmd_histpref(void)
 static void edit_history(void)
 {
        char old_history[4][60];
-       char c;
        int y = 0, x = 0;
        int i, j;
 
@@ -5379,6 +5378,9 @@ static void edit_history(void)
 
        while (TRUE)
        {
+               int skey;
+               char c;
+
                for (i = 0; i < 4; i++)
                {
                        put_str(p_ptr->history[i], i + 12, 10);
@@ -5393,18 +5395,14 @@ static void edit_history(void)
                /* Place cursor just after cost of current stat */
                Term_gotoxy(x + 10, y + 12);
 
-               c = inkey();
+               /* Get special key code */
+               skey = inkey_special();
 
-               /* Cursor key macroes to direction command */
-               if (strlen(inkey_macro_trigger_string) > 1)
-               {
-                       if (c == '8') c = KTRL('P');
-                       else if (c == '2') c = KTRL('N');
-                       else if (c == '6') c = KTRL('F');
-                       else if (c == '4') c = KTRL('B');
-               }
+               /* Get a character code */
+               if (!(skey & SKEY_MASK)) c = (char)skey;
+               else c = 0;
 
-               if (c == KTRL('P'))
+               if (skey == SKEY_UP)
                {
                        y--;
                        if (y < 0) y = 3;
@@ -5412,7 +5410,7 @@ static void edit_history(void)
                        if ((x > 0) && (iskanji2(p_ptr->history[y], x-1))) x--;
 #endif
                }
-               else if (c == KTRL('N'))
+               else if (skey == SKEY_DOWN)
                {
                        y++;
                        if (y > 3) y = 0;
@@ -5420,7 +5418,7 @@ static void edit_history(void)
                        if ((x > 0) && (iskanji2(p_ptr->history[y], x-1))) x--;
 #endif
                }
-               else if (c == KTRL('F'))
+               else if (skey == SKEY_RIGHT)
                {
 #ifdef JP
                        if (iskanji2(p_ptr->history[y], x)) x++;
@@ -5432,7 +5430,7 @@ static void edit_history(void)
                                if (y < 3) y++;
                        }
                }
-               else if (c == KTRL('B'))
+               else if (skey == SKEY_LEFT)
                {
                        x--;
                        if (x < 0)
index a4eefb0..e65a152 100644 (file)
@@ -5344,3 +5344,21 @@ extern int PlayerUID;
 
 #define SCREEN_BUF_SIZE 65536           /* max screen dump buffer size */
 
+
+/*
+ * Special key code used for inkey_special()
+ */
+#define SKEY_MOD_MASK     0x0f00
+#define SKEY_MOD_SHIFT    0x0100
+#define SKEY_MOD_CONTROL  0x0200
+
+#define SKEY_MASK         0xf000
+#define SKEY_DOWN        0xf001
+#define SKEY_LEFT        0xf002
+#define SKEY_RIGHT       0xf003
+#define SKEY_UP          0xf004
+#define SKEY_PGUP        0xf005
+#define SKEY_PGDOWN      0xf006
+#define SKEY_TOP         0xf007
+#define SKEY_BOTTOM      0xf008
+
index 459c4db..d7c49d3 100644 (file)
@@ -179,7 +179,6 @@ extern bool inkey_base;
 extern bool inkey_xtra;
 extern bool inkey_scan;
 extern bool inkey_flag;
-extern char inkey_macro_trigger_string[1024];
 extern s16b coin_type;
 extern bool opening_chest;
 extern bool shimmer_monsters;
@@ -1228,6 +1227,7 @@ extern void build_gamma_table(int gamma);
 
 extern size_t my_strcpy(char *buf, const char *src, size_t bufsize);
 extern size_t my_strcat(char *buf, const char *src, size_t bufsize);
+extern int inkey_special(void);
 
 
 /* xtra1.c */
index 91f2c35..67db09f 100644 (file)
 #include "angband.h"
 
 
-
-
 static int num_more = 0;
 
+/* Save macro trigger string for use in inkey_special() */
+static char inkey_macro_trigger_string[1024];
+
 #if 0
 #ifndef HAS_STRICMP
 
@@ -3150,21 +3151,12 @@ void clear_from(int row)
 bool askfor_aux(char *buf, int len)
 {
        int y, x;
+       int pos = 0;
+       byte color = TERM_YELLOW;
 
-       int i = 0;
-
-       int k = 0;
-
-       bool done = FALSE;
-
-
-#ifdef JP
-    int        k_flag[128];
-#endif
-       /* Locate the cursor */
+       /* Locate the cursor position */
        Term_locate(&x, &y);
 
-
        /* Paranoia -- check len */
        if (len < 1) len = 1;
 
@@ -3174,107 +3166,194 @@ bool askfor_aux(char *buf, int len)
        /* Restrict the length */
        if (x + len > 80) len = 80 - x;
 
-
        /* Paranoia -- Clip the default entry */
        buf[len] = '\0';
 
 
-       /* Display the default answer */
-       Term_erase(x, y, len);
-       Term_putstr(x, y, -1, TERM_YELLOW, buf);
-
-
        /* Process input */
-       while (!done)
+       while (TRUE)
        {
+               int skey;
+
+               /* Display the string */
+               Term_erase(x, y, len);
+               Term_putstr(x, y, -1, color, buf);
+
                /* Place cursor */
-               Term_gotoxy(x + k, y);
+               Term_gotoxy(x + pos, y);
 
-               /* Get a key */
-               i = inkey();
+               /* Get a special key code */
+               skey = inkey_special();
 
                /* Analyze the key */
-               switch (i)
+               switch (skey)
                {
-               case ESCAPE:
-                       k = 0;
-                       done = TRUE;
+               case SKEY_LEFT:
+               case KTRL('b'):
+               {
+                       int i = 0;
+
+                       /* No effect at biggining of line */
+                       if (0 == pos) break;
+
+                       while (TRUE)
+                       {
+                               int next_pos = i + 1;
+
+#ifdef JP
+                               if (iskanji(buf[next_pos])) next_pos++;
+#endif
+
+                               /* Is there the cursor at next position? */ 
+                               if (next_pos >= pos) break;
+
+                               /* Move to next */
+                               i = next_pos;
+                       }
+
+                       /* Get previous position */
+                       pos = i;
+
+                       /* Now on insert mode */
+                       color = TERM_WHITE;
+
                        break;
+               }
+
+               case SKEY_RIGHT:
+               case KTRL('f'):
+                       /* No effect at end of line */
+                       if ('\0' == buf[pos]) break;
+
+#ifdef JP
+                       /* Move right */
+                       if (iskanji(buf[pos])) pos += 2;
+                       else pos++;
+#else
+                       pos++;
+#endif
+
+                       /* Now on insert mode */
+                       color = TERM_WHITE;
+
+                       break;
+
+               case ESCAPE:
+                       /* Cancel input */
+                       buf[0] = '\0';
+                       return FALSE;
 
                case '\n':
                case '\r':
-                       k = strlen(buf);
-                       done = TRUE;
-                       break;
+                       /* Success */
+                       return TRUE;
 
-               case 0x7F:
                case '\010':
+                       /* Backspace */
+
+                       /* No effect at biggining of line */
+                       if (!pos) break;
+
+                       /* Go left 1 unit */
+                       pos--;
+
+                       /* Fall through to 'Delete key' */
+
+               case 0x7F:
+               case KTRL('d'):
+                       /* Delete key */
+               {
+
+                       int dst = pos;
+
+                       /* Position of next character */
+                       int src = pos + 1;
+
 #ifdef JP
-                               if (k > 0)
-                               {
-                                       k--;
-                                       if (k_flag[k] != 0)
-                                               k--;
-                               }
-#else
-                       if (k > 0) k--;
+                       /* Next character is one more byte away */
+                       if (iskanji(src)) src++;
 #endif
 
+                       /* Move characters at src to dst */
+                       while ('\0' != (buf[dst++] = buf[src++]))
+                               /* loop */;
+
                        break;
+               }
 
                default:
+               {
+                       /* Insert a character */
+
+                       char tmp[100];
+                       char c;
+
+                       /* Ignore special keys */
+                       if (skey & SKEY_MASK) break;
+
+                       /* Get a character code */
+                       c = (char)skey;
+
+                       if (color == TERM_YELLOW)
+                       {
+                               /* Overwrite default string */
+                               buf[0] = '\0';
+
+                               /* Go to insert mode */
+                               color = TERM_WHITE;
+                       }
+
+                       /* Save right part of string */
+                       strcpy(tmp, buf + pos);
 #ifdef JP
-       {                       /* ÊÒ»³¤µ¤óºîÀ® */
-               int next;
-
-                               if (iskanji (i)) {
-                                       inkey_base = TRUE;
-                                       next = inkey ();
-                                       if (k+1 < len) {
-                                               buf[k++] = i;
-                                               buf[k] = next;
-                                               k_flag[k++] = 1;
-                                       } else
-                                               bell();
-                               } else {
-#ifdef SJIS
-                   if(k<len && (isprint(i) || (0xa0<=i && i<=0xdf))){
-#else
-                   if(k<len && isprint(i)){
-#endif
-                                               buf[k] = i;
-                                               k_flag[k++] = 0;
-                                       } else
-                                               bell();
-                              }
-                }
-#else
-                       if ((k < len) && (isprint(i)))
+                       if (iskanji(c))
                        {
-                               buf[k++] = i;
+                               char next;
+
+                               /* Bypass macro processing */
+                               inkey_base = TRUE;
+                               next = inkey();
+
+                               if (pos + 1 < len)
+                               {
+                                       buf[pos++] = c;
+                                       buf[pos++] = next;
+                               }
+                               else
+                               {
+                                       bell();
+                               }
                        }
                        else
+#endif
                        {
-                               bell();
-                       }
+#ifdef SJIS
+                               if (pos < len &&
+                                   (isprint(c) || (0xa0 <= c && c <= 0xdf)))
+#else
+                               if (pos < len && isprint(c))
 #endif
+                               {
+                                       buf[pos++] = c;
+                               }
+                               else
+                               {
+                                       bell();
+                               }
+                       }
 
-                       break;
-               }
+                       /* Terminate */
+                       buf[pos] = '\0';
 
-               /* Terminate */
-               buf[k] = '\0';
+                       /* Write back the left part of string */
+                       my_strcat(buf, tmp, len + 1);
 
-               /* Update the entry */
-               Term_erase(x, y, len);
-               Term_putstr(x, y, -1, TERM_WHITE, buf);
-       }
+                       break;
+               } /* default: */
 
-       /* Aborted */
-       if (i == ESCAPE) return (FALSE);
+               }
 
-       /* Success */
-       return (TRUE);
+       } /* while (TRUE) */
 }
 
 
@@ -5100,3 +5179,146 @@ size_t my_strcat(char *buf, const char *src, size_t bufsize)
                return (dlen + strlen(src));
        }
 }
+
+
+/*
+ * Get a keypress from the user.
+ * And interpret special keys as internal code.
+ *
+ * This function is a Mega-Hack and depend on pref-xxx.prf's.
+ * Currently works on Linux(UNIX), Windows, and Macintosh only.
+ */
+int inkey_special(void)
+{
+       static const struct {
+               cptr keyname;
+               int keyflag;
+       } modifier_key_list[] = {
+               {"shift-", SKEY_MOD_SHIFT},
+               {"control-", SKEY_MOD_CONTROL},
+               {NULL, 0},
+       };
+
+       static const struct {
+               cptr keyname;
+               int keycode;
+       } special_key_list[] = {
+               {"Down]", SKEY_DOWN},
+               {"Left]", SKEY_LEFT},
+               {"Right]", SKEY_RIGHT},
+               {"Up]", SKEY_UP},
+               {"Page_Up]", SKEY_PGUP},
+               {"Page_Down]", SKEY_PGDOWN},
+               {"Home]", SKEY_TOP},
+               {"End]", SKEY_BOTTOM},
+               {"KP_Down]", SKEY_DOWN},
+               {"KP_Left]", SKEY_LEFT},
+               {"KP_Right]", SKEY_RIGHT},
+               {"KP_Up]", SKEY_UP},
+               {"KP_Page_Up]", SKEY_PGUP},
+               {"KP_Page_Down]", SKEY_PGDOWN},
+               {"KP_Home]", SKEY_TOP},
+               {"KP_End]", SKEY_BOTTOM},
+               {"KP_2]", SKEY_DOWN},
+               {"KP_4]", SKEY_LEFT},
+               {"KP_6]", SKEY_RIGHT},
+               {"KP_8]", SKEY_UP},
+               {"KP_9]", SKEY_PGUP},
+               {"KP_3]", SKEY_PGDOWN},
+               {"KP_7]", SKEY_TOP},
+               {"KP_1]", SKEY_BOTTOM},
+               {NULL, 0},
+       };
+       char buf[1024];
+       cptr str = buf;
+       char key;
+       int skey = 0;
+       int modifier = 0;
+       int i;
+       size_t trig_len;
+
+       /* Get a keypress */
+       key = inkey();
+
+       /* Examine trigger string */
+       trig_len = strlen(inkey_macro_trigger_string);
+
+       /* No special key */
+       if (!trig_len) return (int)key;
+
+       /*
+        * Mega Hack -- ignore macro defined on ASCII keys
+        *
+        * When this function is used, all ASCII keys are used as
+        * themselfs instead of macro triggers for command macro's.
+        */
+#ifdef JP
+       if (trig_len == 1 && !iskanji(inkey_macro_trigger_string[0]))
+#else
+       if (trig_len == 1)
+#endif
+       {
+               /* Get original key */
+               key = inkey_macro_trigger_string[0];
+               
+               /* Kill further macro expansion */
+               flush();
+
+               /* Return the originaly pressed key */
+               return (int)key;
+       }
+
+       /* Convert the trigger */
+       ascii_to_text(buf, inkey_macro_trigger_string);
+
+       /* Check the prefix "\[" */
+       if (!prefix(str, "\\[")) return 0;
+
+       /* Skip "\[" */
+       str += 2;
+
+       /* Examine modifier keys */
+       while (TRUE)
+       {
+               for (i = 0; modifier_key_list[i].keyname; i++)
+               {
+                       if (prefix(str, modifier_key_list[i].keyname))
+                       {
+                               /* Get modifier key flag */
+                               str += strlen(modifier_key_list[i].keyname);
+                               modifier |= modifier_key_list[i].keyflag;
+                       }
+               }
+
+               /* No more modifier key found */
+               if (!modifier_key_list[i].keyname) break;
+       }
+
+       /* Get a special key code */
+       for (i = 0; special_key_list[i].keyname; i++)
+       {
+               if (streq(str, special_key_list[i].keyname))
+               {
+                       skey = special_key_list[i].keycode;
+                       break;
+               }
+       }
+
+       /* No special key found? */
+       if (!skey)
+       {
+               /* Don't bother with this trigger no more */
+               inkey_macro_trigger_string[0] = '\0';
+
+               /* Return normal keycode */
+               return (int)key;
+       }
+
+       /* A special key found */
+
+       /* Kill further macro expansion */
+       flush();
+
+       /* Return special key code and modifier flags */
+       return (skey | modifier);
+}
index bb9683f..0cee98d 100644 (file)
@@ -134,7 +134,6 @@ bool inkey_base;            /* See the "inkey()" function */
 bool inkey_xtra;               /* See the "inkey()" function */
 bool inkey_scan;               /* See the "inkey()" function */
 bool inkey_flag;               /* See the "inkey()" function */
-char inkey_macro_trigger_string[1024];
 
 s16b coin_type;                        /* Hack -- force coin type */