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 in the Update loop.

Inherited Members
System.Object.Equals(System.Object, System.Object) System.Object.ReferenceEquals(System.Object, System.Object) System.Object.GetType()
Namespace: BepInEx.Configuration
Assembly: BepInEx.dll
Syntax
public struct KeyboardShortcut

Constructors

KeyboardShortcut(KeyCode, KeyCode[])

Create a new keyboard shortcut.

Declaration
public KeyboardShortcut(KeyCode mainKey, params KeyCode[] modifiers)
Parameters
Type Name Description
KeyCode mainKey

Main key to press

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
[Obsolete("Use UnityInput.Current.SupportedKeyCodes instead")]
public static readonly IEnumerable<KeyCode> AllKeyCodes
Field Value
Type Description
System.Collections.Generic.IEnumerable<KeyCode>

Empty

Shortcut that never triggers.

Declaration
public static readonly KeyboardShortcut Empty
Field Value
Type Description
KeyboardShortcut

Properties

MainKey

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, is returned.

Declaration
public readonly KeyCode MainKey { get; }
Property Value
Type Description
KeyCode

Modifiers

Modifiers of the key combination, if any.

Declaration
public readonly IEnumerable<KeyCode> Modifiers { get; }
Property Value
Type Description
System.Collections.Generic.IEnumerable<KeyCode>

Methods

Deserialize(String)

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

Equals(Object)

Declaration
public override bool Equals(object obj)
Parameters
Type Name Description
System.Object obj
Returns
Type Description
System.Boolean
Overrides
System.ValueType.Equals(System.Object)

GetHashCode()

Declaration
public override int GetHashCode()
Returns
Type Description
System.Int32
Overrides
System.ValueType.GetHashCode()

IsDown()

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

IsPressed()

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

IsUp()

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()

Serialize the key combination into a user readable string.

Declaration
public string Serialize()
Returns
Type Description
System.String

ToString()

Declaration
public override string ToString()
Returns
Type Description
System.String
Overrides
System.ValueType.ToString()