// JP opened flex table

Click to See Complete Forum and Search --> : SetWindowsHookEx->Modding keyboard input


Quell
February 18th, 2007, 12:55 PM
Hey.

if (nCode == HC_ACTION)
{
KBDLLHOOKSTRUCT* kbh=(KBDLLHOOKSTRUCT*)lParam;
switch(kbh->vkCode)
{
case 0x41:
{
INPUT bKey;
bKey.type=INPUT_KEYBOARD;
KEYBDINPUT kbinp;
kbinp.dwExtraInfo=0;
kbinp.dwFlags=0;
kbinp.time=0;
kbinp.wScan=0;
kbinp.wVk=0x42;
bKey.ki=kbinp;
SendInput(1,&bKey,sizeof(INPUT));
return 0;
}
};
}
return CallNextHookEx(NULL, nCode, wParam, lParam);

Now the Hook proc gets called alrite and all, however i want to modify the input once it was hooked.
The above code definetly does not work, so i was wondering how can i modify the input that i hook? basically what happens if i press 'a' is i get 'bab' as output.
Thx

Calculator
February 18th, 2007, 01:57 PM
Basically, that is an initial keydown notification, and you send a b, and then when you callnexthook the window manager still interprets the data as an a, and then you get a keyup and you send a b anyways. You can fix this by sending the b only when it's a keydown, and not calling callnexthookex when it is a keydown you are replacing. I think.

Quell
February 18th, 2007, 02:20 PM
eh...i am still having a problem...now i am getting ba:

if (nCode == HC_ACTION)
{
if(wParam== WM_KEYDOWN)
{
KBDLLHOOKSTRUCT* kbh=(KBDLLHOOKSTRUCT*)lParam;
switch(kbh->vkCode)
{
case 0x41:
{
keybd_event(0x42,0,0,0);
return 0;
}
};
}
else
{
KBDLLHOOKSTRUCT* kbh=(KBDLLHOOKSTRUCT*)lParam;
switch(kbh->vkCode)
{
case 0x41:
{
return 0;
}
};
}
}
return CallNextHookEx(NULL, nCode, wParam, lParam);

Any idea why?

Calculator
February 18th, 2007, 03:27 PM
It's possible that you can not do this with WH_KEYBOARD_LL hooks then, and that stopping the hook chain doesn't make the computer forget that it's there.

Quell
February 18th, 2007, 03:36 PM
Hmm...is there another way to hook the keyboard input then?I don't want to start injecting code, because that would be versino dependent, so any other possibilites, maybe something in ring 0?

golanshahar
February 18th, 2007, 04:05 PM
Hmm...is there another way to hook the keyboard input then?I don't want to start injecting code, because that would be versino dependent, so any other possibilites, maybe something in ring 0?

Did you try to simply replace the data you receive in the hook, and call ::CallNextHookEx() with the swapped key, instead of generating keystroke in the hook?

Cheers

Quell
February 18th, 2007, 05:16 PM
yep, does nothing

if (nCode == HC_ACTION)
{
if(wParam == WM_KEYDOWN)
{
KBDLLHOOKSTRUCT* kbh=(KBDLLHOOKSTRUCT*)lParam;
switch(kbh->vkCode)
{
case 0x41:
{
/*keybd_event(0x42,0,0,0);
return 0;*/
kbh->vkCode=0x42;
}
};
}
/*else
{
KBDLLHOOKSTRUCT* kbh=(KBDLLHOOKSTRUCT*)lParam;
switch(kbh->vkCode)
{
case 0x41:
{
return 0;
}
};
}*/

}
return CallNextHookEx(NULL, nCode, wParam, lParam);

//JP added flex table