-7

I am writing a keylogger for windows. I am planning to get the pressed key with GetAsyncKeyState(KEY) and a hidden console. After a key press has been identified I will get the current focused windows with GetForegroundWindow and indentify which program was on top when the key was pressed. I also want to be able to Differentiate between key presses for passwords and other kind of inputs. Is there a way to do it? How?

I am not writing a malicious software. This is for an assignment in Advanced Programming course.

drescherjm
  • 10,365
  • 5
  • 44
  • 64
Amir Qasemi
  • 70
  • 2
  • 10

1 Answers1

0

If the foreground app is using standard Win32 UI controls, then try this:

  • use GetForegroundWindow() to get the HWND of the foreground window.
  • then use GetWindowThreadProcessId() and GetGUIThreadInfo() to get the foreground window's currently focused child control.
  • then use GetClassName() to check if it is a standard EDIT control (this check might fail in some UI frameworks! You might have to use the UI Automation API to detect the control type)
  • then use GetWindowLong/Ptr() to check if it has the ES_PASSWORD style applied.

However, if the foreground app is not using standard Win32 UI controls, and/or is custom-drawing them, or the like, then all bets are off.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770