Struct KeyboardShortcut
A keyboard shortcut that can be used in Update method to check if user presses a key combo. The shortcut is only
triggered when the user presses the exact combination. For example, F + LeftCtrl
will trigger only if user
presses and holds only LeftCtrl, and then presses F. If any other keys are pressed, the shortcut will not trigger.
Can be used as a value of a setting in Bind<T>(ConfigDefinition, T, ConfigDescription) to allow user to change this shortcut and have the changes saved.
How to use: Use IsDown() in this class instead of UnityEngine.Input.GetKeyDown(UnityEngine.KeyCode) in the Update loop.
Syntax
public struct KeyboardShortcut
Constructors
Create a new keyboard shortcut.
Declaration
public KeyboardShortcut(KeyCode mainKey, params KeyCode[] modifiers)
Parameters
Type | Name | Description |
---|---|---|
UnityEngine.KeyCode |
mainKey |
Main key to press |
UnityEngine.KeyCode[] |
modifiers |
Keys that should be held down before main key is registered |
Fields
AllKeyCodes
All KeyCode values that can be used in a keyboard shortcut.
Declaration
public static readonly IEnumerable<KeyCode> AllKeyCodes
Field Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<UnityEngine.KeyCode> |
Empty
Shortcut that never triggers.
Declaration
public static readonly KeyboardShortcut Empty
Field Value
Type | Description |
---|---|
KeyboardShortcut |
Properties
Main key of the key combination. It has to be pressed / let go last for the combination to be triggered. If the combination is empty, UnityEngine.KeyCode.None is returned.
Declaration
public readonly KeyCode MainKey { get; }
Property Value
Type | Description |
---|---|
UnityEngine.KeyCode |
Modifiers of the key combination, if any.
Declaration
public readonly IEnumerable<KeyCode> Modifiers { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<UnityEngine.KeyCode> |
Methods
Attempt to deserialize key combination from the string.
Declaration
public static KeyboardShortcut Deserialize(string str)
Parameters
Type | Name | Description |
---|---|---|
System.String |
str |
Returns
Type | Description |
---|---|
KeyboardShortcut |
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
System.Object |
obj |
Returns
Type | Description |
---|---|
System.Boolean |
Overrides
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
System.Int32 |
Overrides
Check if the main key was just pressed (Input.GetKeyDown), and specified modifier keys are all pressed
Declaration
public bool IsDown()
Returns
Type | Description |
---|---|
System.Boolean |
Check if the main key is currently held down (Input.GetKey), and specified modifier keys are all pressed
Declaration
public bool IsPressed()
Returns
Type | Description |
---|---|
System.Boolean |
Check if the main key was just lifted (Input.GetKeyUp), and specified modifier keys are all pressed.
Declaration
public bool IsUp()
Returns
Type | Description |
---|---|
System.Boolean |
Serialize the key combination into a user readable string.
Declaration
public string Serialize()
Returns
Type | Description |
---|---|
System.String |
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String |