In my specific case, I'm trying to create an application that sends keyboard keystrokes to the DosBox (the dos-games emulator, not the windows command prompt).
I tried doing it using SendKeys but that does not work because DosBox is not an application that processes windows-messages (an exception told me that).
At the moment I'm trying to do that using a keyboard hook, like this: The first method is the one which receives hooked keystrokes and puts them through to the next application (like in this example)
private IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
{
return CallNextHookEx(hookId, nCode, wParam, lParam);
}
private void GenerateKeyPress()
{
int vkCode = (int)Keys.Up; //My chosen key to be send to dosbox
IntPtr lParam = new IntPtr(vkCode);
IntPtr wParam = new IntPtr(255);
CallNextHookEx(hookId, 0, wParam, lParam);
}
The CallNextHookEx() function call however throws an access violation exception.
What do I need to think of here?