我有一个带有组合框的应用程序,其中包含当前正在运行的应用程序的名称。正如我从 msdn 库中了解到的,SendKeys 方法只能将密钥发送到活动应用程序。在.NET中是否有可能将密钥也发送到非活动应用程序?或者至少在 WinAPI 中?
问问题
3305 次
2 回答
1
您可以使用SendMessage()
API 函数将击键发送到非活动窗口。
于 2009-10-18T13:25:28.090 回答
0
With C# <3 is everthing possible :D
No need to be active window, as u wished.
Also here a usefull list of Virtual Key Codes
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
public static extern bool PostMessage(int hWnd, uint Msg, int wParam, int lParam);
private void button1_Click(object sender, EventArgs e)
{
const int WM_SYSKEYDOWN = 0x0104;
const int VK_KEY_A = 0x41;
IntPtr WindowToFind = FindWindow(null, "Window Name");
//In ur case u have to write a code that translates the combobox into Virtual Key Codes. Will take time but it shouls be easy
PostMessage(WindowToFind, WM_SYSKEYDOWN, VK_KEY_A, 0);
//PostMessage(WindowToFind, WM_SYSKEYDOWN, ((int)Keys.NumPad7), 0);
}
于 2018-06-14T12:25:07.123 回答