Table of Contents

Class HidCodeTranslator

Namespace
Yubico.Core.Devices.Hid
Assembly
Yubico.Core.dll

Represents an abstract keyboard's HID code map. Able to convert to and from characters and their corresponding HID code.

public sealed class HidCodeTranslator
Inheritance
object
HidCodeTranslator

Properties

this[byte]

Gets the character that corresponds to the given HID code.

public char this[byte hidCode] { get; }

Parameters

hidCode byte

Property Value

char

The character that would be rendered for this HID code.

Exceptions

ArgumentOutOfRangeException

A character was requested from a HID code not in this HidCodeTranslator.

this[char]

Gets the HID code that corresponds to the given HID code.

public byte this[char ch] { get; }

Parameters

ch char

The character to look-up the HID code for.

Property Value

byte

The HID code that would be generated by typing this character on the keyboard layout.

Exceptions

ArgumentOutOfRangeException

A HID code was requested that is not in this HidCodeTranslator.

Layout

The KeyboardLayout that this HidCodeTranslator instance uses.

public KeyboardLayout Layout { get; }

Property Value

KeyboardLayout

SupportedCharacters

An array of chars respresenting all of the characters supported by this HidCodeTranslator instance.

public IEnumerable<char> SupportedCharacters { get; }

Property Value

IEnumerable<char>

SupportedCharactersString

A string representation of all of the characters supported by this HidCodeTranslator instance.

public string SupportedCharactersString { get; }

Property Value

string

SupportedHidCodes

An array of bytes representing all of the HID codes supported by this HidCodeTranslator instance.

public byte[] SupportedHidCodes { get; }

Property Value

byte[]

Methods

GetCharacters(byte[])

Given a collection of HID codes, returns an System.Collections.Generic.IList<T> of characters that would be produced by the keyboard layout in this class.

public IEnumerable<char> GetCharacters(byte[] hidCodes)

Parameters

hidCodes byte[]

An array of keyboard HID codes.

Returns

IEnumerable<char>

An System.Collections.Generic.IEnumerable<T> of characters that would be generated by the HID codes.

Exceptions

ArgumentOutOfRangeException

At least one of the HID codes was not mapped in this HidCodeTranslator instance.

GetHidCodes(IEnumerable<char>)

Given a collection of characters, returns the corresponding HID codes for the keyboard layout.

public byte[] GetHidCodes(IEnumerable<char> characters)

Parameters

characters IEnumerable<char>

A list of characters to convert.

Returns

byte[]

The HID codes that correspond to the input characters.

Exceptions

ArgumentOutOfRangeException

At least one of the characters in the collection is not in the map for this HidCodeTranslator instance.

GetHidCodes(string)

Given a string, returns the corresponding HID codes for the individual characters in the string for the keyboard layout.

public byte[] GetHidCodes(string value)

Parameters

value string

A string to convert to HID codes.

Returns

byte[]

The HID codes that correspond to the input string.

Exceptions

ArgumentOutOfRangeException

At least one of the characters in the string is not in the map for this HidCodeTranslator instance.

GetInstance(KeyboardLayout)

Gets a KeyboardLayout specific instance of this class.

public static HidCodeTranslator GetInstance(KeyboardLayout layout)

Parameters

layout KeyboardLayout

Identifies which keyboard layout to use.

Returns

HidCodeTranslator

An instance of this class.

GetString(byte[])

Given a collection of HID codes, returns the string that it would produce.

public string GetString(byte[] hidCodes)

Parameters

hidCodes byte[]

An array of keyboard HID codes.

Returns

string

A string of characters that would have been generated by the keyboard HID codes.

Remarks

Only HID codes that are mapped in this KeyboardLayout should be in this collection.

Exceptions

ArgumentOutOfRangeException

At least one of the HID codes was not mapped in this HidCodeTranslator instance.