LeetCodes
LeetCodes

Reputation: 33

Get window title on new window

I'm writing a keylogger type application, and I have pretty much everything done, my problem is getting the window title, I don't want to write the window title every time they press a key, I can get the window title, like I know how to, but how would I only write it to the log when its a new window?

Upvotes: 1

Views: 574

Answers (3)

JosephH
JosephH

Reputation: 8815

Anytime a keypress is detected, call GetForegroundWindow to get the handle to the currently focused window. Store this value as a variable in your program and when it changes, call GetWindowText to get the title of the window and log this title.

Upvotes: 0

icktoofay
icktoofay

Reputation: 129011

Store the previous window title and if the current window title is different than the previous window title, print the new window title and set the previous window title to the current window title.

This fails if there's multiple windows with the same name, but it may work for your needs.

Upvotes: 0

septical
septical

Reputation: 440

You could maintain an internal list of all windows (with window handles as identifiers to keep memory usage low), and when a new one appears, then you can extract it.

The Win32 API (which I assume you're using) has the function:

EnumChildWindows

which can be used for this task. Call

GetDesktopWindow

to supply as the input window handle, and you'll get every window created under this desktop session.

I'm not sure if this would still work via RDP (and Windows Vista+ have the secure desktop as well as the normal clients), but it depends how vital this functionality is for you.

Upvotes: 1

Related Questions