Table of Contents

Struct KeyCombination

Namespace
Gym.Envs
Assembly
Gym.dll

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

codes int[]

The key codes; copied, so the caller may reuse the array.

Exceptions

ArgumentNullException

Thrown when codes is null.

Properties

Count

How many keys the combination holds.

public int Count { get; }

Property Value

int

this[int]

The code at index.

public int this[int index] { get; }

Parameters

index int

The 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

KeyCombination

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

other KeyCombination

The other combination.

Returns

bool

true for the same codes in order.

Equals(object?)

Equal to another combination with the same codes in the same order.

public override bool Equals(object? obj)

Parameters

obj object

The other value.

Returns

bool

true for an equal combination.

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

keys string

The characters.

Returns

KeyCombination

The combination.

Exceptions

ArgumentNullException

Thrown when keys is 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

left KeyCombination

One combination.

right KeyCombination

The other.

Returns

bool

true when they are equal.

operator !=(KeyCombination, KeyCombination)

Whether two combinations differ.

public static bool operator !=(KeyCombination left, KeyCombination right)

Parameters

left KeyCombination

One combination.

right KeyCombination

The other.

Returns

bool

true when they are not equal.