-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.cpp
47 lines (40 loc) · 1.08 KB
/
Main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <string>
#include <Windows.h>
#include <tchar.h>
#include <psapi.h>
// Possibly find out what we can do to programatically decide if the current handle is a UAC prompt
bool IsCurrentWindowBlank(HWND handle) {
int bufsize = GetWindowTextLength(handle) + 1;
LPWSTR title = new WCHAR[bufsize];
GetWindowText(handle, title, bufsize);
DWORD pid = 0;
GetWindowThreadProcessId(handle, &pid);
if ((lstrlenW(title) == 0) && (pid == 0)) {
return true;
}
return false;
}
int main() {
DWORD pid = 0;
DWORD old_pid = 0;
while (1) {
HWND handle = GetForegroundWindow();
GetWindowThreadProcessId(handle, &pid);
// confirm that this is a new window
if (pid != old_pid) {
if (IsCurrentWindowBlank(handle)) {
std::wcout << handle << std::endl;
// current window is blank, let's try to enter our keys
Sleep(1000);
SendMessage(handle, WM_KEYDOWN, (WPARAM)VK_LEFT, 1);
SendMessage(handle, WM_KEYUP, 0, 0);
}
}
Sleep(100);
old_pid = pid;
// pid needs to be reset to zero in case the pointer returns unused
pid = 0;
}
return 0;
}