Capturing Windows click events with Python
I'm trying to capture left/right/double click events with Python on Windows. Can I do this with win32api?
For example, every time I click somewhere, I want it to print out the exact co开发者_高级运维ordinates of the place it was clicked and what type of click it was.
Someone want to point me in the right direction, please?
Maybe PyHook is what you are looking for
Try with this code:
#!/usr/bin/env python
# coordinates.py
import gtk
class Coordinates(gtk.Window):
def __init__(self):
gtk.Window.__init__(self)
self.connect("expose_event", self.expose)
self.connect("motion_notify_event", self.expose)
def expose(self, widget, event):
self.tooltips = gtk.Tooltips()
x ,y = self.get_pointer()
self.set_tooltip_text( str(x) + ',' + str(y))
return False
def main():
window = Coordinates()
window.connect("destroy", gtk.main_quit)
window.show_all()
gtk.main()
if __name__ == "__main__":
main()
You can add the appropriate signals for left/right/double click
gtk.window
Events
source
精彩评论