Created
January 14, 2026 13:41
-
-
Save codebymikey/1b658d7778d5fe597c849e211a830b94 to your computer and use it in GitHub Desktop.
Windows mouse focus debugger. Sourced from https://web.archive.org/web/20250119002413/https://www.happydroid.com/focus (https://drive.google.com/file/d/1ec2a0qJy7JhPtcp_YAYEpgTTLK_dWy-L/view?pli=1)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // Licence: public domain - unrestricted usage | |
| // | |
| #include <iostream> | |
| #include <windows.h> | |
| #include <psapi.h> | |
| #include <fcntl.h> | |
| #include <io.h> | |
| int main() | |
| { | |
| WCHAR program[MAX_PATH]; | |
| DWORD activeProcId = 0; | |
| DWORD lastActiveProcId = 0; | |
| _setmode(_fileno(stdout), _O_U16TEXT); | |
| while (true) { | |
| Sleep(100); | |
| activeProcId = 0; | |
| HWND hWnd = GetForegroundWindow(); | |
| if (hWnd != NULL) { | |
| GetWindowThreadProcessId(hWnd, &activeProcId); | |
| if (activeProcId == 0) { | |
| wprintf(L"GetWindowThreadProcessId had error %u\n", GetLastError()); | |
| continue; | |
| } | |
| HANDLE hProc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, activeProcId); | |
| if (hProc == NULL) { | |
| wprintf(L"OpenProcess had error %u\n", GetLastError()); | |
| continue; | |
| } | |
| DWORD rc = GetModuleFileNameExW((HMODULE)hProc, NULL, program, MAX_PATH); | |
| if (rc == 0) { | |
| wprintf(L"GetModuleFileNameExW had error %u\n", GetLastError()); | |
| CloseHandle(hProc); | |
| continue; | |
| } | |
| CloseHandle(hProc); | |
| } | |
| if (activeProcId != lastActiveProcId) { | |
| WCHAR date[256]; | |
| time_t now = time(0); | |
| struct tm t; | |
| localtime_s(&t, &now); | |
| wcsftime(date, sizeof(date)/sizeof(WCHAR), L"%a %d %B %T", &t); | |
| if (activeProcId == 0) | |
| wprintf(L"No foreground application | %s\n", date); | |
| else | |
| wprintf(L"%u:%s | %s\n", activeProcId, program, date); | |
| lastActiveProcId = activeProcId; | |
| } | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Better off using https://github.com/JocysCom/FocusLogger instead