PROBLEM
This is my function to send key stroke in background.
class SendMessage
{
[DllImport("user32.dll")]
public static extern IntPtr PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
public static void sendKeystroke(string appName)
{
const int WM_KEYDOWN = 0x100;
IntPtr hWnd = FindWindow(null, appName);
IntPtr editx = FindWindowEx(hWnd, IntPtr.Zero, "edit", null);
PostMessage(editx, WM_KEYDOWN, (IntPtr)Keys.A, (IntPtr)0);
}
}
This code is work fine for notepad
for example let appName = "notepad".
However, I can manage to do it in other application ..I practice doing on LINE application.
As you can see in the picture lpszClass variable
= "edit" (small red circle) is for notepad.
I need to find it for LINE app so, I use WinSpy++
to capture those class name.
I found out that its class name is "ATL:00B53BE8" (big red circle) which I can type the message
in WinSpy++ and enter, it will appear to Line textbox (blue circle).
IN CONCLUSION
I try to replace capture class name with "edit" but no hope.
I don't understand why capture class name is not usable please help or give me some hint.
I don't know maybe it is about the hierarchy of system application different or not (pink one)
and I don't know which params in FindWindowEx mean that much.
My ultimate goal is to sent key stroke to other application without focus on them.