Table of Contents

Struct KeyboardState

Namespace
Microsoft.Xna.Framework.Input
Assembly
MonoGame.Framework.dll

Holds the state of keystrokes by a keyboard.

public struct KeyboardState
Inherited Members

Constructors

KeyboardState(params Keys[])

Initializes a new instance of the KeyboardState class.

public KeyboardState(params Keys[] keys)

Parameters

keys Keys[]

List of keys to be flagged as pressed on initialization.

KeyboardState(Keys[], bool, bool)

Initializes a new instance of the KeyboardState class.

public KeyboardState(Keys[] keys, bool capsLock = false, bool numLock = false)

Parameters

keys Keys[]

List of keys to be flagged as pressed on initialization.

capsLock bool

Caps Lock state.

numLock bool

Num Lock state.

Properties

CapsLock

Gets the current state of the Caps Lock key.

public bool CapsLock { get; }

Property Value

bool

this[Keys]

Returns the state of a specified key.

public KeyState this[Keys key] { get; }

Parameters

key Keys

The key to query.

Property Value

KeyState

The state of the key.

NumLock

Gets the current state of the Num Lock key.

public bool NumLock { get; }

Property Value

bool

Methods

Equals(object)

Compares whether current instance is equal to specified object.

public override bool Equals(object obj)

Parameters

obj object

The KeyboardState to compare.

Returns

bool

true if the provided KeyboardState instance is same with current; false otherwise.

GetHashCode()

Gets the hash code for KeyboardState instance.

public override int GetHashCode()

Returns

int

Hash code of the object.

GetPressedKeyCount()

Returns the number of pressed keys in this KeyboardState.

public int GetPressedKeyCount()

Returns

int

An integer representing the number of keys currently pressed in this KeyboardState.

GetPressedKeys()

Returns an array of values holding keys that are currently being pressed.

public Keys[] GetPressedKeys()

Returns

Keys[]

The keys that are currently being pressed.

GetPressedKeys(Keys[])

Fills an array of values holding keys that are currently being pressed.

public void GetPressedKeys(Keys[] keys)

Parameters

keys Keys[]

The keys array to fill. This array is not cleared, and it must be equal to or larger than the number of keys pressed.

IsKeyDown(Keys)

Gets whether given key is currently being pressed.

public bool IsKeyDown(Keys key)

Parameters

key Keys

The key to query.

Returns

bool

true if the key is pressed; false otherwise.

IsKeyUp(Keys)

Gets whether given key is currently being not pressed.

public bool IsKeyUp(Keys key)

Parameters

key Keys

The key to query.

Returns

bool

true if the key is not pressed; false otherwise.

Operators

operator ==(KeyboardState, KeyboardState)

Compares whether two KeyboardState instances are equal.

public static bool operator ==(KeyboardState a, KeyboardState b)

Parameters

a KeyboardState

KeyboardState instance to the left of the equality operator.

b KeyboardState

KeyboardState instance to the right of the equality operator.

Returns

bool

true if the instances are equal; false otherwise.

operator !=(KeyboardState, KeyboardState)

Compares whether two KeyboardState instances are not equal.

public static bool operator !=(KeyboardState a, KeyboardState b)

Parameters

a KeyboardState

KeyboardState instance to the left of the inequality operator.

b KeyboardState

KeyboardState instance to the right of the inequality operator.

Returns

bool

true if the instances are different; false otherwise.