Categories > Coding > C++ >
Systemwide key press hook in C++
Posted
I made this quite a while ago, probably around the beginning of my C++ journey and while looking at my github repositories I found it and thought I should post it here as it's actually quite a cool beginner thing to make.
It creates a system-wide key press hook and outputs the key that was pressed along with its ASCII code ( in base 10 and 16 ).
I rewrote it and cleaned it up a bit since I made it a while ago and my code wasn't as clean.
github repository: https://github.com/expressiongz/kb-hook/blob/main/main.cpp
https://media.discordapp.net/attachments/901227777741692968/1006016162909388951/unknown.png
#include <iostream>
#include <Windows.h>
HHOOK hook = nullptr;
long __stdcall kb_hook( const std::int32_t n_code, const std::uint32_t kb_message, const long llhookstruct )
{
const auto p_kbd_hook_struct = reinterpret_cast< KBDLLHOOKSTRUCT* >( llhookstruct );
if ( n_code == HC_ACTION && kb_message == WM_KEYDOWN )
std::printf( "Hooked Key Down: %c | %u | %x\n", p_kbd_hook_struct->vkCode, p_kbd_hook_struct->vkCode, p_kbd_hook_struct->vkCode );
return CallNextHookEx(hook, n_code, kb_message, llhookstruct);
}
int main( )
{
hook = SetWindowsHookExA( WH_KEYBOARD_LL, kb_hook, 0, 0 );
MSG msg{ nullptr, 0, 0, 0, 0, { 0, 0 } };
while ( !GetMessageA( &msg, 0, 0, 0 ) ) {
TranslateMessage( &msg );
DispatchMessageA( &msg );
}
UnhookWindowsHookEx( hook );
return 0;
}
feel free to ask any questions
https://media.discordapp.net/attachments/1044764388546068510/1051935933836050482/Signature_4.png
Replied
Vouch
Now i can make my own trojan hehe
Cancel
Post
Random quote here...
Replied
so basically a c++ keylogger?
Cancel
Post
Mail me at sirweebdev@protonmail.com if you have any questions or you want to say anything to me, I'll reply (maybe).
Replied
sick release!
Cancel
Post
10 years ago
Users viewing this thread:
( Members: 0, Guests: 1, Total: 1 )
Cancel
Post