问题
这是我在后台发送击键的功能。
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);
}
}
此代码可以正常工作notepad
,例如 let appName = "notepad"。
但是,我可以设法在其他应用程序中做到这一点..我练习在 LINE 应用程序上做。
正如您在图片中看到的lpszClass variable
=“编辑”(红色小圆圈)用于记事本。
我需要为 LINE 应用程序找到它,所以我用它WinSpy++
来捕获那些类名。
我发现它的类名是“ATL:00B53BE8”(大红色圆圈),我可以输入消息
在 WinSpy++ 中输入,它将出现在 Line 文本框(蓝色圆圈)中。
综上所述
我尝试用“编辑”替换捕获类名,但没有希望。
我不明白为什么捕获类名不可用,请帮助或给我一些提示。
我不知道这可能是关于系统应用程序的层次结构不同(粉红色的)
而且我不知道 FindWindowEx 中的哪些参数意义重大。
我的最终目标是将击键发送到其他应用程序而不关注它们。