Function: set-mouse-pixel-position

set-mouse-pixel-position is a function defined in frame.c.

Signature

(set-mouse-pixel-position FRAME X Y)

Documentation

Move the mouse pointer to pixel position (X,Y) in FRAME.

The position is given in pixels, where (0, 0) is the upper-left corner of the frame, X is the horizontal offset, and Y is the vertical offset.

Note, this 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))

View in manual

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)))
    {
      /* Warping the mouse will cause enternotify and focus events.  */
#ifdef HAVE_WINDOW_SYSTEM
      frame_set_mouse_pixel_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;
}