In my specific case, I am trying to create an application that sends keyboard keystrokes to DosBox (dos-games emulator, not the Windows command line).
I tried to do this using SendKeys, but this does not work because DosBox is not an application that processes Windows messages (this was explained to me by the exception).
I am currently trying to do this using the keyboard, for example: The first method is the one that receives keystrokes and transfers them to the next application (for example, 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;
IntPtr lParam = new IntPtr(vkCode);
IntPtr wParam = new IntPtr(255);
CallNextHookEx(hookId, 0, wParam, lParam);
}
However, calling the CallNextHookEx () function throws an access violation exception.
What do I need to think about here?