Lisp HUG Maillist Archive

mouse or pane position

Hi,

I have a feeling that this is an FAQ (or that I've asked it before
myself, at least :-)), but anyway:

Is there a way, preferably portable, to get the _screen_ position
of the mouse or (even better) a pinboard object? I need this as
input to :best-x/:best-y when creating an interface (I want a small
window I create to pop up at (or nearby) a given pane or the mouse).
-- 
  (espen)


Re: mouse or pane position

Unable to parse email body. Email id is 1870

Re: mouse or pane position

Espen Vestre wrote:

> Is there a way, preferably portable, to get the _screen_ position
> of the mouse

On Windows, you can get the screen coordinates of the mouse with the
function GetCursorPos. I have a FLI-interface to this function lying
around somewhere. If you're interested in this, let me know and I'll
dig it up for you.

 --
Arthur Lemmens


Re: mouse or pane position

Arthur Lemmens <alemmens@xs4all.nl> writes:

> On Windows, you can get the screen coordinates of the mouse with the
> function GetCursorPos. I have a FLI-interface to this function lying
> around somewhere. If you're interested in this, let me know and I'll
> dig it up for you.

Thanks a lot, but I think I'll rather come up with a portable solution
myself (it's not very important for me to get the _exact_ position, and
I can approximate a lot from the interface-geometry and the position
within the interface).
-- 
  (espen)


Re: mouse or pane position

On Feb 10, 2004, at 4:05 PM, Espen Vestre wrote:
>
> Is there a way, preferably portable, to get the _screen_ position
> of the mouse or (even better) a pinboard object?

Espen,

I've been able to get the screen mouse coordinates on OS X using FLI 
calls to the Carbon GetGlobalMouse function.  I assume something 
similar could be done in Windows with the Win32 library (?). I don't 
know if there's a better/more portable way to do this.

Here's the code for OS X:

(fli:define-c-struct (point (:foreign-name "Point"))
   (y :short)
   (x :short))

(fli:define-c-typedef (point (:foreign-name "Point"))
   (:struct point))

(fli:define-foreign-function (getglobalmouse "GetGlobalMouse" :source)
     ((p (:pointer point)))
   :result-type :void
   :language :c)

(defun get-global-mouse-position ()
   (fli:with-dynamic-foreign-objects ()
     (let ((point (fli:allocate-foreign-object :type 'point)))
      (getglobalmouse point)
      (list (fli:foreign-slot-value point 'x) (fli:foreign-slot-value 
point 'y)))))

Regards,

Chris Sims

Cognitive Science Department
Rensselaer Polytechnic Institute


Updated at: 2020-12-10 08:57 UTC