Hello guys i'm making a trainer for ms, but can't send keystrokes without the ms windows focused. I tried with the class, name of the windows, pid, and nothing...
I used PostMessage and MapVirtualKey to send key and FindWindow to find the maplestory windows.
[DllImport("user32.dll", EntryPoint = "PostMessageW")]
private static extern bool PostMessage(int hwnd, int wMsg, int wParam, int lParam);
[DllImport("user32.dll", EntryPoint = "FindWindow")]
private static extern int FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
private static extern int MapVirtualKey(uint uCode, uint uMapType);
and use pid to get to correct maplestory windows if use multiclient, like
int hwnd = FindWindow(null, Process.GetProcessById(Int32.Parse(pid, NumberStyles.HexNumber)).MainWindowTitle);
then send the key
int lParam = (MapVirtualKey(key, 0) << 16) + 1;
PostMessage(hwnd, WM_KEYDOWN, key, lParam);
PostMessage(hwnd, WM_KEYUP, key, lParam);
But, don't work if maplestory windows not are focused.
Greetings and thanks!