Processing All Keyboard Inputs (Hooks)
I'm making a program that records all the keyboard actions, and stores this information into a log file (Keylogger). I just can't seem to find a good way of doing t开发者_C百科his.
What I have so far: A LowLevelKeyboardProc, The Virtual Key Code + the Scan Code of the Key being pressed.
What I would like: Using these codes, I will process and write information about the keyboard action being done. For invisible keys I would like the format: "[SHIFT], [ENTER], [ESC], etc. And for visible keys I would simply like their Ascii value (both Upper Case, and Lower Case), including if they enter: !@#$%,etc..
I have a few ideas, but I don't know how I could capture everything. I have the information, I just don't know how to process it efficiently.
Refer to my post from here: Other Post
I've got example code for how to install a low-level keyboard hook and how to process the keystrokes.
Since you already have the hook working, all you need is a mapping from key codes to names for special keys. Just pre-populate an array of strings indexed by the key code:
const char *map[256];
map[VK_SHIFT] = "[SHIFT]";
map[VK_ENTER] = "[ENTER]";
...
Then in your hook function, check if the key is a printable character, if so, print it directly, otherwise lookup the name of the key and print that:
if (isprint(vkCode))
yourFile << char(vkCode);
else
yourFile << map[vkCode];
精彩评论