I wrote this hack to monitor my cz dedicated server and restart it.
The part that may interest you is I look for the error message box window and "press" the ok button by sending it a space bar down and space bar up using PostMessage() . You can do the same for any key....
Code:
void CFindNBWindowDlg::OnTimer(UINT nIDEvent)
{
HWND nbWindow, buttonWindow;
nbWindow = ::FindWindow(NULL, "Fatal error - Dedicated server");
if (::IsWindow(nbWindow))
{
buttonWindow = ::FindWindowEx(nbWindow, NULL, "Button", "Ok");
if (::IsWindow(buttonWindow))
{
Log(" Fatal Error window close.\n");
//::SetForegroundWindow(buttonWindow);
::PostMessage(buttonWindow, WM_KEYDOWN, (WPARAM)VK_SPACE, (LPARAM)0);
::PostMessage(buttonWindow, WM_KEYUP, (WPARAM)VK_SPACE, (LPARAM)0);
}
}
else
{
nbWindow = ::FindWindow(NULL, "Console");
if (!::IsWindow(nbWindow))
{
Log(" Restart.\n");
Sleep(4000);
WinExec("C:\\HLServer\\hlds.exe -game czero -noipx -nojoy -console", SW_SHOWMINIMIZED);
}
}
CDialog::OnTimer(nIDEvent);
}
Hope this helps..