Index: src/Makefile.am
===================================================================
RCS file: /home/rr9/angband/angband/src/Makefile.am,v
retrieving revision 1.29
diff -u -r1.29 Makefile.am
--- src/Makefile.am	16 Feb 2003 10:50:15 -0000	1.29
+++ src/Makefile.am	21 Jan 2004 20:55:13 -0000
@@ -32,7 +32,7 @@
   script.c script.h \
   l-monst.c l-object.c l-player.c l-random.c l-ui.c l-misc.c l-spell.c \
   use-obj.c x-spell.c \
-  obj-info.c
+  obj-info.c pathfind.c
 
 l-monst.c: lua/tolua l-monst.pkg
 	lua/tolua -n monster -o l-monst.c l-monst.pkg
Index: src/cmd1.c
===================================================================
RCS file: /home/rr9/angband/angband/src/cmd1.c,v
retrieving revision 1.22
diff -u -r1.22 cmd1.c
--- src/cmd1.c	28 Feb 2003 16:34:31 -0000	1.22
+++ src/cmd1.c	21 Jan 2004 20:55:14 -0000
@@ -2068,6 +2068,8 @@
  */
 void run_step(int dir)
 {
+	int x,y;
+
 	/* Start run */
 	if (dir)
 	{
@@ -2084,14 +2086,30 @@
 	/* Continue run */
 	else
 	{
-		/* Update run */
-		if (run_test())
+		if (!p_ptr->running_withpathfind)
 		{
-			/* Disturb */
-			disturb(0, 0);
-
-			/* Done */
-			return;
+			/* Update run */
+			if (run_test())
+			{
+				/* Disturb */
+				disturb(0, 0);
+	
+				/* Done */
+				return;
+			}
+		}
+		else
+		{
+			if (pf_result_index < 0)
+			{
+				disturb(0, 0);
+				p_ptr->running_withpathfind = 0;
+				return;
+			}
+			p_ptr->run_cur_dir = pf_result[pf_result_index--] - '0';
+			x = p_ptr->px + ddx[p_ptr->run_cur_dir];
+			y = p_ptr->py + ddy[p_ptr->run_cur_dir];
+			if (!do_cmd_walk_test(y, x)) return;
 		}
 	}
 
Index: src/cmd2.c
===================================================================
RCS file: /home/rr9/angband/angband/src/cmd2.c,v
retrieving revision 1.20
diff -u -r1.20 cmd2.c
--- src/cmd2.c	11 May 2003 15:05:28 -0000	1.20
+++ src/cmd2.c	21 Jan 2004 20:55:15 -0000
@@ -1992,7 +1992,7 @@
 /*
  * Determine if a given grid may be "walked"
  */
-static bool do_cmd_walk_test(int y, int x)
+bool do_cmd_walk_test(int y, int x)
 {
 	/* Hack -- walking obtains knowledge XXX XXX */
 	if (!(cave_info[y][x] & (CAVE_MARK))) return (TRUE);
@@ -2145,6 +2145,30 @@
 
 	/* Start run */
 	run_step(dir);
+}
+
+/*
+ * Start running with pathfinder.
+ *
+ * Note that running while confused is not allowed.
+ */
+void do_cmd_pathfind(int y, int x)
+{
+	/* Hack XXX XXX XXX */
+	if (p_ptr->confused)
+	{
+		msg_print("You are too confused!");
+		return;
+	}
+
+	if (findpath(y, x))
+	{
+		p_ptr->running = 1000;
+		/* Calculate torch radius */
+		p_ptr->update |= (PU_TORCH);
+		p_ptr->running_withpathfind = TRUE;
+		run_step(0);
+	}
 }
 
 
Index: src/defines.h
===================================================================
RCS file: /home/rr9/angband/angband/src/defines.h,v
retrieving revision 1.83
diff -u -r1.83 defines.h
--- src/defines.h	23 Nov 2003 14:25:54 -0000	1.83
+++ src/defines.h	21 Jan 2004 20:55:17 -0000
@@ -3059,3 +3059,14 @@
  * Given an array, determine how many elements are in the array.
  */
 #define N_ELEMENTS(a) (sizeof(a) / sizeof((a)[0]))
+
+/*
+ * Maximum size around the player to consider in the pathfinder
+ */
+#define MAX_PF_RADIUS 50
+
+/*
+ * Maximum distance to consider in the pathfinder
+ */
+#define MAX_PF_LENGTH 250
+
Index: src/dungeon.c
===================================================================
RCS file: /home/rr9/angband/angband/src/dungeon.c,v
retrieving revision 1.42
diff -u -r1.42 dungeon.c
--- src/dungeon.c	27 Aug 2003 20:21:12 -0000	1.42
+++ src/dungeon.c	21 Jan 2004 20:55:19 -0000
@@ -1203,7 +1203,8 @@
  */
 static void process_command(void)
 {
-
+	int x,y;
+	
 #ifdef ALLOW_REPEAT
 
 	/* Handle repeating the last command */
@@ -1797,6 +1798,15 @@
 		case ')':
 		{
 			do_cmd_save_screen();
+			break;
+		}
+
+		/* Mouse click */
+		case '\xff':
+		{
+			x = p_ptr->command_cmd_ex.mousex + p_ptr->wx;
+			y = p_ptr->command_cmd_ex.mousey + p_ptr->wy;
+			do_cmd_pathfind(y,x);
 			break;
 		}
 
Index: src/externs.h
===================================================================
RCS file: /home/rr9/angband/angband/src/externs.h,v
retrieving revision 1.108
diff -u -r1.108 externs.h
--- src/externs.h	10 Aug 2003 10:52:45 -0000	1.108
+++ src/externs.h	21 Jan 2004 20:55:19 -0000
@@ -26,6 +26,10 @@
 extern cptr macro_trigger_name[MAX_MACRO_TRIGGER];
 extern cptr macro_trigger_keycode[2][MAX_MACRO_TRIGGER];
 
+/* pathfind.c */
+extern char pf_result[MAX_PF_LENGTH];
+extern int pf_result_index;
+
 /* tables.c */
 extern const s16b ddd[9];
 extern const s16b ddx[10];
@@ -293,6 +297,7 @@
 extern void py_attack(int y, int x);
 extern void move_player(int dir, int jumping);
 extern void run_step(int dir);
+bool do_cmd_walk_test(int y, int x);
 
 /* cmd2.c */
 extern void do_cmd_go_up(void);
@@ -309,6 +314,7 @@
 extern void do_cmd_walk(void);
 extern void do_cmd_jump(void);
 extern void do_cmd_run(void);
+extern void do_cmd_pathfind(int y, int x);
 extern void do_cmd_hold(void);
 extern void do_cmd_stay(void);
 extern void do_cmd_rest(void);
@@ -534,6 +540,9 @@
 extern void print_spells(const byte *spells, int num, int y, int x);
 extern void display_koff(int k_idx);
 
+/* pathfind.c */
+extern bool findpath(int y, int x);
+
 /* save.c */
 extern bool save_player(void);
 
@@ -670,6 +679,7 @@
 extern void flush(void);
 extern void flush_fail(void);
 extern char inkey(void);
+extern key_event inkey_ex(void);
 extern void bell(cptr reason);
 extern void sound(int val);
 extern s16b quark_add(cptr str);
@@ -706,6 +716,7 @@
 extern s16b get_quantity(cptr prompt, int max);
 extern bool get_check(cptr prompt);
 extern bool get_com(cptr prompt, char *command);
+extern bool get_com_ex(cptr prompt, key_event *command);
 extern void pause_line(int row);
 extern void request_command(bool shopping);
 extern int damroll(int num, int sides);
Index: src/main-win.c
===================================================================
RCS file: /home/rr9/angband/angband/src/main-win.c,v
retrieving revision 1.61
diff -u -r1.61 main-win.c
--- src/main-win.c	21 Feb 2003 16:58:09 -0000	1.61
+++ src/main-win.c	21 Jan 2004 20:55:22 -0000
@@ -245,6 +245,7 @@
  * Include the "windows" support file
  */
 #include <windows.h>
+#include <windowsx.h>
 
 #ifdef USE_SOUND
 
@@ -3939,6 +3940,8 @@
 	term_data *td;
 	int i;
 
+	int xPos, yPos, button;
+
 #ifdef USE_SAVER
 	static int iMouse = 0;
 	static WORD xMouse = 0;
@@ -4054,21 +4057,36 @@
 			return 0;
 		}
 
-#ifdef USE_SAVER
-
 		case WM_MBUTTONDOWN:
 		case WM_RBUTTONDOWN:
 		case WM_LBUTTONDOWN:
 		{
+#ifdef USE_SAVER
 			if (screensaver_active)
 			{
 				stop_screensaver();
 				return 0;
 			}
-
 			break;
+#else
+			xPos = GET_X_LPARAM(lParam);
+			yPos = GET_Y_LPARAM(lParam);
+			xPos = (xPos - 13 * td->font_wid) / td->tile_wid;
+			if (use_bigtile)
+				xPos /= 2;
+			yPos = yPos / td->tile_hgt - 1;
+			if (uMsg == WM_LBUTTONDOWN)
+				button = 1;
+			else if (uMsg == WM_RBUTTONDOWN)
+				button = 2;
+			else
+				button = 3;
+			Term_mousepress(xPos,yPos,button);
+			break;
+#endif /* USE_SAVER */
 		}
 
+#ifdef USE_SAVER
 		case WM_MOUSEMOVE:
 		{
 			if (!screensaver_active) break;
@@ -4450,8 +4468,8 @@
 			return 0;
 		}
 
-#ifdef USE_SAVER
 
+#ifdef USE_SAVER
 		case WM_MBUTTONDOWN:
 		case WM_RBUTTONDOWN:
 		case WM_LBUTTONDOWN:
@@ -4461,7 +4479,6 @@
 				stop_screensaver();
 				return 0;
 			}
-
 			break;
 		}
 
