-
February 18th, 2007, 12:55 PM
#1
Hey.
Code:
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
Last edited by Quell; February 18th, 2007 at 01:56 PM.
-
February 18th, 2007, 01:57 PM
#2
Re: SetWindowsHookEx->Modding keyboard input
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.
Windows XP, Visual Studio 2008, SVN
-
February 18th, 2007, 02:20 PM
#3
Re: SetWindowsHookEx->Modding keyboard input
eh...i am still having a problem...now i am getting ba:
Code:
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?
-
February 18th, 2007, 03:27 PM
#4
Re: SetWindowsHookEx->Modding keyboard input
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.
Windows XP, Visual Studio 2008, SVN
-
February 18th, 2007, 03:36 PM
#5
Re: SetWindowsHookEx->Modding keyboard input
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?
-
February 18th, 2007, 04:05 PM
#6
Re: SetWindowsHookEx->Modding keyboard input
Originally Posted by Quell
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
-
February 18th, 2007, 05:16 PM
#7
Re: SetWindowsHookEx->Modding keyboard input
yep, does nothing
Code:
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);
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|