Hi, I've been researching these past few days on SendMessage and FindWindow and I've been looking at example source codes but I just can't seem to understand the process between it.
At first I just wanted to send a simple message from a textbox to the open chat of another process which is some game. I'm running this game / my server with a cmd console and now I just want to send userinput from a textbox to the cmd since the server uses simple command lines for moderation. Any help will be greatly appreciated thank you.
I've tested a lot of things out and managed to get some macros working but that's about it:
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern IntPtr FindWindow(string IpClassName, string IpWindowName);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
[DllImport("user32.dll", EntryPoint = "SendMessage")]
public static extern int SendMessage(int hWnd, int Msg, int wParam, int lParam);
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
const int WM_KeyDown = 0x100;
const int WM_SYSKeyDown = 0x104;
if ((msg.Msg == WM_KeyDown || (msg.Msg == WM_SYSKeyDown)))
{
switch(keyData)
{
case Keys.Down:
MessageBox.Show("Down Arrow Captured");
break;
case Keys.Up:
MessageBox.Show("Up Arrow Captured");
break;
case Keys.Tab:
MessageBox.Show("Tab Key Captured");
break;
case Keys.Control | Keys.M:
MessageBox.Show("<CTRL> + M Captured");
break;
case Keys.Alt | Keys.Z:
MessageBox.Show("<ALT> + Z Captured");
break;
case Keys.R:
IntPtr handle = FindWindow(null, @"C:\windows\system32\cmd.exe");
break;
}
}
return base.ProcessCmdKey(ref msg, keyData);
}