|
-
Jan 14th, 2007, 06:37 PM
#1
Thread Starter
Hyperactive Member
[2.0] Detecting when a key is pressed even if the application is not in focus
Hi. I'm trying to create a sort of keylogger application that records everything the user types on a computer.
Now I have to add this feature onto a watchdog application that I developed as a window application hidden showing a notify icon.
Now what i'm trying to do is when a key is pressed, add that key to a file that the watchdog will write to. I could do all of that but there is one thing missing.
I could add a Key event handler so when a key is pressed, something is done e.g.:
Code:
private void AddEvent(Control control)
{
control.KeyDown += new KeyEventHandler(control_KeyDown);
foreach (Control co in control.Controls)
{
AddEvent(co);
}
}
...
private void control_KeyDown(object sender, KeyEventArgs e)
{
// User presses A, Key numeration code is 65.
if (e.KeyValue == 65)
{
MessageBox.Show("A");
}
}
This works fine, but since the watchdog is an application, this handler only kicks in when the application is on focus. The way it has to work is in the background even if the application is not in focus.
Does anyone know how to do this?
Jennifer
-
Jan 14th, 2007, 07:16 PM
#2
Re: [2.0] Detecting when a key is pressed even if the application is not in focus
You need to set a keyboard hook using the Windows API so that your app receives a message each time a key is pressed.
http://search.microsoft.com/results....=keyboard+hook
http://search.microsoft.com/results....-AU&FORM=QBME1
Following the first link on that second page led me to this also:
http://forums.microsoft.com/MSDN/Sho...14651&SiteID=1
-
Jan 14th, 2007, 11:57 PM
#3
Frenzied Member
Re: [2.0] Detecting when a key is pressed even if the application is not in focus
heh wow john i can't believe u replied to this post
-
Jan 15th, 2007, 12:05 AM
#4
Re: [2.0] Detecting when a key is pressed even if the application is not in focus
 Originally Posted by Fromethius
heh wow john i can't believe u replied to this post
It's not against the rules to assist if it's for a legit purpose and I think Jen is trustworthy.
-
Jan 15th, 2007, 12:20 AM
#5
Re: [2.0] Detecting when a key is pressed even if the application is not in focus
Indeed. If a newcomer or someone with a dodgy reputation (like you Fromethius ) then I would have at least asked for an indication of a legit purpose. I guess you can never know for sure but if someone says that their app is going to sit in the system tray then they're unlikely to be a black hat.
-
Jan 15th, 2007, 10:13 AM
#6
Frenzied Member
Re: [2.0] Detecting when a key is pressed even if the application is not in focus
heh yea I don't mind though. I'm only 13. I just come here, screw around, help people out. Besides, I already know how :P
-
Jan 16th, 2007, 06:09 PM
#7
Thread Starter
Hyperactive Member
Re: [2.0] Detecting when a key is pressed even if the application is not in focus
Thank you jmcilhinney. I got it out and its working fine.
Hi Penegate!!!! Happy new year, I hope 2007 brings a lot to all of you..... ESPECIALLY MEEEE!!!!!
Jennifer
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|