public static void Update() { if (FirstPlayer == -1) { return; } var oldStates = States; States = new InputStates { GamePadState = OpenTK.Input.GamePad.GetState(FirstPlayer), //KeyboardState = Keyboard.GetState() }; foreach (string button in ButtonNames) { if (States.IsButtonDown(button, true)) { if (!oldStates.IsButtonDown(button, true)) { foreach (var dele in ButtonPress?.GetInvocationList() ?? new Delegate[] { }) { if ((bool)dele.DynamicInvoke(button)) { break; } } } } else if (oldStates.IsButtonDown(button, true)) { foreach (var dele in ButtonRelease?.GetInvocationList() ?? new Delegate[] { }) { if ((bool)dele.DynamicInvoke(button)) { break; } } } } }
/// <summary> /// Check if a button is pressed /// </summary> /// <param name="button"></param> /// <returns></returns> public static bool IsButtonPressed(string button) { return(States.IsButtonDown(button)); }