Thread: keybd_event
View Single Post
Re: keybd_event
Old
  (#14)
Austin
Moderator
 
Austin's Avatar
 
Status: Offline
Posts: 403
Join Date: Nov 2003
Default Re: keybd_event - 05-10-2005

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..

Last edited by Austin; 05-10-2005 at 08:39..
  
Reply With Quote