0

Sorry for making a so basic question, but I'm new to Python.

Suppose I want some code to run when the cursor is in X position. Or when the active window is Y.

w = win32gui
text = w.GetWindowText(w.GetForegroundWindow())

So if I want something to happen when the text is 'Documents' I'd do this with while & time.sleep loops but that doesn't seem so elegant.

I mean, what is the point of this if I decided I'd like this script to run in the background for the rest of my life? I know it wouldn't interfere with any other process, but if it was the case of a bit more complex tracking?

Isn't it possible just to make something happen when a variable turns X?

Sotiris Kiritsis
  • 3,178
  • 3
  • 23
  • 31

1 Answers1

0

After some research and @warmoverflow suggestion, for now I'll be using zope.event + pythoncom.PumpMessages().

This way it is possible to keep it short and simple. I guess it will run fast and stealthy with most key, mouse and windows title events.