So I managed to get it working myself, here's what I found.
DOSBOX is an SDL application and so runs in OpenGL. Sending messages to OpenGL applications has been discussed before and is done using the SendInput()
method. This is apparantly what SendKeys
calls under the hood so I'm not sure why that wasn't working for me but it looks like I'm not the only one.
This unmaintained library seems to work fine, or a custom implementation can be done like this.
The other option as discussed in the stack overflow link above is to write a C or C++ library and call it through the C# application. This is what I ended up doing, here's the code.
Down.h
extern "C" __declspec(dllexport) void PressDownKey();
Down.cpp
#include <Windows.h>
#include "Down.h"
extern "C" __declspec(dllexport) void PressDownKey()
{
KEYBDINPUT KeybdInput;
ZeroMemory(&KeybdInput, sizeof(KeybdInput));
KeybdInput.wVk = VK_DOWN;
KeybdInput.dwExtraInfo = GetMessageExtraInfo();
INPUT InputStruct;
ZeroMemory(&InputStruct, sizeof(InputStruct));
InputStruct.ki = KeybdInput;
InputStruct.type = 1;
int A = SendInput(1,&InputStruct,sizeof(INPUT));
Sleep(10);
ZeroMemory(&KeybdInput, sizeof(KeybdInput));
KeybdInput.wVk = VK_DOWN;
KeybdInput.dwFlags = KEYEVENTF_KEYUP;
KeybdInput.dwExtraInfo = GetMessageExtraInfo();
ZeroMemory(&InputStruct, sizeof(InputStruct));
InputStruct.ki = KeybdInput;
InputStruct.type = 1;
A = SendInput(1,&InputStruct,sizeof(INPUT));
}