I just need some code that will return a string of the name of the current activated window title/name.

I've spent almost hours looking for a simple example though...

================================================================

I've seen other people say to hook windows messages and listen for wm_activate, and others...

I already have when to check, I just need something like...

print window.name.current
>> Get Current Active Window Title/Name - Python - Mozilla Firefox

Recommended Answers

All 4 Replies

Windows calls this the "Foreground Window". It might not be the one your program is running. HWND GetForegroundWindow(VOID); Once you have the HWND you can call GetWindowText(hWnd,outbuf,outlen) to get the title bar contents.

I assume pywin32 supports these calls, but haven't looked them up.

commented: good point +8

It doesn't support those, I was looking for a module, or another method to do that.

Very easy, using pywin32.

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

Thanks a lot, I was looking for an easy answer like this!!!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.