I am making hooks and catching keyboard virtual key codes, according to MSDN, these are the key codes that exist.
Every key code works fine as i will give an example down below of my code.
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
HHOOK altKey;
KBDLLHOOKSTRUCT kbdHK;
MSG message;
LRESULT CALLBACK kbdProc(int nCode, WPARAM wPar, LPARAM lPar);
int main(int argc, char *argv[]) {
altKey = SetWindowsHookEx(WH_KEYBOARD_LL, kbdProc, NULL, 0);
while(GetMessage(&message, NULL, 0, 0) > 0){
TranslateMessage(&message);
DispatchMessage(&message);
}
return 0;
}
LRESULT CALLBACK kbdProc(int nCode, WPARAM wPar, LPARAM lPar){
if(nCode >= 0){
if(wPar == 256){
kbdHK = *(KBDLLHOOKSTRUCT *)lPar;
if(kbdHK.vkCode == 0x20){
printf("spacebar pressed!!\n");
}
}
}
return CallNextHookEx(NULL, nCode, wPar, lPar);
}
But when I replace the virtual key code with 0x12 which is ALT KEY according to MSDN, I can't get a result back. What could be the problem?
Edit:
When I use this line of code, I can get the scanCode for every key but not for alt key again which is interesting.
printf("%d", kbd.scanCode);