Skip to main content
Version: 15.x (API 15) [Current]

Interface IKeyState

Wrapper around the game keystate buffer, which contains the pressed state for all keyboard keys, indexed by virtual vkCode.

Remarks​

The stored key state is actually a combination field, however the below ephemeral states are consumed each frame. Setting the value may be mildly useful, however retrieving the value is largely pointless. In testing, it wasn't possible without setting the statue manually. index & 0 = key pressed. index & 1 = key down (ephemeral). index & 2 = key up (ephemeral). index & 3 = short key press (ephemeral).

<p> Virtual keys are tracked through two methods:

<ul><li><span class="term">Dalamud.Plugin.Services.IKeyState.IsVirtualKeyValid(int) and Dalamud.Plugin.Services.IKeyState.GetValidVirtualKeys()</span>The game's own keystate buffer.</li><li><span class="term">Dalamud.Plugin.Services.IKeyState.IsExtendedVirtualKeyValid(int) and Dalamud.Plugin.Services.IKeyState.GetExtendedVirtualKeys()</span>Dalamud's extended virtual key support.</li></ul>

A given Dalamud.Game.ClientState.Keys.VirtualKey is only ever one or the other, never both. </p> <p> Directional modifier keys (Dalamud.Game.ClientState.Keys.VirtualKey.LSHIFT, Dalamud.Game.ClientState.Keys.VirtualKey.RSHIFT, Dalamud.Game.ClientState.Keys.VirtualKey.LCONTROL, Dalamud.Game.ClientState.Keys.VirtualKey.RCONTROL, Dalamud.Game.ClientState.Keys.VirtualKey.LMENU, Dalamud.Game.ClientState.Keys.VirtualKey.RMENU) are tracked by Dalamud as extended virtual keys. The game only tracks generic modifiers (Dalamud.Game.ClientState.Keys.VirtualKey.SHIFT, Dalamud.Game.ClientState.Keys.VirtualKey.CONTROL, Dalamud.Game.ClientState.Keys.VirtualKey.MENU). Pressing a directional modifier key will activate both the generic game modifier in Dalamud.Plugin.Services.IKeyState.GetValidVirtualKeys() and the extended key in Dalamud.Plugin.Services.IKeyState.GetExtendedVirtualKeys(). </p> <p> Most do not need to distinguish between the two: Dalamud.Plugin.Services.IKeyState.this[int] and Dalamud.Plugin.Services.IKeyState.GetRawValue(int)/Dalamud.Plugin.Services.IKeyState.SetRawValue(System.Int32,System.Int32) transparently handle both. The sole distinction is in Dalamud.Plugin.Services.IKeyState.TryGetSeVirtualKey(System.Int32,System.Int32@) which only succeeds for valid game's keys; a valid extended key and an invalid key will both return false. Use Dalamud.Plugin.Services.IKeyState.IsExtendedVirtualKeyValid(int) to distinguish between the two. </p>

Assembly: Dalamud.dll​
Declaration
public interface IKeyState : IDalamudService

Properties​

this[int]​

Get or set the key-pressed state for a given vkCode.

Declaration
bool this[int vkCode] { get; set; }

this[VirtualKey]​

Get or set the key-pressed state for a given vkCode.

Declaration
bool this[VirtualKey vkCode] { get; set; }

Methods​

GetRawValue(int)​

Gets the value in the index array.

Declaration
int GetRawValue(int vkCode)
Returns​

System.Int32: The raw value stored in the index array.

Parameters​
TypeNameDescription
System.Int32vkCodeThe virtual key to change.
Exceptions​

System.ArgumentException
If the vkCode is not valid. Refer to Dalamud.Plugin.Services.IKeyState.IsVirtualKeyValid(int) or Dalamud.Plugin.Services.IKeyState.GetValidVirtualKeys() or Dalamud.Plugin.Services.IKeyState.GetExtendedVirtualKeys().

GetRawValue(VirtualKey)​

Gets the value in the index array.

Declaration
int GetRawValue(VirtualKey vkCode)
Returns​

