Often, navigating to a location and pressing some key will have the same effect as clicking at that location. There's no built-in mechanism that ensures this, it's just that modes are typically written that way.
You can generate mouse events (click, double/triple/… click, button down/up, drag, motion). All mouse events have the form (TYPE POSITION . EXTRA-DATA)
where TYPE is a symbol that encodes the mouse button, the nature of the action (click, drag, etc.), and the modifiers. TYPE is mouse-movement
for a motion event. Call posn-at-point
to generate the POSITION for the location of the point in the current buffer.
Here's some proof-of-concept code that simulates a mouse click at the cursor position when you press f11
followed by a digit. Modifiers are taken into account.
(defun make-mouse-event-at-point (base-event)
(let ((posn (posn-at-point))
(prefix "")
(basic-type (event-basic-type base-event))
(modifiers (event-modifiers base-event)))
(cond
((and (integerp basic-type) (>= basic-type ?0) (<= basic-type ?9))
;; click
(let* ((mouse-type (intern (format "%smouse-%d" prefix (- basic-type ?0))))
(click-count 1)
(type (event-convert-list (append modifiers (list mouse-type)))))
(list type posn click-count)))
(t
(error "Unsupported key for mouse event: %s" (event-basic-type base-event))))))
(defun simulate-mouse-event-at-point ()
(interactive)
(let ((event (make-mouse-event-at-point last-input-event)))
(setq unread-command-events (cons event unread-command-events))))
(defvar simulate-mouse-event-map (make-sparse-keymap))
(global-set-key [f11] simulate-mouse-event-map)
(define-key simulate-mouse-event-map [t] 'simulate-mouse-event-at-point)
Simulating hover looks more difficult.