Send Keys to a DirectX Game:
Code:
struct INPUT
{
public UInt32 type;
//KEYBDINPUT:
public ushort wVk;
public ushort wScan;
public UInt32 dwFlags;
public UInt32 time;
public UIntPtr dwExtraInfo;
//HARDWAREINPUT:
public UInt32 uMsg;
public ushort wParamL;
public ushort wParamH;
}
enum SendInputFlags
{
KEYEVENTF_EXTENDEDKEY = 0x0001,
KEYEVENTF_KEYUP = 0x0002,
KEYEVENTF_UNICODE = 0x0004,
KEYEVENTF_SCANCODE = 0x0008,
}
[DllImport("user32.dll")]
static extern UInt32 SendInput(UInt32 nInputs, [MarshalAs(UnmanagedType.LPArray, SizeConst = 1)] INPUT[] pInputs, Int32 cbSize);
For using this:
Code:
INPUT[] InputData = new INPUT[1];
InputData[0].type = 1; //INPUT_KEYBOARD
InputData[0].wScan = (ushort)hex_code; // http://tescosi.com/wiki/General:DirectX_KeyMap
InputData[0].dwFlags = (uint)SendInputFlags.KEYEVENTF_SCANCODE;
For your memory problem, there are more than enough tutorials at the www.