Struct KeyCombination
Keys pressed together, as key codes: the key of a keyboard mapping (GetKeysToAction()),
Python's tuple of ints such as MountainCar's (275, 276). A code is an SDL keycode, which for a printable
key is Python's ord of its character (97 for a), so a mapping written with characters
({"wa": 1}, which play also accepts) becomes FromText(string)'s codes.
public readonly struct KeyCombination : IEquatable<KeyCombination>, ITuple, IReadOnlyList<int>, IReadOnlyCollection<int>, IEnumerable<int>, IEnumerable
- Implements
- Inherited Members
- Extension Methods
Remarks
The codes keep the order given, as a Python tuple does, and equality compares them in that order; play sorts
the codes of every key when it looks a held set up, so the order never changes which action fires. The default
value is the empty combination (), nothing pressed (None).
An ITuple, so every tuple reader in Gym.NET (play's key handling, Python's repr, the
parity harness) reads it as the tuple it stands for. Immutable: the codes are copied in.
Constructors
KeyCombination(params int[])
The combination of codes, in the order given.
public KeyCombination(params int[] codes)
Parameters
codesint[]The key codes; copied, so the caller may reuse the array.
Exceptions
- ArgumentNullException
Thrown when
codesis null.
Properties
Count
How many keys the combination holds.
public int Count { get; }
Property Value
this[int]
The code at index.
public int this[int index] { get; }
Parameters
indexintThe position.
Property Value
- int
The key code.
Exceptions
- IndexOutOfRangeException
Thrown for a position outside the combination.
None
The empty combination (): nothing pressed.
public static KeyCombination None { get; }
Property Value
Methods
Equals(KeyCombination)
Equal when both hold the same codes in the same order, as Python's tuples compare.
public bool Equals(KeyCombination other)
Parameters
otherKeyCombinationThe other combination.
Returns
Equals(object?)
Equal to another combination with the same codes in the same order.
public override bool Equals(object? obj)
Parameters
objobjectThe other value.
Returns
FromText(string)
The combination of a text's characters, one code each (Python's tuple(ord(c) for c in keys), what
play makes of a string key): FromText("wa") is (119, 97). A surrogate pair is one character.
public static KeyCombination FromText(string keys)
Parameters
keysstringThe characters.
Returns
- KeyCombination
The combination.
Exceptions
- ArgumentNullException
Thrown when
keysis null.
GetEnumerator()
The codes in order.
public IEnumerator<int> GetEnumerator()
Returns
- IEnumerator<int>
An enumerator over the codes.
GetHashCode()
A hash of the codes in order, equal for equal combinations.
public override int GetHashCode()
Returns
- int
The hash.
ToString()
Python's repr of the tuple: (), (276,), (275, 276).
public override string ToString()
Returns
- string
The text.
Operators
operator ==(KeyCombination, KeyCombination)
Whether two combinations hold the same codes in the same order.
public static bool operator ==(KeyCombination left, KeyCombination right)
Parameters
leftKeyCombinationOne combination.
rightKeyCombinationThe other.
Returns
operator !=(KeyCombination, KeyCombination)
Whether two combinations differ.
public static bool operator !=(KeyCombination left, KeyCombination right)
Parameters
leftKeyCombinationOne combination.
rightKeyCombinationThe other.