JDelonge
JDelonge

Reputation: 315

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 coordinates of the place it was clicked and what type of click it was.

Someone want to point me in the right direction, please?

Upvotes: 4

Views: 2665

Answers (2)

AurumAustralis
AurumAustralis

Reputation: 369

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

Upvotes: 1

joaquin
joaquin

Reputation: 85603

Maybe PyHook is what you are looking for

Upvotes: 4

Related Questions