Function: set-mouse-position
set-mouse-position is a function defined in frame.c.
Signature
(set-mouse-position FRAME X Y)
Documentation
Move the mouse pointer to the center of character cell (X,Y) in FRAME.
Coordinates are relative to the frame, not a window, so the coordinates of the top left character in the frame may be nonzero due to left-hand scroll bars or the menu bar.
The position is given in canonical character cells, where (0, 0) is the upper-left corner of the frame, X is the horizontal offset, and Y is the vertical offset, measured in units of the frame's default character size.
This function is a no-op for an X frame that is not visible.
If you have just created a frame, you must wait for it to become visible
before calling this function on it, like this.
(while (not (frame-visible-p frame)) (sleep-for .5))
Probably introduced at or before Emacs version 19.23.
Source Code
// Defined in /usr/src/emacs/src/frame.c
{
CHECK_LIVE_FRAME (frame);
int xval = check_integer_range (x, INT_MIN, INT_MAX);
int yval = check_integer_range (y, INT_MIN, INT_MAX);
/* I think this should be done with a hook. */
if (FRAME_WINDOW_P (XFRAME (frame)))
{
#ifdef HAVE_WINDOW_SYSTEM
/* Warping the mouse will cause enternotify and focus events. */
frame_set_mouse_position (XFRAME (frame), xval, yval);
#endif /* HAVE_WINDOW_SYSTEM */
}
#ifdef MSDOS
else if (FRAME_MSDOS_P (XFRAME (frame)))
{
Fselect_frame (frame, Qnil);
mouse_moveto (xval, yval);
}
#endif /* MSDOS */
else
{
Fselect_frame (frame, Qnil);
#ifdef HAVE_GPM
term_mouse_moveto (xval, yval);
#else
(void) xval;
(void) yval;
#endif /* HAVE_GPM */
}
return Qnil;
}