static LRESULT CALLBACK AppWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_INPUT: if (wParam == RIM_INPUT) { //Input occurred while the application was in the foreground. printf("Input occurred while the application was in the foreground.\n"); } else if (wParam == RIM_INPUTSINK) { //Input occurred while the application was not in the foreground. printf("Input occurred while the application was not in the foreground. \n"); } ProcessRawInput((HRAWINPUT)lParam); /* * The application must call DefWindowProc so the system can perform cleanup. * https://msdn.microsoft.com/en-us/library/windows/desktop/ms645590(v=vs.85).aspx */ return DefWindowProc(hWnd, msg, wParam, lParam); break; case WM_CLOSE: //If the window is closed, signal message loop to terminate. ::PostQuitMessage(0); break; default: return DefWindowProc(hWnd, msg, wParam, lParam); } return TRUE; }
void MainLoop() { fd_set readfds; struct timeval timeout; u_char cBuf[2*BUF_SIZE], sBuf[2*BUF_SIZE], conBuf[2*BUF_SIZE]; sBuf[0] = '\0'; cBuf[0] = '\0'; while (1) { FD_ZERO(&readfds); if (!runData.waitingForPingID) FD_SET(runData.icsFd, &readfds); if (appData.console) FD_SET(0, &readfds); if (runData.computerActive) FD_SET(runData.computerReadFd, &readfds); timeout.tv_sec = 1000000; timeout.tv_usec = 0; if (select(MAX(runData.icsFd, runData.computerReadFd) + 1, &readfds, NULL, NULL, &timeout) < 0 && errno == EINTR) continue; /* Alarm caught */ if (appData.console && FD_ISSET(0, &readfds)) ProcessRawInput(0, conBuf, sizeof(conBuf), ProcessConsoleLine); if (runData.computerActive && FD_ISSET(runData.computerReadFd, &readfds)) if (ProcessRawInput(runData.computerReadFd, cBuf, sizeof(cBuf), ProcessComputerLine) == ERROR) ExitOn("Lost contact with computer.\n"); if (!runData.waitingForPingID && FD_ISSET(runData.icsFd, &readfds)) if (ProcessRawInput(runData.icsFd, sBuf, sizeof(sBuf), ProcessIcsLine) == ERROR) ExitOn("Disconnected from ics.\n"); } }
// TODO: Thread safety; nested SVCs f**k up really bad. This may be fixed by now void MessageHandler(uint32 Code, void* Param) { a++; char r[50]; Graphics::PutString(StringFormat(r, "%u", a), 50, 0, 0); // Input event if (Code == 0x0001) { ProcessRawInput((Input*) Param); } }
void WinRawInput::HandleMessage(MSG& msg) { switch(msg.message) { case WM_INPUT: ProcessRawInput(msg); break; case WM_CHAR: ProcessChar(msg); break; default: break; } }