Re: How to get mouse position continuously without events

Peter Groves <[email protected]>
Newsgroups gmane.comp.lang.ocaml.lib.gtk
Message-ID <[email protected]>
The Widget class has a method called "pointer" that gives the location
of the mouse pointer. Here is the doc from the gtk core library:

http://library.gnome.org/devel/gtk/2.14/GtkWidget.html#gtk-widget-get-pointer

I have not tried to use it using lablgtk, however, so I can't tell you
much about how to use it.

-Peter

On Fri, 7 Nov 2008 11:56:34 -0600
"Angela Zhu" <[email protected]> wrote:

> Hi,
> I am writing a simulation program, where basically, the program has a
> number of
> time steps. At each time step, it tries to get the current position of
> mouse,
> do some computation, and update a gui with the result computed.
> 
> What I need is a function that can get the current position of mouse
> without any
> events. I know, for example, the following code will work.
> But is there a way to avoid events, but just get the mouse position?
> 
> Thanks a lot in advance!
> 
> 
> method handle_event = function
> 
>     | info (* : GdkEvent.Motion.t *) ->
> 
>     let new_x = (GdkEvent.Motion.x info) -. 350.
> 
>         and new_y = (GdkEvent.Motion.y info) -. 350.
> 
> in
> 
>   print_string "\nfollow mouse\n"; flush stdout;
> 
>   inputs.(0)#move_to new_x new_y;
> 
>   false
> 
>     | _ ->  false
> 
> 
>       ignore (canvas#event#connect#motion_notify
> 
> ~callback:(self#handle_event));
> 
> 
> 
> -- 
> Regards,
> Angela Zhu
> ------------------------------------------
> Dept. of CS, Rice University
> http://www.cs.rice.edu/~yz2/
> ------------------------------------------
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.