Index: src/main-x11.c
===================================================================
RCS file: /home/rr9/angband/angband/src/main-x11.c,v
retrieving revision 1.27
diff -u -r1.27 main-x11.c
--- src/main-x11.c	10 Aug 2003 16:02:08 -0000	1.27
+++ src/main-x11.c	21 Jan 2004 20:55:23 -0000
@@ -1632,8 +1632,8 @@
 static void pixel_to_square(int * const x, int * const y,
 	const int ox, const int oy)
 {
-	(*x) = (ox - Infowin->ox) / Infofnt->wid;
-	(*y) = (oy - Infowin->oy) / Infofnt->hgt;
+	(*x) = (ox - Infowin->ox - 13 * Infofnt->wid) / Infofnt->twid;
+	(*y) = (oy - Infowin->oy) / Infofnt->hgt - 1;
 }
 
 /*
@@ -1642,7 +1642,7 @@
 static void square_to_pixel(int * const x, int * const y,
                             const int ox, const int oy)
 {
-	(*x) = ox * Infofnt->wid + Infowin->ox;
+	(*x) = ox * Infofnt->twid + Infowin->ox;
 	(*y) = oy * Infofnt->hgt + Infowin->oy;
 }
 
@@ -1899,8 +1899,12 @@
 	/* The co-ordinates are only used in Angband format. */
 	pixel_to_square(&x, &y, x, y);
 
