Skip to content
MPGHThe Dark Arts
/
RegisterLog in
Forum
Community
What's NewLatest posts across the boardTrendingHottest threads right nowSubscribedThreads you follow
Discussion
GeneralIntroductionsEntertainmentDebate FortFlaming & Rage
Board
News & AnnouncementsMPGH TimesSuggestions & HelpGiveaways
More Sections
Art & Graphic DesignProgrammingHackingCryptocurrency
Hacks & Cheats
Games
ValorantCS2 / CS:GOCall of Duty / WarzoneFortniteApex LegendsEscape From Tarkov
+14 moreLeague of LegendsGTA VMinecraftRustROTMGBattlefieldTroveBattleOnCombat ArmsCrossFireBlackshotRuneScapeDayZDead by Daylight
Resources
Game Hacking TutorialsReverse EngineeringGeneral Game HackingAnti-CheatConsole Game Hacking
Tools
Game Hacking ToolsTrainers & CheatsHack/Release NewsNew
Submit a release →Share your cheat, tool, or config with the community.
AINEW
AI Tools
General & DiscussionPrompt EngineeringLLM JailbreaksHotAI Agents & AutomationLocal / Open Models
AI × Gaming
AI Aimbots & VisionML Anti-CheatGame Bots & Automation
Create
AI Coding / Vibe CodingAI Art & MediaAI Voice & TTS
The AI frontier →Where game hacking meets modern machine learning. Jump in.
Marketplace
Buy & Sell
SellingBuyingTradingUser Services
Trust & Safety
Middleman LoungeMarketplace TalkVouch Copy Profiles
Money
Cryptocurrency TalkCurrency ExchangeWork & Job Offers
Start selling →List accounts, services, and goods. Use the middleman to trade safe.
MPGH The Dark Arts

A community for offensive security research, reverse engineering, and AI.

Community

ForumMarketplaceSearch

Account

RegisterLog in

Legal

Privacy PolicyForum RulesHelp & FAQ
© 2026 MPGH · All rights reserved.Built by the community, for the community. For educational purposes onlyContent is shared for security research and education — we don't condone illegal use. You're responsible for complying with applicable laws. Use at your own risk.
Home › Forum › Programming › C++/C Programming › Global Hook to detect keypresses?

Global Hook to detect keypresses?

Posts 1–15 of 15 · Page 1 of 1
That0n3Guy
That0n3Guy
Global Hook to detect keypresses?
Is a global hook the only way to detect key presses outside the main program window?

From what I read, a global hook must be contained inside a DLL which won't work for my current scenario.
#1 · 16y ago
B1ackAnge1
B1ackAnge1
It doesn't need to be in a dll.. i Have an exe in assembly that hooks the keyboard.

Just pass the current Module Handle of your exe & the function pointer to your hook proc to SetWindowsHookEx (otherwise you may throw an error if that's NULL and the ThreadID is 0 as well)
#2 · edited 16y ago · 16y ago
ZE
zeco
Quote Originally Posted by B1ackAnge1 View Post
It doesn't need to be in a dll.. i Have an exe in assembly that hooks the keyboard.

Just pass the current Module Handle of your exe & the function pointer to your hook proc to SetWindowsHookEx (otherwise you may throw an error if that's NULL and the ThreadID is 0 as well)
No would be a good time to respond with a black angel-ish description on exactly what a hook is, how it can be used, how one is created (vaguely), and any other background info. I love your explanations =D. They always make things click.
#3 · 16y ago
B1ackAnge1
B1ackAnge1
Lol well in a nutshell, a hook is a way for a function you write to 'intercept' a windows message/event that happens and process it before it gets to the window it's trying to get to. This way your hook callback function, which gets called by windows, can then process the command and do something with it, and in some cases even prevent the original target window from receiving it, or change the message before it reaches the target window.

For instance a Keypress normally works like this:

User presses Key-->OS Reacts--->Sends KeyPress Event-->Active Window-->Application processes keypress and does what it needs to.

If you 'register' a hook (by calling setwindowshookex) which basically tells windows "hey when this or that happens, call my function first", you get something like this:

User does KeyPress->OS-->Sends KeyPress Event--->HOOK CALLBACK gets called->You do whatever you want with it, for instance save to a file-->Message continues on to Active Window as if nothing happened etc.

That's the basics of a keylogger right there

Same thing with D3D hacks etc. they intercept the drawing events and change a few things around to give the user an advantage
#4 · 16y ago
ZE
zeco
Hey that makes beautiful sense! Now here is for something that i was actually confused about and not just ignorant =). Callbacks. I can't seem to find ANY explanations for/about them.

Hmm i'm gonna offer my guess as to what they are. Are they functions that you can set up so that when something happens, the callback function gets called, sort of like an event (don't remember which language this term is from)? I'm probably wrong though. =)
#5 · 16y ago
TE
teat
Can you explain what your problem is with GetAsyncKeyState? I don't see why you would want to get more complicated in regards to that.
#6 · 16y ago
B1ackAnge1
B1ackAnge1
Quote Originally Posted by zeco View Post
Hey that makes beautiful sense! Now here is for something that i was actually confused about and not just ignorant =). Callbacks. I can't seem to find ANY explanations for/about them.

