locked
Properly record keyboard input to a string? RRS feed

  • Question

  • Properly record synthesized keyboard input to a string?
    I'm trying to record user keyboard input to a case-sensitive string.

    Currently, it looks something like this for each character input...

    char KeysInput[256]={};
    ...
    LRESULT CALLBACK KeyboardHook(int nCode,WPARAM wParam,LPARAM lParam)
    ...
    *(KeysInput+strlen(KeysInput))=(char)wParam;
    *(KeysInput+strlen(KeysInput))='\0';

    The recorded characters are all uppercase. I can tell if the character is shifted or not, but how do you record that information to a character string?

    The hook is receiving input from SendInput(), if it matters. I guess it would be the same if a user were pressing keys. I have looked all over but haven't recognized a solution.

    Thanks.
    Monday, March 3, 2014 10:58 PM

Answers

  • You are probably looking for ToAscii, MapVirtualKey (to obtain the scan code that ToAscii needs) and GetKeyboardState (to obtain current keyboard state that ToAscii needs).

    It might be easier to hook WM_CHAR messages via WH_GETMESSAGE hook, rather than raw keystrokes via WH_KEYBOARD hook.


    Igor Tandetnik

    • Marked as answer by Badzilla Tuesday, March 4, 2014 3:02 AM
    Tuesday, March 4, 2014 1:06 AM