+#if 0
 	if (press && button == 1) copy_x11_start(x, y);
 	if (!press && button == 1) copy_x11_end(time);
+#endif
+	
+	if (press) Term_mousepress(x,y,button);
 }
 
 
@@ -2002,9 +2006,11 @@
 			/* Convert to co-ordinates Angband understands. */
 			pixel_to_square(&x, &y, x, y);
 
+#if 0
 			/* Alter the selection if appropriate. */
 			copy_x11_cont(x, y, z);
-
+#endif
+			
 			break;
 		}
 
Index: src/types.h
===================================================================
RCS file: /home/rr9/angband/angband/src/types.h,v
retrieving revision 1.37
diff -u -r1.37 types.h
--- src/types.h	23 Nov 2003 17:41:53 -0000	1.37
+++ src/types.h	21 Jan 2004 20:55:24 -0000
@@ -930,6 +930,7 @@
 
 	s16b resting;			/* Resting counter */
 	s16b running;			/* Running counter */
+	bool running_withpathfind;      /* Are we using the pathfinder ? */
 
 	s16b run_cur_dir;		/* Direction we are running */
 	s16b run_old_dir;		/* Direction we came from */
@@ -942,6 +943,7 @@
 	s16b command_arg;		/* Gives argument of current command */
 	s16b command_rep;		/* Gives repetition of current command */
 	s16b command_dir;		/* Gives direction of current command */
+	key_event command_cmd_ex; /* Gives additional information of current command */
 
 	s16b command_see;		/* See "cmd1.c" */
 	s16b command_wrk;		/* See "cmd1.c" */
Index: src/util.c
===================================================================
RCS file: /home/rr9/angband/angband/src/util.c,v
retrieving revision 1.93
diff -u -r1.93 util.c
--- src/util.c	4 Oct 2003 17:49:02 -0000	1.93
+++ src/util.c	21 Jan 2004 20:55:26 -0000
@@ -1694,33 +1694,38 @@
  * macro trigger, 500 milliseconds must pass before the key sequence is
  * known not to be that macro trigger.  XXX XXX XXX
  */
