Gorgon
Show / Hide Table of Contents

Class GorgonRawKeyboard

Provides events and state for keyboard data returned from Raw Input.

Inheritance
object
GorgonRawKeyboard
Implements
IGorgonKeyboard
IGorgonRawInputDevice
IGorgonRawInputDeviceData<GorgonRawKeyboardData>
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: Gorgon.Input
Assembly: Gorgon.Input.dll
Syntax
public class GorgonRawKeyboard : IGorgonKeyboard, IGorgonRawInputDevice, IGorgonRawInputDeviceData<GorgonRawKeyboardData>
Remarks

This allows a user to read keyboard data from Raw Input for all keyboard devices, or an individual device depending on what is passed to the constructor.

Constructors

| Edit this page View Source

GorgonRawKeyboard(IGorgonKeyboardInfo)

Initializes a new instance of the GorgonRawKeyboard class.

Declaration
public GorgonRawKeyboard(IGorgonKeyboardInfo keyboardInfo = null)
Parameters
Type Name Description
IGorgonKeyboardInfo keyboardInfo

[Optional] The keyboard information used to determine which keyboard to use.

Remarks

When the keyboardInfo is set to null, the system keyboard (that is, all keyboards attached to the computer) will be used. No differentiation between keyboard devices is made. To specify an individual keyboard, pass an appropriate IGorgonKeyboardInfo obtained from the EnumerateKeyboards() method.

Exceptions
Type Condition
InvalidCastException

Thrown if the keyboardInfo is not the expected type.

Properties

| Edit this page View Source

Info

Property to return information about this keyboard.

Declaration
public IGorgonKeyboardInfo Info { get; }
Property Value
Type Description
IGorgonKeyboardInfo
| Edit this page View Source

KeyStates

Property to return the states for each of the Keys.

Declaration
public GorgonKeyStateCollection KeyStates { get; }
Property Value
Type Description
GorgonKeyStateCollection

Methods

| Edit this page View Source

KeyToCharacter(Keys, Keys)

Function to convert a keyboard key into a character (if applicable).

Declaration
public string KeyToCharacter(Keys key, Keys modifier)
Parameters
Type Name Description
Keys key

The key to convert into a character.

Keys modifier

The modifier for that key.

Returns
Type Description
string

The character representation for the key. If no representation is available, an empty string is returned.

Remarks

Use this to retrieve the character associated with a keyboard key. For example, if A is pressed, then 'a' will be returned. A modifier can be passed with the ShiftKey to return 'A'.

This method also supports the AltGr key which is represented by a combination of the ControlKey | Menu keys.

This method only returns characters for the currently active keyboard layout (i.e. the system keyboard layout). If this keyboard interface represents another keyboard attached to the computer then it will default to using the system keyboard to retrieve the character.

This method is not thread safe. Invalid data will be returned if multiple thread access this method.

This method was derived from the answer at .

Events

| Edit this page View Source

KeyDown

Event fired when a key is pressed on the keyboard.

Declaration
public event EventHandler<GorgonKeyboardEventArgs> KeyDown
Event Type
Type Description
EventHandler<GorgonKeyboardEventArgs>
| Edit this page View Source

KeyUp

Event fired when a key is released on the keyboard.

Declaration
public event EventHandler<GorgonKeyboardEventArgs> KeyUp
Event Type
Type Description
EventHandler<GorgonKeyboardEventArgs>

Implements

IGorgonKeyboard
IGorgonRawInputDevice
IGorgonRawInputDeviceData<T>

Extension Methods

GorgonDebugExtensions.ValidateObject<T>(T, string)
GorgonNullExtensions.AsNullable<T>(object)
GorgonNullExtensions.IfNull<T>(object, T)
GorgonNullExtensions.IsNull(object)
  • Edit this page
  • View Source
In this article
Back to top Copyright 2023 - Licensed under the MIT license by Michael Winsor (Tape_Worm).
Send comments on this topic to the author