Class Keybind
A keybind represents a generic way to trigger input. A keybind is made up of multiple key combinations, one of which has to be pressed for the keybind to be triggered. Note that this type is serializable using DataContractAttribute. Note that this class implements IComparable and IComparable<T>, which allows two combinations to be ordered based on how many Modifiers their combinations have.
[DataContract]
public class Keybind : IComparable<Keybind>, IComparable
- Inheritance
-
Keybind
- Implements
- Inherited Members
Constructors
Keybind()
Creates a new keybind with no default combinations
public Keybind()
Keybind(GenericInput, params GenericInput[])
Creates a new keybind and adds the given key and modifiers using Add(GenericInput, params GenericInput[])
public Keybind(GenericInput key, params GenericInput[] modifiers)
Parameters
key
GenericInputThe key to be pressed.
modifiers
GenericInput[]The modifier keys that have to be held down.
Keybind(GenericInput, ModifierKey)
Creates a new keybind and adds the given key and modifiers using Add(GenericInput, params GenericInput[])
public Keybind(GenericInput key, ModifierKey modifier)
Parameters
key
GenericInputThe key to be pressed.
modifier
ModifierKey
Keybind(params Combination[])
Creates a new keybind with the given combinations
.
public Keybind(params Keybind.Combination[] combinations)
Parameters
combinations
Combination[]The combinations to initialize this keybind with.
Properties
Combinations
The combinations that make up this keybind. This collection can be modified using Add(GenericInput, params GenericInput[]), Remove(Func<Combination, int, bool>), Clear(), CopyFrom(Keybind), etc.
[DataMember]
public Keybind.Combination[] Combinations { get; }
Property Value
Methods
Add(GenericInput, params GenericInput[])
Adds a new key combination to this keybind that can optionally be pressed for the keybind to trigger.
public Keybind Add(GenericInput key, params GenericInput[] modifiers)
Parameters
key
GenericInputThe key to be pressed.
modifiers
GenericInput[]The modifier keys that have to be held down.
Returns
- Keybind
This keybind, for chaining
Add(GenericInput, ModifierKey)
Adds a new key combination to this keybind that can optionally be pressed for the keybind to trigger.
public Keybind Add(GenericInput key, ModifierKey modifier)
Parameters
key
GenericInputThe key to be pressed.
modifier
ModifierKey
Returns
- Keybind
This keybind, for chaining
Add(Combination)
Adds the given Keybind.Combination to this keybind that can optionally be pressed for the keybind to trigger.
public Keybind Add(Keybind.Combination combination)
Parameters
combination
Keybind.CombinationThe combination to add.
Returns
- Keybind
This keybind, for chaining
Clear()
Clears this keybind, removing all active combinations.
public Keybind Clear()
Returns
- Keybind
This keybind, for chaining
CompareTo(Keybind)
Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
public int CompareTo(Keybind other)
Parameters
other
KeybindAn object to compare with this instance.
Returns
- int
A value that indicates the relative order of the objects being compared. The return value has these meanings:
<table><thead><tr><th class="term"> Value</th><th class="description"> Meaning</th></tr></thead><tbody><tr><td class="term"> Less than zero</td><td class="description"> This instance precedes <code class="paramref">other</code> in the sort order.</td></tr><tr><td class="term"> Zero</td><td class="description"> This instance occurs in the same position in the sort order as <code class="paramref">other</code>.</td></tr><tr><td class="term"> Greater than zero</td><td class="description"> This instance follows <code class="paramref">other</code> in the sort order.</td></tr></tbody></table>
CompareTo(object)
Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
public int CompareTo(object obj)
Parameters
obj
objectAn object to compare with this instance.
Returns
- int
A value that indicates the relative order of the objects being compared. The return value has these meanings:
<table><thead><tr><th class="term"> Value</th><th class="description"> Meaning</th></tr></thead><tbody><tr><td class="term"> Less than zero</td><td class="description"> This instance precedes <code class="paramref">obj</code> in the sort order.</td></tr><tr><td class="term"> Zero</td><td class="description"> This instance occurs in the same position in the sort order as <code class="paramref">obj</code>.</td></tr><tr><td class="term"> Greater than zero</td><td class="description"> This instance follows <code class="paramref">obj</code> in the sort order.</td></tr></tbody></table>
Exceptions
- ArgumentException
obj
is not the same type as this instance.
CopyFrom(Keybind)
Copies all of the combinations from the given keybind into this keybind. Note that this doesn't Clear() this keybind, so combinations will be merged rather than replaced.
public Keybind CopyFrom(Keybind other)
Parameters
other
KeybindThe keybind to copy from
Returns
- Keybind
This keybind, for chaining
GetCombinations()
Returns an enumerable of all of the combinations that this keybind currently contains
public IEnumerable<Keybind.Combination> GetCombinations()
Returns
- IEnumerable<Keybind.Combination>
This keybind's combinations
Insert(int, GenericInput, params GenericInput[])
Inserts a new key combination into the given index
of this keybind's combinations that can optionally be pressed for the keybind to trigger.
public Keybind Insert(int index, GenericInput key, params GenericInput[] modifiers)
Parameters
index
intThe index to insert this combination into.
key
GenericInputThe key to be pressed.
modifiers
GenericInput[]The modifier keys that have to be held down.
Returns
- Keybind
This keybind, for chaining.
Insert(int, GenericInput, ModifierKey)
Inserts a new key combination into the given index
of this keybind's combinations that can optionally be pressed for the keybind to trigger.
public Keybind Insert(int index, GenericInput key, ModifierKey modifier)
Parameters
index
intThe index to insert this combination into.
key
GenericInputThe key to be pressed.
modifier
ModifierKey
Returns
- Keybind
This keybind, for chaining.
Insert(int, Combination)
Inserts the given Keybind.Combination into the given index
of this keybind's combinations that can optionally be pressed for the keybind to trigger.
public Keybind Insert(int index, Keybind.Combination combination)
Parameters
index
intThe index to insert this combination into.
combination
Keybind.CombinationThe combination to insert.
Returns
- Keybind
This keybind, for chaining.
IsDown(InputHandler, int)
Returns whether this keybind is considered to be down. See IsDown(GenericInput, int) for more information.
public bool IsDown(InputHandler handler, int gamepadIndex = -1)
Parameters
handler
InputHandlerThe input handler to query the keys with
gamepadIndex
intThe index of the gamepad to query, or -1 to query all gamepads
Returns
- bool
Whether this keybind is considered to be down
IsModifierDown(InputHandler, int)
Returns whether any of this keybind's modifier keys are currently down. See IsDown(GenericInput, int) for more information.
public bool IsModifierDown(InputHandler handler, int gamepadIndex = -1)
Parameters
handler
InputHandlerThe input handler to query the keys with
gamepadIndex
intThe index of the gamepad to query, or -1 to query all gamepads
Returns
- bool
Whether any of this keyboard's modifier keys are down
IsPressed(InputHandler, int)
Returns whether this keybind is considered to be pressed. See IsPressed(GenericInput, int) for more information.
public bool IsPressed(InputHandler handler, int gamepadIndex = -1)
Parameters
handler
InputHandlerThe input handler to query the keys with
gamepadIndex
intThe index of the gamepad to query, or -1 to query all gamepads
Returns
- bool
Whether this keybind is considered to be pressed
IsPressedAvailable(InputHandler, int)
Returns whether this keybind is considered to be pressed and has not been consumed yet usingTryConsumePressed(InputHandler, int). See IsPressedAvailable(GenericInput, int) for more information.
public bool IsPressedAvailable(InputHandler handler, int gamepadIndex = -1)
Parameters
handler
InputHandlerThe input handler to query the keys with
gamepadIndex
intThe index of the gamepad to query, or -1 to query all gamepads
Returns
- bool
Whether this keybind is considered to be pressed
Remove(Func<Combination, int, bool>)
Removes all combinations that match the given predicate
public Keybind Remove(Func<Keybind.Combination, int, bool> predicate)
Parameters
predicate
Func<Keybind.Combination, int, bool>The predicate to match against
Returns
- Keybind
This keybind, for chaining
ToString()
Converts this keybind into a string, separating every included Keybind.Combination by a comma
public override string ToString()
Returns
- string
This keybind as a string
ToString(string, string, Func<GenericInput, string>)
Converts this keybind into an easily human-readable string.
When using ToString(), this method is used with joiner
set to ", ".
public string ToString(string joiner, string combinationJoiner = " + ", Func<GenericInput, string> inputName = null)
Parameters
joiner
stringThe string to use to join combinations
combinationJoiner
stringThe string to use for combination-internal joining, see ToString(string, Func<GenericInput, string>)
inputName
Func<GenericInput, string>The function to use for determining the display name of generic inputs, see ToString(string, Func<GenericInput, string>)
Returns
- string
A human-readable string representing this keybind
TryConsumePressed(InputHandler, int)
Returns whether this keybind is considered to be pressed. See TryConsumePressed(GenericInput, int) for more information.
public bool TryConsumePressed(InputHandler handler, int gamepadIndex = -1)
Parameters
handler
InputHandlerThe input handler to query the keys with
gamepadIndex
intThe index of the gamepad to query, or -1 to query all gamepads
Returns
- bool
Whether this keybind is considered to be pressed
TryGetCombination(int, out Combination)
Tries to retrieve the combination at the given index
within this keybind.
public bool TryGetCombination(int index, out Keybind.Combination combination)
Parameters
index
intThe index of the combination to retrieve.
combination
Keybind.CombinationThe combination, or default if this method returns false.
Returns
- bool
Whether the combination could be successfully retrieved or the index was out of bounds of this keybind's combination collection.
WasDown(InputHandler, int)
Returns whether this keybind was considered to be down in the last update call. See WasDown(GenericInput, int) for more information.
public bool WasDown(InputHandler handler, int gamepadIndex = -1)
Parameters
handler
InputHandlerThe input handler to query the keys with
gamepadIndex
intThe index of the gamepad to query, or -1 to query all gamepads
Returns
- bool
Whether this keybind was considered to be down
WasModifierDown(InputHandler, int)
Returns whether any of this keybind's modifier keys were down in the last update call. See WasDown(GenericInput, int) for more information.
public bool WasModifierDown(InputHandler handler, int gamepadIndex = -1)
Parameters
handler
InputHandlerThe input handler to query the keys with
gamepadIndex
intThe index of the gamepad to query, or -1 to query all gamepads
Returns
- bool
Whether any of this keyboard's modifier keys were down