System.Int32: The raw value stored in the index array.

Parameters​
TypeNameDescription
Dalamud.Game.ClientState.Keys.VirtualKeyvkCodeThe virtual key to change.
Exceptions​

System.ArgumentException
If the vkCode is not valid. Refer to Dalamud.Plugin.Services.IKeyState.IsVirtualKeyValid(int) or Dalamud.Plugin.Services.IKeyState.GetValidVirtualKeys() or Dalamud.Plugin.Services.IKeyState.GetExtendedVirtualKeys().

SetRawValue(int, int)​

Sets the value in the index array.

Declaration
void SetRawValue(int vkCode, int value)
Parameters​
TypeNameDescription
System.Int32vkCodeThe virtual key to change.
System.Int32valueThe raw value to set in the index array.
Exceptions​

System.ArgumentException
If the vkCode is not valid. Refer to Dalamud.Plugin.Services.IKeyState.IsVirtualKeyValid(int) or Dalamud.Plugin.Services.IKeyState.GetValidVirtualKeys() or Dalamud.Plugin.Services.IKeyState.GetExtendedVirtualKeys(). System.ArgumentOutOfRangeException
If the set value is non-zero.

SetRawValue(VirtualKey, int)​

Sets the value in the index array.

Declaration
void SetRawValue(VirtualKey vkCode, int value)
Parameters​
TypeNameDescription
Dalamud.Game.ClientState.Keys.VirtualKeyvkCodeThe virtual key to change.
System.Int32valueThe raw value to set in the index array.
Exceptions​

System.ArgumentException
If the vkCode is not valid. Refer to Dalamud.Plugin.Services.IKeyState.IsVirtualKeyValid(int) or Dalamud.Plugin.Services.IKeyState.GetValidVirtualKeys() or Dalamud.Plugin.Services.IKeyState.GetExtendedVirtualKeys(). System.ArgumentOutOfRangeException
If the set value is non-zero.

IsVirtualKeyValid(int)​

Gets a value indicating whether the given VirtualKey code is natively tracked by the game.

Declaration
bool IsVirtualKeyValid(int vkCode)
Returns​

System.Boolean: If the code is valid.

Parameters​
TypeNameDescription
System.Int32vkCodeVirtual key code.
Remarks​

Directional modifier keys (Dalamud.Game.ClientState.Keys.VirtualKey.LSHIFT, Dalamud.Game.ClientState.Keys.VirtualKey.RSHIFT, etc.) return false here as they are tracked by Dalamud as extended virtual keys. Use Dalamud.Plugin.Services.IKeyState.IsExtendedVirtualKeyValid(int) to check for those.

IsVirtualKeyValid(VirtualKey)​

Gets a value indicating whether the given VirtualKey code is natively tracked by the game.

Declaration
bool IsVirtualKeyValid(VirtualKey vkCode)
Returns​

System.Boolean: If the code is valid.

Parameters​
TypeNameDescription
Dalamud.Game.ClientState.Keys.VirtualKeyvkCodeVirtual key code.
Remarks​

Directional modifier keys (Dalamud.Game.ClientState.Keys.VirtualKey.LSHIFT, Dalamud.Game.ClientState.Keys.VirtualKey.RSHIFT, etc.) return false here as they are tracked by Dalamud as extended virtual keys. Use Dalamud.Plugin.Services.IKeyState.IsExtendedVirtualKeyValid(int) to check for those.

IsExtendedVirtualKeyValid(int)​

Gets a value indicating whether the given VirtualKey code is regarded as a valid extended key by Dalamud.

Declaration
bool IsExtendedVirtualKeyValid(int vkCode)
Returns​

System.Boolean: If the code is a valid extended key.

Parameters​
TypeNameDescription
System.Int32vkCodeVirtual key code.
Remarks​

Extended keys include keys the game does not track natively (Dalamud.Game.ClientState.Keys.VirtualKey.F13) as well as directional modifier keys (Dalamud.Game.ClientState.Keys.VirtualKey.LSHIFT, Dalamud.Game.ClientState.Keys.VirtualKey.RSHIFT, etc.).

