Hi, On 2/22/07, Tim Golden <[EMAIL PROTECTED]> wrote: > Kelie wrote: > > for every 0.1 second, check the active application or current > > application, or active window? (I don't know what is the correct > > term.) if it is AutoCAD (meaning user is using AutoCAD), turn on the > > CapsLock, if it is Microsoft Word (meaning user is using Word), turn > > off the CapsLock. > > Well your best bet is to look at WATSUP: > > http://www.tizmoi.net/watsup/intro.html > > or at pywinauto: > > http://sourceforge.net/projects/pywinauto >
I don't know about pywin, but some things to look at: GetForegroundWindow() will return the window that is currently active It might be easier to just ask what the class name of the parent of that window is, in that case you could just pass the HWND to GetClassName() AutoCAD has a specific class name (may depend on your AutoCAD version) - Afx:00400000:8:00010011:00000000:00010199 (this is the main windows - so you probably need to call GetParent()) - on the other hand you may only want to set caps lock when the command line window is enabled (class = Afx:00400000:8:00010013:00000000:00000000) so pseudo code would be something like # get active window hwnd = GetForegroundWindow() # get the class of this window classname = GetClassName(hwnd) # check if it is our class... if classname == "Afx:...." or GetClassName(GetParent(hwnd)) == "Afx:...": Set caps loc Or something like that - I have been using ctypes to do all that windows api stuff - so I am not sure if all the methods are wrapped by pywin32. > but I'm not convinced that what you're trying to do is > A Good Thing ;) > > > Oh, the reason I check the active application for every 0.1 second is > > I don't know how to do it otherway. Is there an event that > > corresponds to the active application/window change? > > It's a long while since I did lowish-level Windows stuff in earnest. > I suspect you'd have to install a system message hook and look for > WM_ACTIVATE messages or something similar. Perhaps someone more > knowledgeable here can chip in...? > PyHook might be an interesting thing to look at - it allows you to hook keyboard and mouse events at least. Mark (author of pywinauto) > TJG > _______________________________________________ > Python-win32 mailing list > Python-win32@python.org > http://mail.python.org/mailman/listinfo/python-win32 > _______________________________________________ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32