Getting all the pressed keys everywhere
So is there possible to intersect all keys pressed everywhere, where everywhere is at any applicatio开发者_StackOverflow社区n? More or so like a keylogger. I was wondering if that is possible in C++ or C#.
Regards
What you're looking for is a Keyboard Hook. This is possible using some P/Invoke. See sample here:
http://www.codeproject.com/KB/cs/CSLLKeyboardHook.aspx
If you want to use winapi thaen function you are looking for is SetWindowsHookEx
with flag WH_KEYBOARD. If you want to get really all kes you might use low-lewel flag instead WH_KEYBOARD_LL
, but this will not translate keystrokes, so it's more difficult to work with.
I never used this flag, but i know that some flags need registered hook function to be in separate module (eg. dll) as they will be loaded and executed executed in context of application that actually recieves keyboard input. If it is so you must also think of a mechanism of returning colected data back to your application, cause global variables will not work.
精彩评论