IsExtendedVirtualKeyValid(VirtualKey)​

Gets a value indicating whether the given VirtualKey code is regarded as a valid extended key by Dalamud.

Declaration
bool IsExtendedVirtualKeyValid(VirtualKey vkCode)
Returns​

System.Boolean: If the code is a valid extended key.

Parameters​
TypeNameDescription
Dalamud.Game.ClientState.Keys.VirtualKeyvkCodeVirtual key code.
Remarks​

Extended keys include keys the game does not track natively (Dalamud.Game.ClientState.Keys.VirtualKey.F13) as well as directional modifier keys (Dalamud.Game.ClientState.Keys.VirtualKey.LSHIFT, Dalamud.Game.ClientState.Keys.VirtualKey.RSHIFT, etc.).

TryGetSeVirtualKey(int, out int)​

Attempts to get the game's virtual key code equivalent of a given virtual key code.

Declaration
bool TryGetSeVirtualKey(int vkCode, out int seVkCode)
Returns​

System.Boolean: Whether the virtual key code has a valid game's virtual key code equivalent.

Parameters​
TypeNameDescription
System.Int32vkCodeThe virtual key code to convert.
System.Int32seVkCodeThe resulting game's virtual key code, if the conversion is successful.
Remarks​

Returns false both when <code class="paramref">vkCode</code> is not a valid Dalamud.Game.ClientState.Keys.VirtualKey and when it is a valid extended key that the game does not recognize. If you need to distinguish between the two, use Dalamud.Plugin.Services.IKeyState.IsExtendedVirtualKeyValid(int).

TryGetSeVirtualKey(VirtualKey, out int)​

Attempts to get the game's virtual key code equivalent of a given virtual key code.

Declaration
bool TryGetSeVirtualKey(VirtualKey vkCode, out int seVkCode)
Returns​

System.Boolean: Whether the virtual key code has a valid game's virtual key code equivalent.

Parameters​
TypeNameDescription
Dalamud.Game.ClientState.Keys.VirtualKeyvkCodeThe virtual key code to convert.
System.Int32seVkCodeThe resulting game's virtual key code, if the conversion is successful.
Remarks​

Returns false both when <code class="paramref">vkCode</code> is not a valid Dalamud.Game.ClientState.Keys.VirtualKey and when it is a valid extended key that the game does not recognize. If you need to distinguish between the two, use Dalamud.Plugin.Services.IKeyState.IsExtendedVirtualKeyValid(int).

GetValidVirtualKeys()​

Gets an array of virtual keys the game considers valid input.

Declaration
IEnumerable<VirtualKey> GetValidVirtualKeys()
Returns​

System.Collections.Generic.IEnumerable<Dalamud.Game.ClientState.Keys.VirtualKey>: An array of valid virtual keys.

Remarks​

This list contains generic modifiers (Dalamud.Game.ClientState.Keys.VirtualKey.SHIFT, Dalamud.Game.ClientState.Keys.VirtualKey.CONTROL, Dalamud.Game.ClientState.Keys.VirtualKey.MENU). See Dalamud.Plugin.Services.IKeyState.GetExtendedVirtualKeys() for directional modifiers (Dalamud.Game.ClientState.Keys.VirtualKey.LSHIFT, Dalamud.Game.ClientState.Keys.VirtualKey.RSHIFT, etc.).

GetExtendedVirtualKeys()​

Gets an array of virtual keys tracked by Dalamud for plugin use.

Declaration
IEnumerable<VirtualKey> GetExtendedVirtualKeys()
Returns​

System.Collections.Generic.IEnumerable<Dalamud.Game.ClientState.Keys.VirtualKey>: An array of extended virtual keys.

Remarks​

This list contains directional modifiers (Dalamud.Game.ClientState.Keys.VirtualKey.LSHIFT, Dalamud.Game.ClientState.Keys.VirtualKey.RSHIFT, etc.) and keys the game does not natively recognize.

ClearAll()​

Clears the pressed state for all keys.

Declaration
void ClearAll()