And you don't need to copy/paste all VKey Values for the WPARAM... an build-in enum will do the work for you:
Code:
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace Windows.Interop
{
static class KeySim
{
#region P/Invoke
private const uint WM_KEYDOWN = 0x100,
WM_KEYUP = 0x101;
[DllImport("user32", EntryPoint = "PostMessage", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private extern static bool InternalPostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
#endregion
public static void KeyDown(Keys keyDown)
{
if (!InternalPostMessage(ObjectManager.MemReader.MainWindowHandle, // Insert your WowProcessHandle!
WM_KEYDOWN,
new IntPtr(IntPtr.Size == 4 ? (int)keyDown : (long)keyDown), // WPARAM is x64/x86 dependant, therefore cast from long/int to IntPtr
IntPtr.Zero)) throw new Win32Exception(Marshal.GetLastWin32Error());
}
public static void KeyUp(Keys keyUp)
{
if (!InternalPostMessage(ObjectManager.MemReader.MainWindowHandle,
WM_KEYUP,
new IntPtr(IntPtr.Size == 4 ? (int)keyUp : (long)keyUp),
IntPtr.Zero)) throw new Win32Exception(Marshal.GetLastWin32Error());
}
public static void ReleaseArrowKeys()
{
KeyUp(Keys.Up);
KeyUp(Keys.Down);
KeyUp(Keys.Left);
KeyUp(Keys.Right);
}
}
}
is just how i've done it. This uses the Keys-enum in System.Windows.Forms.