Keylogger in C# :: Hooking and unhooking keyboard hook
by Arxleol on Thursday 07.05.2009, under C#, tutorial, vista, xp
Now I take that you did in fact checked my introduction to this topic of keylogger. If you did then you may procede if you did not then I woudl suggest that you back there make some reading and understanding. Now I will discuss simple ways to connect to hook that is hooking and unhooking our keyboard hook.
So what’s this all about. I take that you have made aplication in C# already it should be windows form application preferablty since that way we will be on the same road during this learnign process.
If you have form you should place some button on the forum and double click it. This will open you function that will be called when your button is clicked. Now we need to add some chunk of code that will initiate and destroy hook when not needed.
First, of all to easy our procudere we will be using two buttons start and stop.
This is the code that start button should contain:
Hook.CreateHook(KeyReaderr); button2.Enabled = true; button1.Enabled = false;
You see we are calling function in the class hook created in the previous post. And as parameter we have to input name of method that will be used in the process of detecting pressed keys.
The last two lines of code are in fact just to disable and enable buttons so that when we have hook already initiated there may not be initiated another hook.
Hook.DestroyHook(); button2.Enabled = false; button1.Enabled = true;
Destroying hook is even easier now we just call method in Hook class, that will do job for us. And as said before now switch enabled buttons.
Now you should have working project that is form and two buttons that when pressed will hook and unhook us. However, before you procede you should have method for reading keys this will be discussed in the next post. But here is definition of that method:
public void KeyReaderr(IntPtr wParam, IntPtr lParam)
As you can notice it is delagating our keyhandler from the introduction.
Good luck ![]()
Monday 08.06.2009 on 20:10
This is good stuff, but what’s so bad about being a “script kiddie”? It saves a lot of time using tools that are already out there.
If I want to write a letter, do I first have to create a word processor program?
Cheers
Monday 08.06.2009 on 20:55
Well, this was more of school project and these tutorials are developed from there.
Also I think that comparing this with word processor doesn’t do justice.
And as we are obviously talking about hacking then one should always tend to at least understand principles behind tools used. Otherwise that person will not develop skills and potentials by using pre-made tools.
Another thing is that the same person will never be able to be on edge. As if there is automated tool but it exploits is also well known…
Friday 12.06.2009 on 23:19
Nice
When is the next tutorial?
Regards
Steve
Saturday 20.03.2010 on 04:55
i am regularly bumping around the online world the majority of the day which means that I tend to browse quite a bit, which unfortunately isnt usually a beneficial thing as almost all of the online resources I visit are made up of unnecessary garbage copied from similar web pages a trillion times, on the other hand I gotta say this page is indeed decent and also contains some original content, so cheers for removing the trends of basically replicating other peoples’ blogs, in case you ever want to play a couple of hands of myspace poker together let me know – you have my email