public override void EndInput() { base.EndInput(); ButtonsPressed.Clear(); ButtonsPressed = null; NextButtonToPress = Keys.None; StartTime = 0d; }
protected override void ReadInput() { if (Time.ActiveMilliseconds >= StartTime) { OnComplete(CommandResults.Success); return; } //If the user reached the max input amount, stop if (ButtonsPressed.Count >= InputLimit) { return; } //Check if the player pressed the correct button. //If a button from the possible ones was pressed and the correct button wasn't, //the command is failed and ends immediately bool pressedCorrectButton = false; bool pressedIncorrectButton = false; for (int i = 0; i < PossibleButtons.Length; i++) { Keys currentButton = PossibleButtons[i]; if (AutoComplete == true || Input.GetKeyDown(currentButton) == true) { if (AutoComplete == true || currentButton == NextButtonToPress) { //Add the button to the list, send the response, and retrieve the new one ButtonsPressed.Add(NextButtonToPress); SendResponse(ButtonsPressed.Count); NextButtonToPress = GetNextButton(); pressedCorrectButton = true; break; } else { pressedIncorrectButton = true; } } } //If the correct button wasn't pressed and another button out of the possible options was pressed, it's a failure if (pressedIncorrectButton == true && pressedCorrectButton == false) { OnComplete(CommandResults.Failure); } }
public override int GetHashCode() { int hash = 1; if (Id != 0) { hash ^= Id.GetHashCode(); } if (ButtonsPressed != 0) { hash ^= ButtonsPressed.GetHashCode(); } if (ButtonsReleased != 0) { hash ^= ButtonsReleased.GetHashCode(); } return(hash); }
private static void OnReport(HidReport report) { if (_attached == false) { return; } if (report.Data.Length >= 4) { var message = MessageFactory.CreateMessage(_currentProductId, report.Data); ButtonsPressed.Update(message); ButtonsDepressed.Update(message); /*if (ButtonsPressed.leftBongoBottomPressed) * Console.WriteLine("Left Bongo Bottom Pressed"); * if (ButtonsPressed.leftBongoTopPressed) * Console.WriteLine("Left Bongo Top Pressed"); * if (ButtonsPressed.rightBongoBottomPressed) * Console.WriteLine("Right Bongo Bottom Pressed"); * if (ButtonsPressed.rightBongoTopPressed) * Console.WriteLine("Right Bongo Top Pressed"); * if (ButtonsPressed.startPressed) * Console.WriteLine("Start Pressed");*/ if (mode == -1 && message.startPressed) { mode = 0; currentChar = 0; Press("A"); } else if (mode != -1) { string charSet = GetCharacterSet(); if (ButtonsPressed.startPressed) { mode++; mode %= 3; currentChar = 0; UpdateCharacter(); } if (ButtonsPressed.leftBongoBottomPressed) { Press("{BACKSPACE}"); } if (ButtonsPressed.leftBongoTopPressed) { currentChar = 0; Press(charSet.Substring(currentChar, 1)); } if (ButtonsPressed.rightBongoBottomPressed) { currentChar = ((currentChar - 1) + charSet.Length) % charSet.Length; UpdateCharacter(); } if (ButtonsPressed.rightBongoTopPressed) { currentChar = ((currentChar + 1) + charSet.Length) % charSet.Length; UpdateCharacter(); } if (ButtonsPressed.micClap) { Console.WriteLine("Clapped"); Press(" "); } } } System.Threading.Thread.Sleep(1000 / 30); _device.ReadReport(OnReport); }
public bool IsPressed(Buttons button) => ButtonsPressed.Contains(button);