I am trying to make an application for routine projects;
It is more like autogui,macro but when macro is running i should be able to do another things so i need two mouse and two keyboards at the sametime running one of for my use otherone should run in the application
I can successfully post message to notepad with enter it to textbox but other applications not work like calculator,notepad++,discord,.. so on
I need to send keyboard,mouse to current form application
In both methods
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
First method
[DllImport("User32.Dll", EntryPoint = "PostMessageA", SetLastError = true)]
public static extern bool PostMessage(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);
public void control()
{
Process[] processes = Process.GetProcessesByName(textBox1.Text);
foreach (Process p in processes)
{
textBox2.Text += p.ProcessName + System.Environment.NewLine;
IntPtr windowHandle = p.MainWindowHandle;
const int WM_KEYDOWN = 0x0100;
const int VM_KEYUP = 0x0101;
IntPtr editx = FindWindowEx(windowHandle, IntPtr.Zero, "edit", null);
PostMessage(editx, WM_KEYDOWN, (IntPtr)66, IntPtr.Zero);
PostMessage(editx, VM_KEYUP, (IntPtr)66, IntPtr.Zero);
}
}
Other tried method
[DllImport("user32.dll")]
private static extern bool PostMessage(IntPtr hWnd, UInt32 Msg, int wParam, Int32 lParam);
public void control()
{
IntPtr handle = this.Handle;
IntPtr handle2 = Handle;
const int WM_KEYDOWN = 0x0100;
const int VM_KEYUP = 0x0101;
const int WM_MOUSEMOVE = 0x0200;
const int WM_LBUTTONDOWN = 0x0201;
const int WM_LBUTTONUP = 0x0202;
IntPtr editx = FindWindowEx(handle , IntPtr.Zero, "edit", null);
IntPtr editx2 = FindWindowEx(handle2, IntPtr.Zero, "edit", null);
PostMessage(editx, WM_KEYDOWN, (Int32)Keys.S, 1);
PostMessage(editx, VM_KEYUP, (Int32)Keys.S, 1);
PostMessage(editx, WM_LBUTTONDOWN, 1, (280 << 16) | 280);
PostMessage(editx, WM_LBUTTONUP, 0, (280 << 16) | 280);
PostMessage(editx2, WM_KEYDOWN, (Int32)Keys.S, 1);
PostMessage(editx2, VM_KEYUP, (Int32)Keys.S, 1);
PostMessage(editx2, WM_LBUTTONDOWN, 1, (280 << 16) | 280);
PostMessage(editx2, WM_LBUTTONUP, 0, (280 << 16) | 280);
}
It can be about:
IntPtr editx = FindWindowEx(windowHandle, IntPtr.Zero, "edit", null);
What can i write instead edit and how can i find it ?
I tried to trace what i giving to GetProcessesByName("") with textBox2.Text , i am sure about process names are true
Even to make sure about used method i send to all related names with for
So what is wrong about this method ?
Why it is not working on other applications ?