I use C++ program to interact with my web, it will simulate the keys pressing when print page show . key pressing event is CTRL + SHIFT + P .
Using SendInput send pressing event (ctrl + shift + p) for my web page(in Chorme) , function is ok for web page, I have tested it, but it is invalid when the print page show .
why print page show and the SendInput is invalid ? Is print page forbidden key message for ?
int main() {
HWND parentHwnd, childHwnd;
parentHwnd = FindWindow(NULL,"XiaoYouCha - Google Chrome");
if (parentHwnd)
{
childHwnd = FindWindowEx(parentHwnd, NULL, NULL, NULL);
SetForegroundWindow(parentHwnd);
Sleep(1000);
ShowPrint();
}
}
void ShowPrint()
{
INPUT inputs[6] = {};
ZeroMemory(inputs, sizeof(inputs));
inputs[0].type = INPUT_KEYBOARD;
inputs[0].ki.wVk = VK_LCONTROL;
inputs[0].ki.wScan = MapVirtualKeyEx(VK_LCONTROL, 0, (HKL)0xf0010413);
inputs[1].type = INPUT_KEYBOARD;
inputs[1].ki.wVk = VK_LSHIFT;
inputs[1].ki.wScan = MapVirtualKeyEx(VK_LSHIFT, 0, (HKL)0xf0010413);
inputs[2].type = INPUT_KEYBOARD;
inputs[2].ki.wVk = 'P';
inputs[2].ki.wScan = MapVirtualKeyEx('P', 0, (HKL)0xf0010413);
inputs[3].type = INPUT_KEYBOARD;
inputs[3].ki.wVk = 'P';
inputs[3].ki.dwFlags = KEYEVENTF_KEYUP;
inputs[4].type = INPUT_KEYBOARD;
inputs[4].ki.wVk = VK_LSHIFT;
inputs[4].ki.dwFlags = KEYEVENTF_KEYUP;
inputs[5].type = INPUT_KEYBOARD;
inputs[5].ki.wVk = VK_LCONTROL;
inputs[5].ki.dwFlags = KEYEVENTF_KEYUP;
UINT uSent = SendInput(ARRAYSIZE(inputs), inputs, sizeof(INPUT));
if (uSent != ARRAYSIZE(inputs))
{
printf("SendInput failed: 0x%x\n", HRESULT_FROM_WIN32(GetLastError()));
}
}