Keyboard hook in C++
Apparently this is too hard for a lot of people to figure out so here's a little something to get them on their way...
Figured i'd show what's in STDAFX.H since people will freak out when their copy/paste job doesn't compile...
Oh and look.. not in a DLL
How's this not easy? XD
If you guys want though I can comment the code some more..
Code:
// Keyhook.cpp : Defines the entry point for the console application.
// by B1ackAnge1
// Alt-F12 Exits app
// All you leechers have to do is parse the vkCode ;)
#include "stdafx.h"
using namespace std;
HHOOK hHook;
LRESULT CALLBACK KeyboardProc(int nCode,WPARAM wParam, LPARAM lParam)
{
if(wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN)
{
PKBDLLHOOKSTRUCT pKey = (PKBDLLHOOKSTRUCT)lParam;
//Now just check pKey->vkCode etc for whatever you want
//for instance, a basic printout of the value and a check for pgup
cout << pKey->vkCode << " ";
if(pKey->vkCode == VK_PRIOR)
cout << endl << "Page Up!" << endl;
}
CallNextHookEx(hHook,nCode,wParam,lParam);
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
RegisterHotKey(NULL,0xB1AC7B1A,MOD_ALT,VK_F12);
HMODULE hInstance = GetModuleHandle(NULL);
hHook = SetWindowsHookEx(WH_KEYBOARD_LL,KeyboardProc,hInstance,NULL);
MSG msg;
GetMessage(&msg,NULL,NULL,NULL);
UnhookWindowsHookEx(hHook);
return 0;
}
Code:
#pragma once #include "targetver.h" #include <stdio.h> #include <tchar.h> #include <windows.h> #include <iostream>
How's this not easy? XD
If you guys want though I can comment the code some more..

(unlike a million other things haha)