1
我一直在寻找一个有关如何完成此操作的工作示例,但目前为止没有运气。将按键发送到不在前台的应用程序(即最小化)
这就是我现在所拥有的:
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool PostMessage(IntPtr hWnd, uint Msg, IntPtr
wParam, IntPtr lParam);
Process[] processlist = Process.GetProcesses();
foreach (Process p in processlist)
{
if (p.ProcessName == "notepad")
{
//MessageBox.Show("bu");
/*
LRESULT PostMessage(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
WM_KEYDOWN
WPARAM wParam
LPARAM lParam;
Parameters
wParam
Specifies the virtual-key code of the nonsystem key.
lParam
Specifies the repeat count, scan code, extended-key flag,
context code, previous key-state flag, and transition-state flag,
as shown in this table.
......So......
LRESULT debugvalue = PostMessage(Handle_to_where_the_message_is_going,
WM_KEYDOWN, (WPARAM)VK_ENTER, (LPARAM)0)
*/
uint WM_KEYDOWN = 0x0100;
PostMessage(p.Handle, WM_KEYDOWN, Marshal.StringToHGlobalAuto("something"), IntPtr.Zero);
}
}
现在,我究竟做错了什么?
http://msdn.microsoft.com/en-us/library/ms646280%28VS.85%29.aspx可能的援助
“现在,我做错了什么?” - 对于初学者,您可以在其他问题上标记一些答案......这可能会让您获得更多答复,尤其是当您粘贴大量代码而不是询问尖锐问题时。 – 2010-02-27 02:06:01
为什么要在最小化的应用程序中捕获击键?除非你能证明你想要做的事情,而且我错误地假设了,我希望主持人给你一个愉快的假期。 – 2010-02-27 02:23:58
@Nick,他希望将击键发送到最小化的应用程序,而不是捕获它们。 – 2010-02-27 11:36:19