我正在尝试向Chrome发送一些键盘输入并让它打开一个新窗口
int NewWindow(const char *url)
{
HWND chrome = FindWindow(L"Chrome_WidgetWin_1", NULL);
if (chrome == NULL)
{
puts("Can't find chrome window");
return -1;
}
if (! SetForegroundWindow(chrome))
{
puts("Can't move chrome to foreground");
return -2;
}
INPUT *inputs = new INPUT[2];
inputs[0].type = INPUT_KEYBOARD;
inputs[0].ki.wVk = VK_CONTROL;
inputs[0].ki.wScan = 'n';
inputs[0].ki.dwFlags = KEYEVENTF_UNICODE;
inputs[0].ki.time = 0;
inputs[0].ki.dwExtraInfo = GetMessageExtraInfo();
inputs[1].type = INPUT_KEYBOARD;
inputs[1].ki.wVk = VK_CONTROL;
inputs[1].ki.wScan = 'n';
inputs[1].ki.dwFlags = KEYEVENTF_UNICODE | KEYEVENTF_KEYUP;
inputs[1].ki.time = 0;
inputs[1].ki.dwExtraInfo = GetMessageExtraInfo();
int keystrokes_sent = SendInput(2, inputs, sizeof(*inputs));
fprintf(stderr, "Send %d keystrokes\n", keystrokes_sent);
delete [] inputs;
return 0;
}
当我执行它时,chrome窗口被移动到前景但没有任何改变。
有什么想法吗?我正在使用版本58.0.3029.110