Hey,
I've got a keyboard hook that drops the keys A-Z when they're pressed (shows in console that they were pressed, but they don't make it to the processing queue). I'm now trying to figure out how to make it so that it will send a different key to the queue instead of the one pressed.
Here's my code that drops the keys and simulates another one
Code:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <iostream>
using namespace std;
LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
PKBDLLHOOKSTRUCT p = (PKBDLLHOOKSTRUCT) lParam;
BOOL fEatKeystroke = FALSE;
if (nCode == HC_ACTION)
{
switch (wParam)
{
case WM_KEYDOWN:
case WM_SYSKEYDOWN:
case WM_KEYUP:
case WM_SYSKEYUP:
{
//block out keys A-Z
if ( p->vkCode <= 90 && p->vkCode >= 41 )
{
fEatKeystroke = true;
}
//if we're gonna drop the keystroke
if (fEatKeystroke)
{
//Show on the console that the key was pressed...
cout << (char)p->vkCode << " Pressed, scancode: " << (p->scanCode) << endl;
//Simulate another random key (random # that I came up with).
p->vkCode = 70;
p->scanCode = 30;
//This probably isn't necessary, but I'm doing it instead
lParam = (LPARAM)p;
}
break;
}
}
}
//Call the next hook if the key isn't going to be dropped...
//return(fEatKeystroke ? 1 : CallNextHookEx(NULL, nCode, wParam, lParam));
return CallNextHookEx ( NULL, nCode, wParam, lParam );
}
int main ( void )
{
// Install the low-level keyboard & mouse hooks
HHOOK hhkLowLevelKybd = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, NULL, 0);
// Keep this app running until we're told to stop
MessageBox(NULL,
TEXT("Click \"Ok\" to terminate this application."),
TEXT("Disable Low-Level Keys"), MB_OK);
UnhookWindowsHookEx(hhkLowLevelKybd);
return(0);
}
However, this code doesn't simulate a different key (still forwards the keys I pressed). How can I simulate keys with this hook?
Thanks in advance for the help,
Guitarist809