I recently learning to use PyGObject. I can listening a "motion-notify-event" to get mouse move events with a Gtk.Widget. However, it can't work fine outside the window, I need the mouse event outside the window,.Maybe I should ask how a root window listening motion-notify-event. I think a timeout function could do it, but not the best approach should be. how should I do?
How can I get a global mouse event in GTK?
I don't really know about doing that with GTK but you can easily do this with other methods.
1)You can create a thread inside of your python program that records for the mouse position. 2)You can get (with gtk) your window position and size.
So you have everything you need to know.. under linux there are some programs that will allow you to capture the mouse position etc..
this command cnee --record --mouse | awk '/7,4,0,0,1/ { system("xdotool getmouselocation") }'
will print your mouse position every time that you click. (you must install cnee and xdotool)
You can for example, write that output to a file and reed the last line of the file.. or If you don't want to pass trough a file, you can directly execute the command in python and retrieve its output like this:
(python 2.7)
>>> import os
>>> from subprocess import Popen
>>> mouse=os.popen("xdotool getmouselocation")
>>> mouse=str(mouse.read())
>>> print mouse
x:838 y:439 screen:0
then you play a little bit with the string and you will get x, y, and the screen.
With 1) and 2) you can know if the mouse is inside the window or outside.