0
我寫簡單的控制檯應用程序,我想通過按鍵 來控制它有我的代碼:進行ON/OFF的控制檯程序通過按鍵
#include "stdafx.h"
#include <windows.h>
int i = 1;
BOOL WINAPI ConsoleHandlerRoutine(DWORD dwCtrlType)
{
if (dwCtrlType == CTRL_CLOSE_EVENT)
{
i = 0;
return TRUE;
}
return FALSE;
}
int _tmain(int argc, _TCHAR* argv[])
{
BOOL ret = SetConsoleCtrlHandler(ConsoleHandlerRoutine, TRUE);
while(i == 1){
SetCursorPos(200, 200);
mouse_event(MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0);
SetCursorPos(205, 205);
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
}
}
我怎樣才能使程序啓動和停止在鍵盤上按當控制檯窗口不活動?