-static char inkey_aux(void)
+static key_event inkey_aux(void)
 {
 	int k, n;
 	int p = 0, w = 0;
 
+	key_event ke, ke0;
 	char ch;
 
 	cptr pat, act;
 
 	char buf[1024];
 
+  /* Initialize the no return */
+  ke0.key = 0;
 
 	/* Wait for a keypress */
-	(void)(Term_inkey(&ch, TRUE, TRUE));
+	(void)(Term_inkey(&ke, TRUE, TRUE));
+	ch = ke.key;
 
 
 	/* End "macro action" */
-	if (ch == 30) parse_macro = FALSE;
+	if ((ch == 30) || (ch == '\xff'))
+  {
+    parse_macro = FALSE;
+    return (ke);
+  }
 
 	/* Inside "macro action" */
-	if (ch == 30) return (ch);
-
-	/* Inside "macro action" */
-	if (parse_macro) return (ch);
+	if (parse_macro) return (ke);
 
 	/* Inside "macro trigger" */
-	if (parse_under) return (ch);
+	if (parse_under) return (ke);
 
 
 	/* Save the first key, advance */
@@ -1732,7 +1737,7 @@
 	k = macro_find_check(buf);
 
 	/* No macro pending */
-	if (k < 0) return (ch);
+	if (k < 0) return (ke);
 
 
 	/* Wait for a macro, or a timeout */
@@ -1745,10 +1750,10 @@
 		if (k < 0) break;
 
 		/* Check for (and remove) a pending key */
-		if (0 == Term_inkey(&ch, FALSE, TRUE))
+		if (0 == Term_inkey(&ke, FALSE, TRUE))
 		{
 			/* Append the key */
-			buf[p++] = ch;
+			buf[p++] = ke.key;
 			buf[p] = '\0';
 
 			/* Restart wait */
@@ -1780,14 +1785,14 @@
 		while (p > 0)
 		{
 			/* Push the key, notice over-flow */
-			if (Term_key_push(buf[--p])) return (0);
+			if (Term_key_push(buf[--p])) return (ke0);
 		}
 
 		/* Wait for (and remove) a pending key */
-		(void)Term_inkey(&ch, TRUE, TRUE);
+		(void)Term_inkey(&ke, TRUE, TRUE);
 
 		/* Return the key */
-		return (ch);
+		return (ke);
 	}
 
 
@@ -1801,7 +1806,7 @@
 	while (p > n)
 	{
 		/* Push the key, notice over-flow */
-		if (Term_key_push(buf[--p])) return (0);
+		if (Term_key_push(buf[--p])) return (ke0);
 	}
 
 
@@ -1809,7 +1814,7 @@
 	parse_macro = TRUE;
 
 	/* Push the "end of macro action" key */
-	if (Term_key_push(30)) return (0);
+	if (Term_key_push(30)) return (ke0);
 
 
 	/* Get the macro action */
@@ -1822,12 +1827,12 @@
 	while (n > 0)
 	{
 		/* Push the key, notice over-flow */
-		if (Term_key_push(act[--n])) return (0);
+		if (Term_key_push(act[--n])) return (ke0);
 	}
 
 
 	/* Hack -- Force "inkey()" to call us again */
-	return (0);
+	return (ke0);
 }
 
 
