/
InputHandler.cs
1137 lines (1059 loc) · 64.4 KB
/
InputHandler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using static MLEM.Input.GenericInput;
namespace MLEM.Input {
/// <summary>
/// An input handler is a more advanced wrapper around MonoGame's default input system.
/// It includes keyboard, mouse, gamepad and touch handling through the <see cref="GenericInput"/> wrapper, as well as a new "pressed" state for inputs, the ability for keyboard and gamepad repeat events, and the ability to track down, up and press times for inputs.
/// </summary>
public class InputHandler : GameComponent {
/// <summary>
/// All values of the <see cref="Buttons"/> enum.
/// </summary>
public static readonly Buttons[] AllButtons =
#if NET6_0_OR_GREATER
Enum.GetValues<Buttons>();
#else
(Buttons[]) Enum.GetValues(typeof(Buttons));
#endif
/// <summary>
/// All values of the <see cref="Keys"/> enum.
/// </summary>
public static readonly Keys[] AllKeys =
#if NET6_0_OR_GREATER
Enum.GetValues<Keys>();
#else
(Keys[]) Enum.GetValues(typeof(Keys));
#endif
#if FNA
private const int MaximumGamePadCount = 4;
#else
private static readonly int MaximumGamePadCount = GamePad.MaximumGamePadCount;
#endif
private static readonly TouchLocation[] EmptyTouchLocations = new TouchLocation[0];
private static readonly GenericInput[] EmptyGenericInputs = new GenericInput[0];
/// <summary>
/// Contains all of the gestures that have finished during the last update call.
/// To easily query these gestures, use <see cref="GetGesture"/> or <see cref="GetViewportGesture"/>.
/// </summary>
public readonly ReadOnlyCollection<GestureSample> Gestures;
/// <summary>
/// Set this field to false to disable keyboard handling for this input handler.
/// </summary>
public bool HandleKeyboard;
/// <summary>
/// Set this field to false to disable mouse handling for this input handler.
/// </summary>
public bool HandleMouse;
/// <summary>
/// Set this field to false to disable keyboard handling for this input handler.
/// </summary>
public bool HandleGamepads;
/// <summary>
/// Set this field to false to disable touch handling for this input handler.
/// </summary>
public bool HandleTouch;
/// <summary>
/// This is the amount of time that has to pass before the first keyboard repeat event is triggered.
/// <seealso cref="KeyRepeatRate"/>
/// </summary>
public TimeSpan KeyRepeatDelay = TimeSpan.FromSeconds(0.65);
/// <summary>
/// This is the amount of time that has to pass between keyboard repeat events.
/// <seealso cref="KeyRepeatDelay"/>
/// </summary>
public TimeSpan KeyRepeatRate = TimeSpan.FromSeconds(0.05);
/// <summary>
/// Set this field to false to disable keyboard repeat event handling.
/// </summary>
public bool HandleKeyboardRepeats = true;
/// <summary>
/// Set this field to false to disable gamepad repeat event handling.
/// </summary>
public bool HandleGamepadRepeats = true;
/// <summary>
/// This field represents the deadzone that gamepad <see cref="Buttons"/> have when input is queried for them using this input handler.
/// A deadzone is the percentage (between 0 and 1) that an analog value has to exceed for it to be considered down (<see cref="IsGamepadButtonDown"/>) or pressed (<see cref="IsGamepadButtonPressed"/>).
/// Querying of analog values is done using <see cref="GamepadExtensions.GetAnalogValue"/>.
/// </summary>
public float GamepadButtonDeadzone;
/// <summary>
/// Set this field to true to invert the press behavior of <see cref="IsKeyPressed"/>, <see cref="IsMouseButtonPressed"/>, <see cref="IsGamepadButtonPressed"/> and <see cref="IsPressed"/>.
/// Inverted behavior means that, instead of an input counting as pressed when it was up in the last frame and is now down, it will be counted as pressed when it was down in the last frame and is now up.
/// </summary>
public bool InvertPressBehavior;
/// <summary>
/// If your project already handles the processing of MonoGame's gestures elsewhere, you can set this field to true to ensure that this input handler's gesture handling does not override your own, since <see cref="GestureSample"/> objects can only be retrieved once and are then removed from the <see cref="TouchPanel"/>'s queue.
/// If this value is set to true, but you still want to be able to use <see cref="Gestures"/>, <see cref="GetGesture"/>, and <see cref="GetViewportGesture"/>, you can make this input handler aware of a gesture for the duration of the update frame that you added it on by using <see cref="AddExternalGesture"/>.
/// For more info, see https://mlem.ellpeck.de/articles/input.html#external-gesture-handling.
/// </summary>
public bool ExternalGestureHandling;
/// <summary>
/// An array of all <see cref="Keys"/>, <see cref="Buttons"/> and <see cref="MouseButton"/> values that are currently down.
/// Additionally, <see cref="TryGetDownTime"/> or <see cref="GetDownTime"/> can be used to determine the amount of time that a given input has been down for.
/// </summary>
public GenericInput[] InputsDown { get; private set; } = InputHandler.EmptyGenericInputs;
/// <summary>
/// An array of all <see cref="Keys"/>, <see cref="Buttons"/> and <see cref="MouseButton"/> that are currently considered pressed.
/// An input is considered pressed if it was up in the last update, and is up in the current one.
/// </summary>
public GenericInput[] InputsPressed { get; private set; } = InputHandler.EmptyGenericInputs;
/// <summary>
/// Contains the touch state from the last update call
/// </summary>
public TouchCollection LastTouchState { get; private set; } = new TouchCollection(InputHandler.EmptyTouchLocations);
/// <summary>
/// Contains the current touch state
/// </summary>
public TouchCollection TouchState { get; private set; } = new TouchCollection(InputHandler.EmptyTouchLocations);
/// <summary>
/// Contains the <see cref="LastTouchState"/>, but with the <see cref="GraphicsDevice.Viewport"/> taken into account.
/// </summary>
public IList<TouchLocation> LastViewportTouchState { get; private set; } = new List<TouchLocation>();
/// <summary>
/// Contains the <see cref="TouchState"/>, but with the <see cref="GraphicsDevice.Viewport"/> taken into account.
/// </summary>
public IList<TouchLocation> ViewportTouchState { get; private set; } = new List<TouchLocation>();
/// <summary>
/// Contains the amount of gamepads that are currently connected. Note that this value will be set to 0 if <see cref="HandleGamepads"/> is false.
/// This field is automatically updated in <see cref="Update()"/>.
/// </summary>
public int ConnectedGamepads { get; private set; }
/// <summary>
/// Contains the mouse state from the last update call
/// </summary>
public MouseState LastMouseState { get; private set; }
/// <summary>
/// Contains the current mouse state
/// </summary>
public MouseState MouseState { get; private set; }
/// <summary>
/// Contains the position of the mouse from the last update call, extracted from <see cref="LastMouseState"/>
/// </summary>
public Point LastMousePosition => new Point(this.LastMouseState.X, this.LastMouseState.Y);
/// <summary>
/// Contains the <see cref="LastMousePosition"/>, but with the <see cref="GraphicsDevice.Viewport"/> taken into account.
/// </summary>
public Point LastViewportMousePosition => this.LastMousePosition + this.ViewportOffset;
/// <summary>
/// Contains the current position of the mouse, extracted from <see cref="MouseState"/>
/// </summary>
public Point MousePosition => new Point(this.MouseState.X, this.MouseState.Y);
/// <summary>
/// Contains the <see cref="MousePosition"/>, but with the <see cref="GraphicsDevice.Viewport"/> taken into account.
/// </summary>
public Point ViewportMousePosition => this.MousePosition + this.ViewportOffset;
/// <summary>
/// Contains the current scroll wheel value, in increments of 120
/// </summary>
public int ScrollWheel => this.MouseState.ScrollWheelValue;
/// <summary>
/// Contains the scroll wheel value from the last update call, in increments of 120
/// </summary>
public int LastScrollWheel => this.LastMouseState.ScrollWheelValue;
/// <summary>
/// Contains the keyboard state from the last update call
/// </summary>
public KeyboardState LastKeyboardState { get; private set; }
/// <summary>
/// Contains the current keyboard state
/// </summary>
public KeyboardState KeyboardState { get; private set; }
private readonly GamePadState[] lastGamepads = new GamePadState[InputHandler.MaximumGamePadCount];
private readonly GamePadState[] gamepads = new GamePadState[InputHandler.MaximumGamePadCount];
private readonly DateTime[] lastGamepadButtonRepeats = new DateTime[InputHandler.MaximumGamePadCount];
private readonly bool[] triggerGamepadButtonRepeat = new bool[InputHandler.MaximumGamePadCount];
private readonly Buttons?[] heldGamepadButtons = new Buttons?[InputHandler.MaximumGamePadCount];
private readonly List<GestureSample> gestures = new List<GestureSample>();
private readonly HashSet<(GenericInput, int)> consumedPresses = new HashSet<(GenericInput, int)>();
private readonly Dictionary<(GenericInput, int), DateTime> inputUpTimes = new Dictionary<(GenericInput, int), DateTime>();
private readonly Dictionary<(GenericInput, int), DateTime> inputDownTimes = new Dictionary<(GenericInput, int), DateTime>();
private readonly Dictionary<(GenericInput, int), DateTime> inputPressedTimes = new Dictionary<(GenericInput, int), DateTime>();
private Point ViewportOffset => new Point(-this.Game.GraphicsDevice.Viewport.X, -this.Game.GraphicsDevice.Viewport.Y);
private Dictionary<(GenericInput, int), DateTime> inputsDownAccum = new Dictionary<(GenericInput, int), DateTime>();
private Dictionary<(GenericInput, int), DateTime> inputsDown = new Dictionary<(GenericInput, int), DateTime>();
private DateTime lastKeyRepeat;
private bool triggerKeyRepeat;
private Keys heldKey;
/// <summary>
/// Creates a new input handler with optional initial values.
/// </summary>
/// <param name="game">The game instance that this input handler belongs to.</param>
/// <param name="handleKeyboard">The initial value for <see cref="HandleKeyboard"/>, which determines whether this input handler handles keyboard inputs.</param>
/// <param name="handleMouse">The initial value for <see cref="HandleMouse"/>, which determines whether this input handler handles mouse inputs.</param>
/// <param name="handleGamepads">The initial value for <see cref="HandleGamepads"/>, which determines whether this input handler handles gamepad inputs.</param>
/// <param name="handleTouch">The initial value for <see cref="HandleTouch"/>, which determines whether this input handler handles touch inputs.</param>
/// <param name="externalGestureHandling">The initial value for <see cref="ExternalGestureHandling"/>, which determines whether gestures will be supplied using <see cref="AddExternalGesture"/> (or this input handler should handle gestures itself).</param>
public InputHandler(Game game, bool handleKeyboard = true, bool handleMouse = true, bool handleGamepads = true, bool handleTouch = true, bool externalGestureHandling = false) : base(game) {
this.HandleKeyboard = handleKeyboard;
this.HandleMouse = handleMouse;
this.HandleGamepads = handleGamepads;
this.HandleTouch = handleTouch;
this.ExternalGestureHandling = externalGestureHandling;
this.Gestures = this.gestures.AsReadOnly();
}
/// <summary>
/// Updates this input handler, querying pressed and released keys and calculating repeat events.
/// Call this in your <see cref="Game.Update"/> method.
/// </summary>
public void Update() {
var now = DateTime.UtcNow;
var active = this.Game.IsActive;
this.consumedPresses.Clear();
this.LastKeyboardState = this.KeyboardState;
if (this.HandleKeyboard) {
this.KeyboardState = active ? Keyboard.GetState() : default;
var pressedKeys = this.KeyboardState.GetPressedKeys();
foreach (var pressed in pressedKeys)
this.AccumulateDown(pressed, -1);
this.triggerKeyRepeat = false;
if (this.HandleKeyboardRepeats) {
// the key that started being held most recently should be the one being repeated
this.heldKey = pressedKeys.OrderBy(k => this.GetDownTime(k)).FirstOrDefault();
if (this.TryGetDownTime(this.heldKey, out var heldTime)) {
// if we've been holding the key longer than the initial delay...
if (heldTime >= this.KeyRepeatDelay) {
var diff = now - this.lastKeyRepeat;
// and we've been holding it for longer than a repeat...
if (diff >= this.KeyRepeatRate) {
this.lastKeyRepeat = now;
// then trigger a repeat, causing IsKeyPressed to be true once
this.triggerKeyRepeat = true;
}
}
}
} else {
this.heldKey = Keys.None;
}
} else {
this.KeyboardState = default;
this.triggerKeyRepeat = false;
this.heldKey = Keys.None;
}
this.LastMouseState = this.MouseState;
if (this.HandleMouse) {
var state = Mouse.GetState();
if (active && this.Game.GraphicsDevice.Viewport.Bounds.Contains(state.X, state.Y)) {
this.MouseState = state;
foreach (var button in MouseExtensions.MouseButtons) {
if (state.GetState(button) == ButtonState.Pressed)
this.AccumulateDown(button, -1);
}
} else {
// mouse position and scroll wheel value should be preserved when the mouse is out of bounds
#if FNA
this.MouseState = new MouseState(state.X, state.Y, state.ScrollWheelValue, 0, 0, 0, 0, 0);
#else
this.MouseState = new MouseState(state.X, state.Y, state.ScrollWheelValue, 0, 0, 0, 0, 0, state.HorizontalScrollWheelValue);
#endif
}
} else {
this.MouseState = default;
}
if (this.HandleGamepads) {
this.ConnectedGamepads = InputHandler.MaximumGamePadCount;
for (var i = 0; i < InputHandler.MaximumGamePadCount; i++) {
this.lastGamepads[i] = this.gamepads[i];
this.gamepads[i] = default;
if (GamePad.GetCapabilities((PlayerIndex) i).IsConnected) {
if (active) {
this.gamepads[i] = GamePad.GetState((PlayerIndex) i);
foreach (var button in InputHandler.AllButtons) {
if (this.IsDown(button, i))
this.AccumulateDown(button, i);
}
}
} else if (this.ConnectedGamepads > i) {
this.ConnectedGamepads = i;
}
}
for (var i = 0; i < this.ConnectedGamepads; i++) {
this.triggerGamepadButtonRepeat[i] = false;
if (this.HandleGamepadRepeats) {
this.heldGamepadButtons[i] = InputHandler.AllButtons
.Where(b => this.IsDown(b, i))
.OrderBy(b => this.GetDownTime(b, i))
.Cast<Buttons?>().FirstOrDefault();
if (this.heldGamepadButtons[i].HasValue && this.TryGetDownTime(this.heldGamepadButtons[i].Value, out var heldTime, i)) {
if (heldTime >= this.KeyRepeatDelay) {
var diff = now - this.lastGamepadButtonRepeats[i];
if (diff >= this.KeyRepeatRate) {
this.lastGamepadButtonRepeats[i] = now;
this.triggerGamepadButtonRepeat[i] = true;
}
}
}
} else {
this.heldGamepadButtons[i] = null;
}
}
} else {
this.ConnectedGamepads = 0;
for (var i = 0; i < InputHandler.MaximumGamePadCount; i++) {
this.lastGamepads[i] = this.gamepads[i];
this.gamepads[i] = default;
this.triggerGamepadButtonRepeat[i] = false;
this.heldGamepadButtons[i] = null;
}
}
this.LastTouchState = this.TouchState;
this.LastViewportTouchState = this.ViewportTouchState;
if (this.HandleTouch) {
this.TouchState = active ? TouchPanel.GetState() : new TouchCollection(InputHandler.EmptyTouchLocations);
if (this.TouchState.Count > 0 && this.ViewportOffset != Point.Zero) {
this.ViewportTouchState = new List<TouchLocation>();
foreach (var touch in this.TouchState) {
touch.TryGetPreviousLocation(out var previous);
var offset = new Vector2(this.ViewportOffset.X, this.ViewportOffset.Y);
this.ViewportTouchState.Add(new TouchLocation(touch.Id, touch.State, touch.Position + offset, previous.State, previous.Position + offset));
}
} else {
this.ViewportTouchState = this.TouchState;
}
// we still want to clear gestures when handling externally to maintain the per-frame gesture system
this.gestures.Clear();
if (active && !this.ExternalGestureHandling) {
while (TouchPanel.IsGestureAvailable)
this.gestures.Add(TouchPanel.ReadGesture());
}
} else {
this.TouchState = new TouchCollection(InputHandler.EmptyTouchLocations);
this.ViewportTouchState = this.TouchState;
this.gestures.Clear();
}
if (this.inputsDownAccum.Count <= 0 && this.inputsDown.Count <= 0) {
this.InputsPressed = InputHandler.EmptyGenericInputs;
this.InputsDown = InputHandler.EmptyGenericInputs;
} else {
// handle pressed inputs
var pressed = new List<GenericInput>();
// if we're inverting press behavior, we need to check the press state for the inputs that were down in the last frame
foreach (var key in (this.InvertPressBehavior ? this.inputsDown : this.inputsDownAccum).Keys) {
if (this.IsPressed(key.Item1, key.Item2)) {
this.inputPressedTimes[key] = DateTime.UtcNow;
pressed.Add(key.Item1);
}
}
this.InputsPressed = pressed.ToArray();
// handle inputs that changed between down and up
foreach (var key in this.inputsDown.Keys) {
if (!this.inputsDownAccum.ContainsKey(key))
this.inputUpTimes[key] = DateTime.UtcNow;
}
foreach (var key in this.inputsDownAccum.Keys) {
if (!this.inputsDown.ContainsKey(key))
this.inputDownTimes[key] = DateTime.UtcNow;
}
// handle inputs that are currently down
this.InputsDown = this.inputsDownAccum.Keys.Select(key => key.Item1).ToArray();
// swapping these collections means that we don't have to keep moving entries between them
(this.inputsDown, this.inputsDownAccum) = (this.inputsDownAccum, this.inputsDown);
this.inputsDownAccum.Clear();
}
}
/// <inheritdoc cref="Update()"/>
public override void Update(GameTime gameTime) {
this.Update();
}
/// <summary>
/// Returns the state of the <c>index</c>th gamepad from the last update call
/// </summary>
/// <param name="index">The zero-based gamepad index</param>
/// <returns>The state of the gamepad last update</returns>
public GamePadState GetLastGamepadState(int index) {
return this.lastGamepads[index];
}
/// <summary>
/// Returns the current state of the <c>index</c>th gamepad
/// </summary>
/// <param name="index">The zero-based gamepad index</param>
/// <returns>The current state of the gamepad</returns>
public GamePadState GetGamepadState(int index) {
return this.gamepads[index];
}
/// <summary>
/// Returns whether the given modifier key is down.
/// </summary>
/// <param name="modifier">The modifier key</param>
/// <returns>If the modifier key is down</returns>
public bool IsModifierKeyDown(ModifierKey modifier) {
foreach (var key in modifier.GetKeys()) {
if (this.IsDown(key))
return true;
}
return false;
}
/// <inheritdoc cref="Microsoft.Xna.Framework.Input.KeyboardState.IsKeyDown"/>
[Obsolete("This method is deprecated. Use the GenericInput version IsDown instead.")]
public bool IsKeyDown(Keys key) {
return this.KeyboardState.IsKeyDown(key);
}
/// <inheritdoc cref="Microsoft.Xna.Framework.Input.KeyboardState.IsKeyUp"/>
[Obsolete("This method is deprecated. Use the GenericInput version IsUp instead.")]
public bool IsKeyUp(Keys key) {
return this.KeyboardState.IsKeyUp(key);
}
/// <inheritdoc cref="Microsoft.Xna.Framework.Input.KeyboardState.IsKeyDown"/>
[Obsolete("This method is deprecated. Use the GenericInput version WasDown instead.")]
public bool WasKeyDown(Keys key) {
return this.LastKeyboardState.IsKeyDown(key);
}
/// <inheritdoc cref="Microsoft.Xna.Framework.Input.KeyboardState.IsKeyUp"/>
[Obsolete("This method is deprecated. Use the GenericInput version WasUp instead.")]
public bool WasKeyUp(Keys key) {
return this.LastKeyboardState.IsKeyUp(key);
}
/// <summary>
/// Returns whether the given key is considered pressed.
/// A key is considered pressed if it was not down the last update call, but is down the current update call. If <see cref="InvertPressBehavior"/> is true, this behavior is inverted.
/// If <see cref="HandleKeyboardRepeats"/> is true, this method will also return true to signify a key repeat.
/// </summary>
/// <param name="key">The key to query</param>
/// <returns>If the key is pressed</returns>
[Obsolete("This method is deprecated. Use the GenericInput version IsPressed instead.")]
public bool IsKeyPressed(Keys key) {
// if the queried key is the held key and a repeat should be triggered, return true
if (this.HandleKeyboardRepeats && key == this.heldKey && this.triggerKeyRepeat)
return true;
return this.IsKeyPressedIgnoreRepeats(key);
}
/// <summary>
/// Returns whether the given key is considered pressed.
/// A key is considered pressed if it was not down the last update call, but is down the current update call. If <see cref="InvertPressBehavior"/> is true, this behavior is inverted.
/// This has the same behavior as <see cref="IsKeyPressed"/>, but ignores keyboard repeat events.
/// If <see cref="HandleKeyboardRepeats"/> is false, this method does the same as <see cref="IsKeyPressed"/>.
/// </summary>
/// <param name="key">The key to query</param>
/// <returns>If the key is pressed</returns>
[Obsolete("This method is deprecated. Use the GenericInput version IsPressedIgnoreRepeats instead.")]
public bool IsKeyPressedIgnoreRepeats(Keys key) {
if (this.InvertPressBehavior)
return this.WasKeyDown(key) && this.IsKeyUp(key);
return this.WasKeyUp(key) && this.IsKeyDown(key);
}
/// <summary>
/// Returns if the given key is considered pressed, and if the press has not been consumed yet using <see cref="TryConsumeKeyPressed"/>.
/// </summary>
/// <param name="key">The key to query.</param>
/// <returns>If the key is pressed and the press is not consumed yet.</returns>
[Obsolete("This method is deprecated. Use the GenericInput version IsPressedAvailable instead.")]
public bool IsKeyPressedAvailable(Keys key) {
return this.IsKeyPressed(key) && !this.IsPressConsumed(key);
}
/// <summary>
/// Returns whether the given key is considered pressed, and marks the press as consumed if it is.
/// A key is considered pressed if it was not down the last update call, but is down the current update call.
/// A key press is considered consumed if this method has already returned true previously since the last <see cref="Update()"/> call.
/// If <see cref="HandleKeyboardRepeats"/> is true, this method will also return true to signify a key repeat.
/// </summary>
/// <param name="key">The key to query.</param>
/// <returns>If the key is pressed and the press is not consumed yet.</returns>
[Obsolete("This method is deprecated. Use the GenericInput version TryConsumePressed instead.")]
public bool TryConsumeKeyPressed(Keys key) {
if (this.IsKeyPressedAvailable(key)) {
this.consumedPresses.Add((key, -1));
return true;
}
return false;
}
/// <summary>
/// Returns whether the given mouse button is currently down.
/// </summary>
/// <param name="button">The button to query</param>
/// <returns>Whether or not the queried button is down</returns>
[Obsolete("This method is deprecated. Use the GenericInput version IsDown instead.")]
public bool IsMouseButtonDown(MouseButton button) {
return this.MouseState.GetState(button) == ButtonState.Pressed;
}
/// <summary>
/// Returns whether the given mouse button is currently up.
/// </summary>
/// <param name="button">The button to query</param>
/// <returns>Whether or not the queried button is up</returns>
[Obsolete("This method is deprecated. Use the GenericInput version IsUp instead.")]
public bool IsMouseButtonUp(MouseButton button) {
return this.MouseState.GetState(button) == ButtonState.Released;
}
/// <summary>
/// Returns whether the given mouse button was down the last update call.
/// </summary>
/// <param name="button">The button to query</param>
/// <returns>Whether or not the queried button was down</returns>
[Obsolete("This method is deprecated. Use the GenericInput version WasDown instead.")]
public bool WasMouseButtonDown(MouseButton button) {
return this.LastMouseState.GetState(button) == ButtonState.Pressed;
}
/// <summary>
/// Returns whether the given mouse button was up the last update call.
/// </summary>
/// <param name="button">The button to query</param>
/// <returns>Whether or not the queried button was up</returns>
[Obsolete("This method is deprecated. Use the GenericInput version WasUp instead.")]
public bool WasMouseButtonUp(MouseButton button) {
return this.LastMouseState.GetState(button) == ButtonState.Released;
}
/// <summary>
/// Returns whether the given mouse button is considered pressed.
/// A mouse button is considered pressed if it was up the last update call, and is down the current update call. If <see cref="InvertPressBehavior"/> is true, this behavior is inverted.
/// </summary>
/// <param name="button">The button to query</param>
/// <returns>Whether the button is pressed</returns>
[Obsolete("This method is deprecated. Use the GenericInput version IsPressed instead.")]
public bool IsMouseButtonPressed(MouseButton button) {
if (this.InvertPressBehavior)
return this.WasMouseButtonDown(button) && this.IsMouseButtonUp(button);
return this.WasMouseButtonUp(button) && this.IsMouseButtonDown(button);
}
/// <summary>
/// Returns if the given mouse button is considered pressed, and if the press has not been consumed yet using <see cref="TryConsumeMouseButtonPressed"/>.
/// </summary>
/// <param name="button">The button to query.</param>
/// <returns>If the button is pressed and the press is not consumed yet.</returns>
[Obsolete("This method is deprecated. Use the GenericInput version IsPressedAvailable instead.")]
public bool IsMouseButtonPressedAvailable(MouseButton button) {
return this.IsMouseButtonPressed(button) && !this.IsPressConsumed(button);
}
/// <summary>
/// Returns whether the given mouse button is considered pressed, and marks the press as consumed if it is.
/// A mouse button is considered pressed if it was up the last update call, and is down the current update call.
/// A mouse button press is considered consumed if this method has already returned true previously since the last <see cref="Update()"/> call.
/// </summary>
/// <param name="button">The button to query.</param>
/// <returns>If the button is pressed and the press is not consumed yet.</returns>
[Obsolete("This method is deprecated. Use the GenericInput version TryConsumePressed instead.")]
public bool TryConsumeMouseButtonPressed(MouseButton button) {
if (this.IsMouseButtonPressedAvailable(button)) {
this.consumedPresses.Add((button, -1));
return true;
}
return false;
}
/// <inheritdoc cref="GamePadState.IsButtonDown"/>
[Obsolete("This method is deprecated. Use the GenericInput version IsDown instead.")]
public bool IsGamepadButtonDown(Buttons button, int index = -1) {
if (index < 0) {
for (var i = 0; i < this.ConnectedGamepads; i++) {
if (this.GetGamepadState(i).GetAnalogValue(button) > this.GamepadButtonDeadzone)
return true;
}
return false;
}
return this.GetGamepadState(index).GetAnalogValue(button) > this.GamepadButtonDeadzone;
}
/// <inheritdoc cref="GamePadState.IsButtonUp"/>
[Obsolete("This method is deprecated. Use the GenericInput version IsUp instead.")]
public bool IsGamepadButtonUp(Buttons button, int index = -1) {
if (index < 0) {
for (var i = 0; i < this.ConnectedGamepads; i++) {
if (this.GetGamepadState(i).GetAnalogValue(button) <= this.GamepadButtonDeadzone)
return true;
}
return false;
}
return this.GetGamepadState(index).GetAnalogValue(button) <= this.GamepadButtonDeadzone;
}
/// <inheritdoc cref="GamePadState.IsButtonDown"/>
[Obsolete("This method is deprecated. Use the GenericInput version WasDown instead.")]
public bool WasGamepadButtonDown(Buttons button, int index = -1) {
if (index < 0) {
for (var i = 0; i < this.ConnectedGamepads; i++) {
if (this.GetLastGamepadState(i).GetAnalogValue(button) > this.GamepadButtonDeadzone)
return true;
}
return false;
}
return this.GetLastGamepadState(index).GetAnalogValue(button) > this.GamepadButtonDeadzone;
}
/// <inheritdoc cref="GamePadState.IsButtonUp"/>
[Obsolete("This method is deprecated. Use the GenericInput version WasUp instead.")]
public bool WasGamepadButtonUp(Buttons button, int index = -1) {
if (index < 0) {
for (var i = 0; i < this.ConnectedGamepads; i++) {
if (this.GetLastGamepadState(i).GetAnalogValue(button) <= this.GamepadButtonDeadzone)
return true;
}
return false;
}
return this.GetLastGamepadState(index).GetAnalogValue(button) <= this.GamepadButtonDeadzone;
}
/// <summary>
/// Returns whether the given gamepad button on the given index is considered pressed.
/// A gamepad button is considered pressed if it was down the last update call, and is up the current update call. If <see cref="InvertPressBehavior"/> is true, this behavior is inverted.
/// If <see cref="HandleGamepadRepeats"/> is true, this method will also return true to signify a gamepad button repeat.
/// </summary>
/// <param name="button">The button to query</param>
/// <param name="index">The zero-based index of the gamepad, or -1 for any gamepad</param>
/// <returns>Whether the given button is pressed</returns>
[Obsolete("This method is deprecated. Use the GenericInput version IsPressed instead.")]
public bool IsGamepadButtonPressed(Buttons button, int index = -1) {
if (this.HandleGamepadRepeats) {
if (index < 0) {
for (var i = 0; i < this.ConnectedGamepads; i++) {
if (this.heldGamepadButtons[i] == button && this.triggerGamepadButtonRepeat[i])
return true;
}
} else if (this.heldGamepadButtons[index] == button && this.triggerGamepadButtonRepeat[index]) {
return true;
}
}
return this.IsGamepadButtonPressedIgnoreRepeats(button, index);
}
/// <summary>
/// Returns whether the given key is considered pressed.
/// A gamepad button is considered pressed if it was down the last update call, and is up the current update call. If <see cref="InvertPressBehavior"/> is true, this behavior is inverted.
/// This has the same behavior as <see cref="IsGamepadButtonPressed"/>, but ignores gamepad repeat events.
/// If <see cref="HandleGamepadRepeats"/> is false, this method does the same as <see cref="IsGamepadButtonPressed"/>.
/// </summary>
/// <param name="button">The button to query</param>
/// <param name="index">The zero-based index of the gamepad, or -1 for any gamepad</param>
/// <returns>Whether the given button is pressed</returns>
[Obsolete("This method is deprecated. Use the GenericInput version IsPressedIgnoreRepeats instead.")]
public bool IsGamepadButtonPressedIgnoreRepeats(Buttons button, int index = -1) {
if (this.InvertPressBehavior)
return this.WasGamepadButtonDown(button, index) && this.IsGamepadButtonUp(button, index);
return this.WasGamepadButtonUp(button, index) && this.IsGamepadButtonDown(button, index);
}
/// <summary>
/// Returns if the given gamepad button is considered pressed, and if the press has not been consumed yet using <see cref="TryConsumeMouseButtonPressed"/>.
/// </summary>
/// <param name="button">The button to query.</param>
/// <param name="index">The zero-based index of the gamepad, or -1 for any gamepad.</param>
/// <returns>Whether the given button is pressed and the press is not consumed yet.</returns>
[Obsolete("This method is deprecated. Use the GenericInput version IsPressedAvailable instead.")]
public bool IsGamepadButtonPressedAvailable(Buttons button, int index = -1) {
return this.IsGamepadButtonPressed(button) && !this.IsPressConsumed(button, index) && (index < 0 || !this.IsPressConsumed(button));
}
/// <summary>
/// Returns whether the given gamepad button on the given index is considered pressed, and marks the press as consumed if it is.
/// A gamepad button is considered pressed if it was down the last update call, and is up the current update call.
/// A gamepad button press is considered consumed if this method has already returned true previously since the last <see cref="Update()"/> call.
/// If <see cref="HandleGamepadRepeats"/> is true, this method will also return true to signify a gamepad button repeat.
/// </summary>
/// <param name="button">The button to query.</param>
/// <param name="index">The zero-based index of the gamepad, or -1 for any gamepad.</param>
/// <returns>Whether the given button is pressed and the press is not consumed yet.</returns>
[Obsolete("This method is deprecated. Use the GenericInput version TryConsumePressed instead.")]
public bool TryConsumeGamepadButtonPressed(Buttons button, int index = -1) {
if (this.IsGamepadButtonPressedAvailable(button, index)) {
this.consumedPresses.Add((button, index));
return true;
}
return false;
}
/// <summary>
/// Queries for a gesture of a given type that finished during the current update call.
/// </summary>
/// <param name="type">The type of gesture to query for</param>
/// <param name="sample">The resulting gesture sample, or default if there isn't one</param>
/// <returns>True if a gesture of the type was found, otherwise false</returns>
public bool GetGesture(GestureType type, out GestureSample sample) {
foreach (var gesture in this.Gestures) {
if (type.HasFlag(gesture.GestureType)) {
sample = gesture;
return true;
}
}
sample = default;
return false;
}
/// <summary>
/// Queries for a gesture of the given type that finished during the current update call.
/// Unlike <see cref="GetGesture"/>, the return value of this method takes the <see cref="GraphicsDevice.Viewport"/> into account.
/// </summary>
/// <param name="type">The type of gesture to query for</param>
/// <param name="sample">The resulting gesture sample with the <see cref="GraphicsDevice.Viewport"/> taken into account, or default if there isn't one</param>
/// <returns>True if a gesture of the type was found, otherwise false</returns>
public bool GetViewportGesture(GestureType type, out GestureSample sample) {
if (this.GetGesture(type, out var original)) {
var offset = new Vector2(this.ViewportOffset.X, this.ViewportOffset.Y);
sample = new GestureSample(original.GestureType, original.Timestamp, original.Position + offset, original.Position2 + offset, original.Delta, original.Delta2);
return true;
}
sample = default;
return false;
}
/// <summary>
/// Adds a gesture to the <see cref="Gestures"/> collection and allows it to be queried using <see cref="GetGesture"/> and <see cref="GetViewportGesture"/> for the duration of the update frame that it was added on.
/// This method should be used when <see cref="ExternalGestureHandling"/> is set to true, but <see cref="GetGesture"/> and <see cref="GetViewportGesture"/> should still be available.
/// For more info, see https://mlem.ellpeck.de/articles/input.html#external-gesture-handling.
/// </summary>
/// <param name="sample">The gesture sample to add.</param>
/// <exception cref="InvalidOperationException">Thrown if <see cref="ExternalGestureHandling"/> is false.</exception>
public void AddExternalGesture(GestureSample sample) {
if (!this.ExternalGestureHandling)
throw new InvalidOperationException($"Cannot add external gestures if {nameof(this.ExternalGestureHandling)} is false");
this.gestures.Add(sample);
}
/// <summary>
/// Returns if a given control of any kind is down.
/// This is a helper function that can be passed a <see cref="Keys"/>, <see cref="Buttons"/> or <see cref="MouseButton"/>.
/// </summary>
/// <param name="control">The control whose down state to query</param>
/// <param name="index">The index of the gamepad to query (if applicable), or -1 for any gamepad</param>
/// <returns>Whether the given control is down</returns>
public bool IsDown(GenericInput control, int index = -1) {
switch (control.Type) {
case InputType.Keyboard:
return this.KeyboardState.IsKeyDown(control);
case InputType.Gamepad:
if (index < 0) {
for (var i = 0; i < this.ConnectedGamepads; i++) {
if (this.GetGamepadState(i).GetAnalogValue(control) > this.GamepadButtonDeadzone)
return true;
}
return false;
}
return this.GetGamepadState(index).GetAnalogValue(control) > this.GamepadButtonDeadzone;
case InputType.Mouse:
return this.MouseState.GetState(control) == ButtonState.Pressed;
default:
return false;
}
}
/// <summary>
/// Returns if a given control of any kind is up.
/// This is a helper function that can be passed a <see cref="Keys"/>, <see cref="Buttons"/> or <see cref="MouseButton"/>.
/// </summary>
/// <param name="control">The control whose up state to query</param>
/// <param name="index">The index of the gamepad to query (if applicable), or -1 for any gamepad</param>
/// <returns>Whether the given control is up.</returns>
public bool IsUp(GenericInput control, int index = -1) {
switch (control.Type) {
case InputType.Keyboard:
return this.KeyboardState.IsKeyUp(control);
case InputType.Gamepad:
if (index < 0) {
for (var i = 0; i < this.ConnectedGamepads; i++) {
if (this.GetGamepadState(i).GetAnalogValue(control) <= this.GamepadButtonDeadzone)
return true;
}
return false;
}
return this.GetGamepadState(index).GetAnalogValue(control) <= this.GamepadButtonDeadzone;
case InputType.Mouse:
return this.MouseState.GetState(control) == ButtonState.Released;
default:
return true;
}
}
/// <summary>
/// Returns if a given control of any kind was down in the last update call.
/// This is a helper function that can be passed a <see cref="Keys"/>, <see cref="Buttons"/> or <see cref="MouseButton"/>.
/// </summary>
/// <param name="control">The control whose down state to query</param>
/// <param name="index">The index of the gamepad to query (if applicable), or -1 for any gamepad</param>
/// <returns>Whether the given control was down</returns>
public bool WasDown(GenericInput control, int index = -1) {
switch (control.Type) {
case InputType.Keyboard:
return this.LastKeyboardState.IsKeyDown(control);
case InputType.Gamepad:
if (index < 0) {
for (var i = 0; i < this.ConnectedGamepads; i++) {
if (this.GetLastGamepadState(i).GetAnalogValue(control) > this.GamepadButtonDeadzone)
return true;
}
return false;
}
return this.GetLastGamepadState(index).GetAnalogValue(control) > this.GamepadButtonDeadzone;
case InputType.Mouse:
return this.LastMouseState.GetState(control) == ButtonState.Pressed;
default:
return false;
}
}
/// <summary>
/// Returns if a given control of any kind was up in the last update call.
/// This is a helper function that can be passed a <see cref="Keys"/>, <see cref="Buttons"/> or <see cref="MouseButton"/>.
/// </summary>
/// <param name="control">The control whose up state to query</param>
/// <param name="index">The index of the gamepad to query (if applicable), or -1 for any gamepad</param>
/// <returns>Whether the given control was up.</returns>
public bool WasUp(GenericInput control, int index = -1) {
switch (control.Type) {
case InputType.Keyboard:
return this.LastKeyboardState.IsKeyUp(control);
case InputType.Gamepad:
if (index < 0) {
for (var i = 0; i < this.ConnectedGamepads; i++) {
if (this.GetLastGamepadState(i).GetAnalogValue(control) <= this.GamepadButtonDeadzone)
return true;
}
return false;
}
return this.GetLastGamepadState(index).GetAnalogValue(control) <= this.GamepadButtonDeadzone;
case InputType.Mouse:
return this.LastMouseState.GetState(control) == ButtonState.Released;
default:
return true;
}
}
/// <summary>
/// Returns if a given control of any kind is pressed.
/// If <see cref="HandleKeyboardRepeats"/> or <see cref="HandleGamepadRepeats"/> are true, this method will also return true to signify a key or gamepad button repeat.
/// An input is considered pressed if it was not down the last update call, but is down the current update call. If <see cref="InvertPressBehavior"/> is true, this behavior is inverted.
/// </summary>
/// <param name="control">The control whose pressed state to query</param>
/// <param name="index">The index of the gamepad to query (if applicable), or -1 for any gamepad</param>
/// <returns>Whether the given control is pressed.</returns>
public bool IsPressed(GenericInput control, int index = -1) {
// handle repeat events for specific inputs, and delegate to default "ignore repeats" behavior otherwise
switch (control.Type) {
case InputType.Keyboard:
if (this.HandleKeyboardRepeats && (Keys) control == this.heldKey && this.triggerKeyRepeat)
return true;
break;
case InputType.Gamepad:
if (this.HandleGamepadRepeats) {
if (index < 0) {
for (var i = 0; i < this.ConnectedGamepads; i++) {
if (this.heldGamepadButtons[i] == (Buttons) control && this.triggerGamepadButtonRepeat[i])
return true;
}
} else if (this.heldGamepadButtons[index] == (Buttons) control && this.triggerGamepadButtonRepeat[index]) {
return true;
}
}
break;
}
return this.IsPressedIgnoreRepeats(control, index);
}
/// <summary>
/// An input is considered pressed if it was not down the last update call, but is down the current update call. If <see cref="InvertPressBehavior"/> is true, this behavior is inverted.
/// This has the same behavior as <see cref="IsPressed"/>, but ignores keyboard and gamepad repeat events.
/// If <see cref="HandleKeyboardRepeats"/> and <see cref="HandleGamepadRepeats"/> are false, this method does the same as <see cref="IsPressed"/>.
/// </summary>
/// <param name="control">The control whose pressed state to query</param>
/// <param name="index">The index of the gamepad to query (if applicable), or -1 for any gamepad</param>
/// <returns>Whether the given control is pressed, ignoring repeat events.</returns>
public bool IsPressedIgnoreRepeats(GenericInput control, int index = -1) {
if (this.InvertPressBehavior)
return this.WasDown(control, index) && this.IsUp(control, index);
return this.WasUp(control, index) && this.IsDown(control, index);
}
/// <summary>
/// Returns if a given control of any kind is pressed, and if the press has not been consumed yet using <see cref="TryConsumePressed"/>.
/// </summary>
/// <param name="control">The control whose pressed state to query.</param>
/// <param name="index">The index of the gamepad to query (if applicable), or -1 for any gamepad.</param>
/// <returns>Whether the given control is pressed and the press is not consumed yet.</returns>
public bool IsPressedAvailable(GenericInput control, int index = -1) {
return this.IsPressed(control, index) && !this.IsPressConsumed(control, index);
}
/// <summary>
/// Returns if a given control of any kind is pressed and available, and marks the press as consumed if it is.
/// This is a helper function that can be passed a <see cref="Keys"/>, <see cref="Buttons"/> or <see cref="MouseButton"/>.
/// </summary>
/// <param name="control">The control whose pressed state to query.</param>
/// <param name="index">The index of the gamepad to query (if applicable), or -1 for any gamepad.</param>
/// <returns>Whether the given control is pressed and the press is not consumed yet.</returns>
public bool TryConsumePressed(GenericInput control, int index = -1) {
if (this.IsPressedAvailable(control, index)) {
this.consumedPresses.Add((control, index));
return true;
}
return false;
}
/// <summary>
/// Returns if a given control of any kind was just let go this frame, and had been down for less than the given <paramref name="time"/> before that. Essentially, this action signifies a short press action.
/// </summary>
/// <param name="control">The control whose pressed state to query.</param>
/// <param name="time">The maximum time that the control should have been down for.</param>
/// <param name="index">The index of the gamepad to query (if applicable), or -1 for any gamepad.</param>
/// <returns>Whether the given control was pressed for less than the given time.</returns>
public bool WasPressedForLess(GenericInput control, TimeSpan time, int index = -1) {
return this.WasDown(control, index) && this.IsUp(control, index) && this.GetDownTime(control, index) < time;
}
/// <summary>
/// Returns if a given control of any kind was just let go this frame, and had been down for less than the given <paramref name="time"/> before that, and if the press has not been consumed yet using <see cref="TryConsumePressedForLess"/>. Essentially, this action signifies a short press action.
/// </summary>
/// <param name="control">The control whose pressed state to query.</param>
/// <param name="time">The maximum time that the control should have been down for.</param>
/// <param name="index">The index of the gamepad to query (if applicable), or -1 for any gamepad.</param>
/// <returns>Whether the given control was pressed for less than the given time, and the press has not been consumed yet.</returns>
public bool WasPressedForLessAvailable(GenericInput control, TimeSpan time, int index = -1) {
return this.WasPressedForLess(control, time, index) && !this.IsPressConsumed(control, index);
}
/// <summary>
/// Returns if a given control of any kind was just let go this frame, and had been down for less than the given <paramref name="time"/> before that, and if the press has not been consumed yet using <see cref="TryConsumePressedForLess"/>, and marks the press as consumed if it is. Essentially, this action signifies a short press action.
/// </summary>
/// <param name="control">The control whose pressed state to query.</param>
/// <param name="time">The maximum time that the control should have been down for.</param>
/// <param name="index">The index of the gamepad to query (if applicable), or -1 for any gamepad.</param>
/// <returns>Whether the given control was pressed for less than the given time, and the press was successfully consumed.</returns>
public bool TryConsumePressedForLess(GenericInput control, TimeSpan time, int index = -1) {
if (this.WasPressedForLessAvailable(control, time, index)) {
this.consumedPresses.Add((control, index));
return true;
}
return false;
}
/// <inheritdoc cref="IsDown"/>
public bool IsAnyDown(params GenericInput[] controls) {
foreach (var control in controls) {
if (this.IsDown(control))
return true;
}
return false;
}
/// <inheritdoc cref="IsUp"/>
public bool IsAnyUp(params GenericInput[] controls) {
foreach (var control in controls) {
if (this.IsUp(control))
return true;
}
return false;
}
/// <inheritdoc cref="IsPressed"/>
public bool IsAnyPressed(params GenericInput[] controls) {
foreach (var control in controls) {
if (this.IsPressed(control))
return true;
}
return false;
}
/// <inheritdoc cref="IsPressedAvailable"/>
public bool IsAnyPressedAvailable(params GenericInput[] controls) {
foreach (var control in controls) {
if (this.IsPressedAvailable(control))
return true;
}
return false;
}
/// <summary>
/// Tries to retrieve the amount of time that a given <see cref="GenericInput"/> has been held down for.
/// If the input is currently down or has been down previously, this method returns true and the amount of time that it has currently or last been down for is stored in <paramref name="downTime"/>.
/// </summary>
/// <param name="input">The input whose down time to query.</param>