Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

with python, I want to get a window title,a stock software window.

the window's title will change when I browse another stock ,now I want to scan it every 100ms and return the new title,but the front text in the window title is the same text.

I can print the title in cmd,but I don't know how to scan it every 100ms and return

I use this code:

from win32gui import *
import re
titles = set() 
titlekey = ''
def foo(hwnd,nouse):
    if IsWindow(hwnd) and IsWindowEnabled(hwnd) and IsWindowVisible(hwnd):
        titles.add(GetWindowText(hwnd))
EnumWindows(foo, 0) 
lt = [t for t in titles if t] 
lt.sort() 
for t in lt:
    if re.match(titlekey,t):
        print t

How to scan every 100ms and return the new title when it change?

Where you have code, indent it to format as code, don't put it in a blockquote. Edited for you. – Gareth Latty Apr 18, 2012 at 11:07
import win32gui
tempWindowName=win32gui.GetWindowText (win32gui.GetForegroundWindow())
import time
while True:
    if (tempWindowName==win32gui.GetWindowText (win32gui.GetForegroundWindow()))
        tempWindowName=win32gui.GetWindowText (win32gui.GetForegroundWindow())
        #do what you want
    time.sleep(0.1)
                em.....I think my idea maybe wrong.I want get the title when it change,return the new title,and use some text in the title to Query data in sqlite,now I think scan it every 100ms maybe can't work.so......I have no idea.....
– sword
                Apr 18, 2012 at 12:29
                sure,your answer resover my question。but may be my idea is wrong。my program need to get the active window's title or it's parent window's title,and return new title when the title change,if no change then do nothing,how sould I do?use hook?
– sword
                Apr 19, 2012 at 11:39
                1. edit your question to ask what you want to ask. 2. except the answer. 3. if you need more assistance, ask a new question.
– user850498
                Apr 19, 2012 at 15:46
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.