@@ -1920,44 +1925,56 @@
  */
 char inkey(void)
 {
+	key_event ke;
+	do
+	{
+		ke = inkey_ex();
+	} while (ke.key == '\xff');
+	return ke.key;
+}
+
+key_event inkey_ex(void)
+{
 	bool cursor_state;
 
-	char kk;
+	key_event kk;
 
-	char ch = 0;
+	key_event ke;
 
 	bool done = FALSE;
 
 	term *old = Term;
 
-
+	ke.key = 0;
 	/* Hack -- Use the "inkey_next" pointer */
 	if (inkey_next && *inkey_next && !inkey_xtra)
 	{
 		/* Get next character, and advance */
-		ch = *inkey_next++;
+		ke.key = *inkey_next++;
 
 		/* Cancel the various "global parameters" */
 		inkey_base = inkey_xtra = inkey_flag = inkey_scan = FALSE;
 
 		/* Accept result */
-		return (ch);
+		return (ke);
 	}
 
 	/* Forget pointer */
 	inkey_next = NULL;
 
 
+
+
 #ifdef ALLOW_BORG
 
 	/* Mega-Hack -- Use the special hook */
-	if (inkey_hack && ((ch = (*inkey_hack)(inkey_xtra)) != 0))
+	if (inkey_hack && ((ke.key = (*inkey_hack)(inkey_xtra)) != 0))
 	{
 		/* Cancel the various "global parameters" */
 		inkey_base = inkey_xtra = inkey_flag = inkey_scan = FALSE;
 
 		/* Accept result */
-		return (ch);
+		return (ke);
 	}
 
 #endif /* ALLOW_BORG */
@@ -1993,7 +2010,7 @@
 
 
 	/* Get a key */
-	while (!ch)
+	while (!ke.key)
 	{
 		/* Hack -- Handle "inkey_scan" */
 		if (!inkey_base && inkey_scan &&
@@ -2035,7 +2052,7 @@
 			if (!inkey_scan)
 			{
 				/* Wait for (and remove) a pending key */
-				if (0 == Term_inkey(&ch, TRUE, TRUE))
+				if (0 == Term_inkey(&ke, TRUE, TRUE))
 				{
 					/* Done */
 					break;
@@ -2049,7 +2066,7 @@
 			while (TRUE)
 			{
 				/* Check for (and remove) a pending key */
-				if (0 == Term_inkey(&ch, FALSE, TRUE))
+				if (0 == Term_inkey(&ke, FALSE, TRUE))
 				{
 					/* Done */
 					break;
@@ -2075,14 +2092,14 @@
 
 
 		/* Get a key (see above) */
-		ch = inkey_aux();
+		ke = inkey_aux();
 
 
 		/* Handle "control-right-bracket" */
-		if (ch == 29)
+		if (ke.key == 29)
 		{
 			/* Strip this key */
-			ch = 0;
+			ke.key = 0;
 
 			/* Continue */
 			continue;
@@ -2090,14 +2107,14 @@
 
 
 		/* Treat back-quote as escape */
-		if (ch == '`') ch = ESCAPE;
+		if (ke.key == '`') ke.key = ESCAPE;
 
 
 		/* End "macro trigger" */
-		if (parse_under && (ch <= 32))
+		if (parse_under && (ke.key <= 32))
 		{
 			/* Strip this key */
-			ch = 0;
+			ke.key = 0;
 
 			/* End "macro trigger" */
 			parse_under = FALSE;
@@ -2105,17 +2122,17 @@
 
 
 		/* Handle "control-caret" */
-		if (ch == 30)
+		if (ke.key == 30)
 		{
 			/* Strip this key */
-			ch = 0;
+			ke.key = 0;
 		}
 
 		/* Handle "control-underscore" */
-		else if (ch == 31)
+		else if (ke.key == 31)
 		{
 			/* Strip this key */
-			ch = 0;
+			ke.key = 0;
 
 			/* Begin "macro trigger" */
 			parse_under = TRUE;
@@ -2125,7 +2142,7 @@
 		else if (parse_under)
 		{
 			/* Strip this key */
-			ch = 0;
+			ke.key = 0;
 		}
 	}
 
@@ -2143,7 +2160,7 @@
 
 
 	/* Return the keypress */
-	return (ch);
+	return (ke);
 }
 
 
@@ -3717,7 +3734,18 @@
  */
 bool get_com(cptr prompt, char *command)
 {
-	char ch;
+	key_event ke;
+	bool result;
+	result = get_com_ex(prompt, &ke);
+	*command = ke.key;
+  if (ke.key == '\xff')
+     bell("Potential loss of mouse input");
+	return result;
+}
+
+bool get_com_ex(cptr prompt, key_event *command)
+{
+	key_event ke;
 
 	/* Paranoia XXX XXX XXX */
 	message_flush();
@@ -3726,16 +3754,16 @@
 	prt(prompt, 0, 0);
 
 	/* Get a key */
-	ch = inkey();
+	ke = inkey_ex();
 
 	/* Clear the prompt */
 	prt("", 0, 0);
 
 	/* Save the command */
-	*command = ch;
+	*command = ke;
 
 	/* Done */
-	return (ch != ESCAPE);
+	return (ke.key != ESCAPE);
 }
 
 
@@ -3784,7 +3812,7 @@
 {
 	int i;
 
-	char ch;
+	key_event ke;
 
 	int mode;
 
@@ -3824,7 +3852,7 @@
 			message_flush();
 
 			/* Use auto-command */
-			ch = (char)p_ptr->command_new;
+			ke.key = (char)p_ptr->command_new;
 
 			/* Forget it */
 			p_ptr->command_new = 0;
@@ -3840,7 +3868,7 @@
 			inkey_flag = TRUE;
 
 			/* Get a command */
-			ch = inkey();
+			ke = inkey_ex();
 		}
 
 		/* Clear top line */
@@ -3848,7 +3876,7 @@
 
 
 		/* Command Count */
-		if (ch == '0')
+		if (ke.key == '0')
 		{
 			int old_arg = p_ptr->command_arg;
 
@@ -3862,10 +3890,10 @@
 			while (1)
 			{
 				/* Get a new keypress */
-				ch = inkey();
+				ke.key = inkey();
 
 				/* Simple editing (delete or backspace) */
-				if ((ch == 0x7F) || (ch == KTRL('H')))
+				if ((ke.key == 0x7F) || (ke.key == KTRL('H')))
 				{
 					/* Delete a digit */
 					p_ptr->command_arg = p_ptr->command_arg / 10;
@@ -3875,7 +3903,7 @@
 				}
 
 				/* Actual numeric data */
-				else if (isdigit((unsigned char)ch))
+				else if (isdigit((unsigned char)ke.key))
 				{
 					/* Stop count at 9999 */
 					if (p_ptr->command_arg >= 1000)
@@ -3891,7 +3919,7 @@
 					else
 					{
 						/* Incorporate that digit */
-						p_ptr->command_arg = p_ptr->command_arg * 10 + D2I(ch);
+						p_ptr->command_arg = p_ptr->command_arg * 10 + D2I(ke.key);
 					}
 
 					/* Show current count */
@@ -3926,10 +3954,10 @@
 			}
 
 			/* Hack -- white-space means "enter command now" */
-			if ((ch == ' ') || (ch == '\n') || (ch == '\r'))
+			if ((ke.key == ' ') || (ke.key == '\n') || (ke.key == '\r'))
 			{
 				/* Get a real command */
-				if (!get_com("Command: ", &ch))
+				if (!get_com("Command: ", &ke.key))
 				{
 					/* Clear count */
 					p_ptr->command_arg = 0;
@@ -3942,10 +3970,10 @@
 
 
 		/* Allow "keymaps" to be bypassed */
-		if (ch == '\\')
+		if (ke.key == '\\')
 		{
 			/* Get a real command */
-			(void)get_com("Command: ", &ch);
+			(void)get_com("Command: ", &ke.key);
 
 			/* Hack -- bypass keymaps */
 			if (!inkey_next) inkey_next = "";
@@ -3953,15 +3981,15 @@
 
 
 		/* Allow "control chars" to be entered */
-		if (ch == '^')
+		if (ke.key == '^')
 		{
 			/* Get a new command and controlify it */
-			if (get_com("Control: ", &ch)) ch = KTRL(ch);
+			if (get_com("Control: ", &ke.key)) ke.key = KTRL(ke.key);
 		}
 
 
 		/* Look up applicable keymap */
-		act = keymap_act[mode][(byte)(ch)];
+		act = keymap_act[mode][(byte)(ke.key)];
 
 		/* Apply keymap if not inside a keymap already */
 		if (act && !inkey_next)
@@ -3978,11 +4006,12 @@
 
 
 		/* Paranoia */
-		if (ch == '\0') continue;
+		if (ke.key == '\0') continue;
 
 
 		/* Use command */
-		p_ptr->command_cmd = ch;
+		p_ptr->command_cmd = ke.key;
+		p_ptr->command_cmd_ex = ke;
 
 		/* Done */
 		break;
@@ -4056,6 +4085,9 @@
 
 	/* Hack -- erase the message line. */
 	prt("", 0, 0);
+
+	/* Hack again -- apply the modified key command */
+	p_ptr->command_cmd_ex.key = p_ptr->command_cmd;
 }
 
 
Index: src/xtra2.c
===================================================================
RCS file: /home/rr9/angband/angband/src/xtra2.c,v
retrieving revision 1.34
diff -u -r1.34 xtra2.c
--- src/xtra2.c	21 Mar 2003 20:53:55 -0000	1.34
+++ src/xtra2.c	21 Jan 2004 20:55:28 -0000
@@ -2753,6 +2753,8 @@
 		p_ptr->target_who = 0;
 		p_ptr->target_row = 0;
 		p_ptr->target_col = 0;
+
+		printf("In bounds check failed : %d %d\n", x,y);
 	}
 }
 
@@ -3014,7 +3016,7 @@
  *
  * This function must handle blindness/hallucination.
  */
-static int target_set_interactive_aux(int y, int x, int mode, cptr info)
+static key_event target_set_interactive_aux(int y, int x, int mode, cptr info)
 {
 	s16b this_o_idx, next_o_idx = 0;
 
@@ -3026,7 +3028,7 @@
 
 	int feat;
 
-	int query;
+	key_event query;
 
 	char out_val[256];
 
@@ -3035,7 +3037,7 @@
 	while (1)
 	{
 		/* Paranoia */
-		query = ' ';
+		query.key = ' ';
 
 		/* Assume boring */
 		boring = TRUE;
@@ -3076,10 +3078,10 @@
 
 			prt(out_val, 0, 0);
 			move_cursor_relative(y, x);
-			query = inkey();
+			query = inkey_ex();
 
 			/* Stop on everything but "return" */
-			if ((query != '\n') && (query != '\r')) break;
+			if ((query.key != '\n') && (query.key != '\r')) break;
 
 			/* Repeat forever */
 			continue;
@@ -3130,7 +3132,7 @@
 						Term_addstr(-1, TERM_WHITE, format("  [r,%s]", info));
 
 						/* Command */
-						query = inkey();
+						query = inkey_ex();
 
 						/* Load screen */
 						screen_load();
@@ -3164,21 +3166,21 @@
 						move_cursor_relative(y, x);
 
 						/* Command */
-						query = inkey();
+						query = inkey_ex();
 					}
 
 					/* Normal commands */
-					if (query != 'r') break;
+					if (query.key != 'r') break;
 
 					/* Toggle recall */
 					recall = !recall;
 				}
 
 				/* Stop on everything but "return"/"space" */
-				if ((query != '\n') && (query != '\r') && (query != ' ')) break;
+				if ((query.key != '\n') && (query.key != '\r') && (query.key != ' ')) break;
 
 				/* Sometimes stop at "space" key */
-				if ((query == ' ') && !(mode & (TARGET_LOOK))) break;
+				if ((query.key == ' ') && !(mode & (TARGET_LOOK))) break;
 
 				/* Change the intro */
 				s1 = "It is ";
@@ -3221,13 +3223,13 @@
 
 					prt(out_val, 0, 0);
 					move_cursor_relative(y, x);
-					query = inkey();
+					query = inkey_ex();
 
 					/* Stop on everything but "return"/"space" */
-					if ((query != '\n') && (query != '\r') && (query != ' ')) break;
+					if ((query.key != '\n') && (query.key != '\r') && (query.key != ' ')) break;
 
 					/* Sometimes stop at "space" key */
-					if ((query == ' ') && !(mode & (TARGET_LOOK))) break;
+					if ((query.key == ' ') && !(mode & (TARGET_LOOK))) break;
 
 					/* Change the intro */
 					s2 = "also carrying ";
@@ -3282,10 +3284,10 @@
 
 					prt(out_val, 0, 0);
 					move_cursor_relative(y, x);
-					query = inkey();
+					query = inkey_ex();
 
 					/* Display objects */
-					if (query == 'r')
+					if (query.key == 'r')
 					{
 						/* Save screen */
 						screen_save();
@@ -3295,13 +3297,13 @@
 
 						/* Describe the pile */
 						prt(out_val, 0, 0);
-						query = inkey();
+						query = inkey_ex();
 
 						/* Load screen */
 						screen_load();
 
 						/* Continue on 'r' only */
-						if (query == 'r') continue;
+						if (query.key == 'r') continue;
 					}
 
 					/* Done */
@@ -3309,10 +3311,10 @@
 				}
 
 				/* Stop on everything but "return"/"space" */
-				if ((query != '\n') && (query != '\r') && (query != ' ')) break;
+				if ((query.key != '\n') && (query.key != '\r') && (query.key != ' ')) break;
 
 				/* Sometimes stop at "space" key */
-				if ((query == ' ') && !(mode & (TARGET_LOOK))) break;
+				if ((query.key == ' ') && !(mode & (TARGET_LOOK))) break;
 
 				/* Change the intro */
 				s1 = "It is ";
@@ -3362,13 +3364,13 @@
 
 				prt(out_val, 0, 0);
 				move_cursor_relative(y, x);
-				query = inkey();
+				query = inkey_ex();
 
 				/* Stop on everything but "return"/"space" */
-				if ((query != '\n') && (query != '\r') && (query != ' ')) break;
+				if ((query.key != '\n') && (query.key != '\r') && (query.key != ' ')) break;
 
 				/* Sometimes stop at "space" key */
-				if ((query == ' ') && !(mode & (TARGET_LOOK))) break;
+				if ((query.key == ' ') && !(mode & (TARGET_LOOK))) break;
 
 				/* Change the intro */
 				s1 = "It is ";
@@ -3429,14 +3431,14 @@
 
 			prt(out_val, 0, 0);
 			move_cursor_relative(y, x);
-			query = inkey();
+			query = inkey_ex();
 
 			/* Stop on everything but "return"/"space" */
-			if ((query != '\n') && (query != '\r') && (query != ' ')) break;
+			if ((query.key != '\n') && (query.key != '\r') && (query.key != ' ')) break;
 		}
 
 		/* Stop on everything but "return" */
-		if ((query != '\n') && (query != '\r')) break;
+		if ((query.key != '\n') && (query.key != '\r')) break;
 	}
 
 	/* Keep going */
@@ -3503,7 +3505,7 @@
 
 	bool flag = TRUE;
 
-	char query;
+	key_event query;
 
 	char info[80];
 
@@ -3553,7 +3555,7 @@
 			d = 0;
 
 			/* Analyze */
-			switch (query)
+			switch (query.key)
 			{
 				case ESCAPE:
 				case 'q':
@@ -3610,6 +3612,14 @@
 					break;
 				}
 
+				case '\xff':
+				{
+					x = query.mousex + p_ptr->wx;
+					y = query.mousey + p_ptr->wy;
+					target_set_location(y, x);
+					done = TRUE;
+					break;
+				}
 				case 't':
 				case '5':
 				case '0':
@@ -3630,10 +3640,17 @@
 					break;
 				}
 
+				case 'g':
+				{
+					do_cmd_pathfind(y,x);
+					done = TRUE;
+					break;
+				}
+
 				default:
 				{
 					/* Extract direction */
-					d = target_dir(query);
+					d = target_dir(query.key);
 
 					/* Oops */
 					if (!d) bell("Illegal command for target mode!");
@@ -3699,7 +3716,7 @@
 			d = 0;
 
 			/* Analyze the keypress */
-			switch (query)
+			switch (query.key)
 			{
 				case ESCAPE:
 				case 'q':
@@ -3762,6 +3779,11 @@
 					break;
 				}
 
+				case '\xff':
+				{
+					x = query.mousex + p_ptr->wx;
+					y = query.mousey + p_ptr->wy;
+				}
 				case 't':
 				case '5':
 				case '0':
@@ -3772,10 +3794,17 @@
 					break;
 				}
 
+				case 'g':
+				{
+					do_cmd_pathfind(y,x);
+					done = TRUE;
+					break;
+				}
+
 				default:
 				{
 					/* Extract a direction */
-					d = target_dir(query);
+					d = target_dir(query.key);
 
 					/* Oops */
 					if (!d) bell("Illegal command for target mode!");
@@ -3869,7 +3898,7 @@
 {
 	int dir;
 
-	char ch;
+	key_event ke;
 
 	cptr p;
 
@@ -3914,11 +3943,19 @@
 		}
 
 		/* Get a command (or Cancel) */
-		if (!get_com(p, &ch)) break;
+		if (!get_com_ex(p, &ke)) break;
 
 		/* Analyze */
-		switch (ch)
+		switch (ke.key)
 		{
+			/* Mouse aiming */
+			case '\xff':
+			{
+				target_set_location(ke.mousey + p_ptr->wy, ke.mousex + p_ptr->wx);
+				dir = 5;
+				break;
+			}
+			
 			/* Set new target, use target if legal */
 			case '*':
 			{
@@ -3939,7 +3976,7 @@
 			/* Possible direction */
 			default:
 			{
-				dir = target_dir(ch);
+				dir = target_dir(ke.key);
 				break;
 			}
 		}
Index: src/z-term.c
===================================================================
RCS file: /home/rr9/angband/angband/src/z-term.c,v
retrieving revision 1.15
diff -u -r1.15 z-term.c
--- src/z-term.c	28 Jul 2002 19:16:41 -0000	1.15
+++ src/z-term.c	21 Jan 2004 20:55:29 -0000
@@ -1876,7 +1876,7 @@
 	if (!k) return (-1);
 
 	/* Store the char, advance the queue */
-	Term->key_queue[Term->key_head++] = k;
+	Term->key_queue[Term->key_head++].key = k;
 
 	/* Circular queue, handle wrap */
 	if (Term->key_head == Term->key_size) Term->key_head = 0;
@@ -1893,6 +1893,34 @@
 	return (1);
 }
 
+/*
+ * Add a mouse event to the "queue"
+ */
+errr Term_mousepress(int x, int y, int button)
+{
+	/* Store the char, advance the queue */
+	Term->key_queue[Term->key_head].key = '\xff';
+	Term->key_queue[Term->key_head].mousex = x;
+	Term->key_queue[Term->key_head].mousey = y;
+	Term->key_queue[Term->key_head].mousebutton = button;
+	Term->key_head++;
+
+	/* Circular queue, handle wrap */
+	if (Term->key_head == Term->key_size) Term->key_head = 0;
+
+	/* Success (unless overflow) */
+	if (Term->key_head != Term->key_tail) return (0);
+
+#if 0
+	/* Hack -- Forget the oldest key */
+	if (++Term->key_tail == Term->key_size) Term->key_tail = 0;
+#endif
+
+	/* Problem */
+	return (1);
+}
+
+
 
 /*
  * Add a keypress to the FRONT of the "queue"
@@ -1906,7 +1934,7 @@
 	if (Term->key_tail == 0) Term->key_tail = Term->key_size;
 
 	/* Back up, Store the char */
-	Term->key_queue[--Term->key_tail] = k;
+	Term->key_queue[--Term->key_tail].key = k;
 
 	/* Success (unless overflow) */
 	if (Term->key_head != Term->key_tail) return (0);
@@ -1934,10 +1962,10 @@
  *
  * Remove the keypress if "take" is true.
  */
-errr Term_inkey(char *ch, bool wait, bool take)
+errr Term_inkey(key_event *ke, bool wait, bool take)
 {
 	/* Assume no key */
-	(*ch) = '\0';
+	ke->key = '\0';
 
 	/* Hack -- get bored */
 	if (!Term->never_bored)
@@ -1972,7 +2000,7 @@
 	if (Term->key_head == Term->key_tail) return (1);
 
 	/* Extract the next keypress */
-	(*ch) = Term->key_queue[Term->key_tail];
+	memcpy(ke, &Term->key_queue[Term->key_tail], sizeof(key_event));
 
 	/* If requested, advance the queue, wrap around if necessary */
 	if (take && (++Term->key_tail == Term->key_size)) Term->key_tail = 0;
@@ -2405,7 +2433,7 @@
 	t->key_size = k;
 
 	/* Allocate the input queue */
-	C_MAKE(t->key_queue, t->key_size, char);
+	C_MAKE(t->key_queue, t->key_size, key_event);
 
 
 	/* Save the size */
Index: src/z-term.h
===================================================================
RCS file: /home/rr9/angband/angband/src/z-term.h,v
retrieving revision 1.7
diff -u -r1.7 z-term.h
--- src/z-term.h	28 Jul 2002 19:16:41 -0000	1.7
+++ src/z-term.h	21 Jan 2004 20:55:29 -0000
@@ -155,6 +155,14 @@
 
 typedef struct term term;
 
+typedef struct key_event key_event;
+
+struct key_event
+{
+	int mousex, mousey;
+	char mousebutton, key;
+};
+
 struct term
 {
 	void *user;
@@ -181,7 +189,7 @@
 	byte attr_blank;
 	char char_blank;
 
-	char *key_queue;
+	key_event *key_queue;
 
 	u16b key_head;
 	u16b key_tail;
@@ -295,8 +303,9 @@
 
 extern errr Term_flush(void);
 extern errr Term_keypress(int k);
+extern errr Term_mousepress(int x, int y, int button);
 extern errr Term_key_push(int k);
-extern errr Term_inkey(char *ch, bool wait, bool take);
+extern errr Term_inkey(key_event *ke, bool wait, bool take);
 
 extern errr Term_save(void);
 extern errr Term_load(void);