Hmm i'm gonna offer my guess as to what they are. Are they functions that you can set up so that when something happens, the callback function gets called, sort of like an event (don't remember which language this term is from)? I'm probably wrong though. =)
That's basically it
#7 · 16y ago
That0n3Guy
That0n3Guy
Quote Originally Posted by teat View Post
Can you explain what your problem is with GetAsyncKeyState? I don't see why you would want to get more complicated in regards to that.
GetAsyncKeyState ONLY affects that window. I'm making something where you can press the key anywhere you want and make a function happen, meaning GetAsyncKeyState wouldn't work.
#8 · edited 16y ago · 16y ago
Hell_Demon
Hell_Demon
GetAsyncKeystate works fine outside the window o__O
#9 · 16y ago
TE
teat
Yes it does, and on the contrary I would be looking for something that would affect ONLY the window. Don't know why you are looking for something to affect all windows.
#10 · 16y ago
B1ackAnge1
B1ackAnge1
only 'bad' thing about getasynckeystate is that if another app calls it before your app you won't see it.
#11 · 16y ago
That0n3Guy
That0n3Guy
Ehh, I'm still having a ton of trouble using hooks.
#12 · 16y ago
B1ackAnge1
B1ackAnge1
What part are you sitll having issues with?
#13 · 16y ago
That0n3Guy
That0n3Guy
Quote Originally Posted by B1ackAnge1 View Post
What part are you sitll having issues with?
I can't figure out how to parse the keys the hook returns.
#14 · 16y ago
B1ackAnge1
B1ackAnge1
Depending on whether or not you're using WH_KEYBOARD or WH_KEYBOARD_LL it's different.

if you using WH_KEYBOARD then the wparam in your callback will hold the virtual keycode whicih you can then compare to what you're looking for

If you're using WH_KEYBOARD_LL then lparam will hold a KBDLLHOOKSTRUCT in which has a vkcode member you can check against

I can probably write you up a working sample if need be?
#15 · 16y ago
Posts 1–15 of 15 · Page 1 of 1

Post a Reply

Similar Threads

  • DirectX Global HookBy torrentsoo in Hack Requests
    0Last post 15y ago
  • Hook DetectedBy .::SCHiM::. in Combat Arms Coding Help & Discussion
    47Last post 15y ago
  • Detected Hook???By Skaterforeva1 in Combat Arms Coding Help & Discussion
    5Last post 15y ago
  • MPGH Public Hook 10/10/09 (DETECTED)By Z0d14k in WarRock - International Hacks
    132Last post 16y ago
  • AUTOMATON HAD BE DETECTEDBy shinygold in Mission Against Terror Discussions
    3Last post 15y ago

Tags for this Thread

#detect#global#hook#keypresses