private void RunKeyboardReader() { string input; while (true) { // Set a delay for checking the enabled status (save CPU%). Thread.Sleep(CHECK_FOR_INPUT_DELAY); while (!isEnabled) { Thread.Sleep(CHECK_FOR_INPUT_DELAY); } isRunning = true; keyboardProc = Process.Start(keyboardProcStartInfo); StreamReader reader = keyboardProc.StandardOutput; while (!keyboardProc.HasExited && !reader.EndOfStream) { input = reader.ReadLine(); if (isEnabled) { theInputReaderController. AddToInputQueue(input.Split(',').ToList()); theInputReaderController.SetLookingForInput(false); } } isRunning = false; isEnabled = false; } }
private void RunGamepadReader(string gamepad) { /* * Start the process to read gamepad input. */ int gamepadIndex = int.Parse( gamepad.Substring( GAMEPAD_NUMBER_START_INDEX, gamepad.Length - GAMEPAD_NUMBER_START_INDEX) ); ProcessStartInfo startInfo = new ProcessStartInfo { FileName = EXE_PATH, Arguments = EXE_ARGS + " " + gamepad, WorkingDirectory = gamepadDirectory, UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true }; Process gamepadProc; gamepadProc = Process.Start(startInfo); bool gamepadProcRunning = true; gamepadProcs.Add(gamepadProc); StreamReader reader = gamepadProc.StandardOutput; while (gamepadProcRunning && !gamepadProc.HasExited) { readString = reader.ReadLine(); if (readString == PROC_TERMINATING_STRING) { gamepadProcRunning = false; } else { List <string> splitStringList; splitStringList = readString.Split(',').ToList(); // Verify whether the input meets or exceeds the axis // deadzone threshold. Only add the input to the queue if it // meets or exceeds the threshold or no the buttons on the UI // are not being set. if (!theInputReaderController.CheckLookingForInput() || MeetsAxisThreshold(splitStringList) ) { theInputReaderController.AddToInputQueue(splitStringList); theInputReaderController.SetLookingForInput(false); } } } enabledGamepadList.Remove(gamepadIndex); gamepadProcs.Remove(gamepadProc); }