Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How a key logger works. What is the logic behind this.
Can any body tell me logic of key logger?
Posted

Why?

OK, this is what it is: http://en.wikipedia.org/wiki/Key_logger[^].

You probably mean software key logger. According to Microsoft, it impossible to create with C#. It needs a Windows Hook to be registered. See http://msdn.microsoft.com/en-us/library/ms632589%28v=vs.85%29.aspx[^]. The problem is registration and using of a system-global hook. It must be implemented in an unmanaged DLL which you can use to communicate with your .NET software.

See also:
http://msdn.microsoft.com/en-us/library/ms644959(v=vs.85).aspx[^],
http://msdn.microsoft.com/en-us/library/ms644960(v=vs.85).aspx[^],
http://msdn.microsoft.com/en-us/library/ff468841(v=vs.85).aspx[^].

See the following CodeProject articles helping to implement Global System Hook in C# with the help of C++ unmanaged DLL:
Using Window Messages to Implement Global System Hooks in C#[^],
Global System Hooks in .NET[^],
Processing Global Mouse and Keyboard Hooks in C#[^].

—SA
 
Share this answer
 
v2
Comments
Abhinav S 21-Jul-11 4:46am    
My 5. Lot of details. But I hope the OP does not misuse this information.
Sergey Alexandrovich Kryukov 21-Jul-11 10:26am    
Yes, that a concern. Hope not.
Thank you, Abhinav.
--SA
The logic is simple enoough. Every key typed on the keyboard is captured by a program.
This can be achieved using a keyboard hook.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 21-Jul-11 2:08am    
And how would you do it in C#? P/Invoke of SetWindowsHookEx? According to Microsoft, it won't work if the global system hook is needed -- unfortunately; and it is needed for a key logger.
Please see my solution.
--SA
Abhinav S 21-Jul-11 4:45am    
I left it for the OP as an exercise to find out.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900