title: How to generate mouse event programmatically?
body: <p>There are two very useful functions in SLIME: <code>slime-copy-or-inspect-presentation-at-mouse</code> and <code>slime-presentation-menu</code>. But they must be called with an event argument. In order to generate an even I'd need to do a lot of logistics (calculating the region occupied by a printed representation of the object the "mouse" is currently pointing at, lines and columns - something I don't really want to do because, certainly there's something in Emacs that calculates all that stuff already.</p>
  
  <p>So, is there an easy way to generate "fake" mouse event? Because using mouse for only two things in an editor that otherwise doesn't require mouse feels... well, not very smart. :)</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Here's what I've tried:</p>
  
  <pre><code>(define-key lisp-mode-map (kbd "C-x ?")
    #'(lambda ()
        (interactive)
        (message "called")
        (slime-copy-or-inspect-presentation-at-mouse
         `(mouse-2 ;; button
       (,(selected-window) ;; window
        ,(point) ;; position
        (0 . 0) ;; window-relative pixel
        0 ;; timestamp
        nil ;; object
        ,(point) ;; text position 
        (,(current-column) . ;; column
         ,(line-number-at-pos (point))) ;; line
        nil ;; image
        (0 . 0) ;; object-relative pixel
        (1 . 1))))))
  (define-key lisp-mode-map (kbd "C-x SPC")
    #'(lambda ()
        (interactive)
        (message "called")
        (slime-presentation-menu
         `(mouse-3 ;; button
       (,(selected-window) ;; window
        ,(point) ;; position
        (0 . 0) ;; window-relative pixel
        0 ;; timestamp
        nil ;; object
        ,(point) ;; text position 
        (,(current-column) . ;; column
         ,(line-number-at-pos (point))) ;; line
        nil ;; image
        (0 . 0) ;; object-relative pixel
        (1 . 1))))))
  </code></pre>
  
  <p>And this actually can get me to the point where it displays menu, but when <code>slime-presentation-menu</code> calls any of the functions bound to menu items they somehow see that they weren't called with a "real" mouse event, throw and exit. :(</p>
  
  <p><strong>EDIT2</strong></p>
  
  <p>I actually think this is because of the <code>x-popup-menu</code>, which dispatches different events when you select a menu item with mouse or with keyboard... arrrrrgh.</p>