-5

I got a task to create a simple keyLogger using c++,
but it seems like some of the keys are missing..

It can detect the keys such as "." under my NumLock key, but it can't detect the keys next to the letters on my keyboard such as: "[", "]", "/", "." and all of those.

I have tried to make this simple function for testing, still cant detect it:
(i cant detect the "46" ASCII dec number)

void test() {

    char key;

    while (true) {

        Sleep(10);
        for (key = 0; key <= 222; key++) {

            if (GetAsyncKeyState(key) == -32767 || GetAsyncKeyState(key) == 1) {

                cout << key+0;
            }
        }
    }

    cout << "\n\n\n";
    system("PAUSE");
}

Thank You !

xsss
  • 81
  • 1
  • 2
  • 9
  • you have to take the key modifiers into account (alt, shift)... – Jean-François Fabre Oct 22 '16 at 13:05
  • 6
    You have implemented a keylogger (to monitor keyboard keys), but are asking for **characters** instead. You need to fix your mental model before moving forward. Also, don't be afraid to read the [documentation](https://msdn.microsoft.com/en-us/library/windows/desktop/ms646293.aspx). Both of your expressions in the `if` statement are wrong. – IInspectable Oct 22 '16 at 13:13

1 Answers1

-1

I think that the issue is with cout << key + 0; numbers can be added to 0 but symbols cant be.

  • `key` stores a numerical value. The expression `key+0` propagates the type to `int`, so that its numerical value is displayed instead of the character. – IInspectable Oct 23 '16 at 09:50