![](/img/trans.png)
[英]how to properly simulate keyboard events once a hotkey combination is activated
[英]How to simulate Keyboard Events in Code in not active window?
如何在不使用SetForegroundWindow()
使目標窗口處於活動狀態的情況下使用SendWait()
將擊鍵發送到窗口?
這是MSDN站點上的SendWait示例: http : //msdn.microsoft.com/zh-cn/library/ms171548.aspx
看到這個線程 。 基本上為窗口提供了一些句柄,您需要使用p / invoke並使用WM_KEYDOWN
消息調用PostMessage :
private const int VK_RETURN = 0x0D;
private const uint WM_KEYDOWN = 0x0100;
[DllImport("user32.dll", SetLastError = true)]
private static extern bool PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
public void SendKeysToWindow(IntPtr hWnd)
{
PostMessage(hWnd, WM_KEYDOWN, new IntPtr(VK_RETURN), IntPtr.Zero);
}
這是虛擬密鑰的列表 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.