class

Keyleds::Device

Inherits Reference < Object

Represents a physical Logitech device that can be interfaced with.

Constants

APP_IDS = LibKeyleds::APP_ID_MIN..LibKeyleds::APP_ID_MAX

The full range of valid application IDs that can be used for initialization (i.e. Device.open.)

Constructors

new(path : String, app_id : UInt8)

Creates a new Device. Must be explicitly closed with Device#close after usage.

  • path must be a valid path to the device's corresponding HID file (i.e. /dev/hidraw1).
  • app_id is a constant identifier for use with all further device communication. See APP_IDS for valid arguments.
Source

Class methods

open(path : String, app_id : UInt8, &)

Creates a new Device with the given parameters, yields it to a block, and automatically closes the device.

Source

Instance methods

blocks

Gets all device LED Keyblocks.

Source
close

Closes the device handle.

Source
commit_leds

Applies pending lighting changes set by Device#set_leds or Device#set_led_block.

Source
custom_gkeys(enabled : Bool)

Enables or disable custom G-key behavior. If false, G-keys will default to their corresponding F-keys.

Source
fd

Returns the device's underlying file descriptor.

Source
feature_count

Gets the number of HID++ features supported by the device.

Source
feature_id(feature_index : UInt8) : UInt16

Finds the feature ID of a feature, given its index in the device's internal feature table.

Source
feature_index(feature_id : UInt16) : UInt8

Given a feature's ID, returns its index in the device's internal table.

Source
flush

Flushes pending inbound events, processing G-key presses if present.

Source
gamemode_add(scancodes : Array(UInt8))

Adds the given keys, represented by their scancodes, to the game mode block list.

Source
gamemode_max_blocked

Returns the maximum possible number of keys that can be blocked at a time during game mode.

Source
gamemode_remove(scancodes : Array(UInt8))

Remove the given keys, represented by their scancodes, from the game mode block list.

Source
gamemode_reset

Resets the game mode blocked key list to empty.

Source
gkeys_count

Returns the number of G-keys available on the device.

Source
keyboard_layout

Returns the device's declared international keyboard layout.

Source
leds(block : BlockId, key_offset : UInt16, num_keys : UInt32) : Array(KeyColor)

Starting at key_offset within the given block, returns num_keys current LED states.

Source
name

Returns the name of the device.

Source
on_gkey

Defines a callback that should be run whenever a G-key (or M/MR-key) is pressed. The second parameter is a BitArray, with the first bit representing the first key in the group. Triggered by Device#flush.

Keyleds::Device.open("/dev/hidraw1", 1) do |dev|
  dev.custom_gkeys(true)

  dev.on_gkey do |type, keys|
    puts "is the first key on? #{keys[0]}"
  end

  loop { dev.flush } # is the first key on? false
end
Source
ping

Resynchronizes with the device. Use as a recovery mechanism after another call has errored.

Source
protocol

Returns the device's current protocol.

Source
reportrate

Returns the device's current report rate.

Source
set_led_block(block : BlockId, red : UInt8, green : UInt8, blue : UInt8)

Sets the entire LED block to a single uniform color. Must be committed with Device#commit_leds.

Source
set_leds(block : BlockId, keys : Array(KeyColor))

Sets the LED color for the given keys. Must be committed with Device#commit_leds.

Source
set_mkeys(state : Tuple(Bool, Bool, Bool))

Sets the lighting state for the M keys.

Source
set_mrkey(state : Bool)

Sets the lighting state for the MR key.

Source
set_reportrate(rate : UInt32)

Sets the keyboard's report rate to rate.

Source
set_timeout(microseconds : UInt32)

Sets the device's HID++ command timeout.

Source
supported_rates

Gets all supported report rates.

Source
type

Returns the device's type. See Type for more info.

Source
version

Returns the device's current firmware version.

Source

Nested types