masterkeys

Author: RedFantom License: GNU GPLv3 Copyright (c) 2018-2019 RedFantom

class masterkeys.ControlMode[source]
CUSTOM_CTRL = 2
EFFECT_CTRL = 1
FIRMWARE_CTRL = 0
PROFILE_CTRL = 3
class masterkeys.Effect[source]
EFF_BREATH = 1
EFF_BREATH_CYCLE = 2
EFF_CROSS = 6
EFF_FULL_ON = 0
EFF_RAIN = 7
EFF_RAPID_FIRE = 12
EFF_REC = 10
EFF_RIPPLE = 5
EFF_SINGLE = 3
EFF_SNAKE = 9
EFF_SPECTRUM = 11
EFF_STAR = 8
EFF_WAVE = 4
class masterkeys.Model[source]
MODEL_ANY = -2
MODEL_NOT_SET = -1
MODEL_RGB_L = 0
MODEL_RGB_M = 5
MODEL_RGB_S = 1
MODEL_UNKNOWN = -3
MODEL_WHITE_L = 2
MODEL_WHITE_M = 3
MODEL_WHITE_S = 7
class masterkeys.ResultCode[source]
ERR_DESCR = -11
ERR_DEV_CLOSE_FAILED = -6
ERR_DEV_LIST = -9
ERR_DEV_NOT_CLOSED = -15
ERR_DEV_NOT_CONNECTED = -2
ERR_DEV_NOT_SET = -3
ERR_DEV_OPEN_FAILED = -7
ERR_DEV_RESET_FAILED = -16
ERR_IFACE_CLAIM_FAILED = -4
ERR_IFACE_RELEASE_FAILED = -5
ERR_INVALID_DEV = -1
ERR_KERNEL_DRIVER = -8
ERR_PROTOCOL = -13
ERR_TRANSFER = -10
ERR_UNKNOWN_LAYOUT = -14
SUCCESS = 0
masterkeys.build_layout_list()[source]

Return a list of the right proportions for full LED layout

Returns

Empty layout list

Return type

List[List[Tuple[int, int, int], ..], ..]

masterkeys.detect_devices()[source]

Detect supported connected devices and return a tuple of models

Returns

Tuple of integers (Model)

Return type

Tuple[int, ..]

Raises

RuntimeError upon internal Python error

masterkeys.disable_control()[source]

Disable control on the device that has been set and is controlled

Returns

Result code (ResultCode)

Return type

int

masterkeys.enable_control()[source]

Enable control on the device that has been set

Returns

Result code (ResultCode)

Return type

int

masterkeys.get_active_profile()[source]

Return the number of the profile active on the keyboard

Returns

Result code (ResultCode) or profile number

Return type

int

masterkeys.get_device_ident()[source]

Return the bDevice USB descriptor value for the controlled keyboard

Returns

bDevice USB descriptor value or result code (<0)

Return type

int

masterkeys.save_profile()[source]

Save the changes made to the lighting to the active profile

Returns

Result code (ResultCode)

Return type

int

masterkeys.set_active_profile(profile)[source]

Activate a profile on the keyboard

Parameters

profile (int) – Number of profile to activate

Returns

Result code (ResultCode)

Return type

int

masterkeys.set_all_led_color(layout)[source]

Set the color of all LEDs on the keyboard individually

Parameters

layout (List[List[Tuple[int, int, int], ..], ..]) – List of lists of color tuples such as created by build_layout_list()

Returns

Result code (ResultCode)

Return type

int

Raises

ValueError if the wrong amount of elements is in the list

Raises

TypeError if invalid argument type (any element)

masterkeys.set_all_led_color_dict(keys)[source]

Set the color of all LEDs on the controlled device with a dictionary

The keys should be specified in a dictionary of the format {(row, col): (r, g, b)}

Parameters

keys (Dict[Tuple[int, int], Tuple[int, int, int]]) – Dictionary containing key color data

Returns

Result code (ResultCode)

Return type

int

masterkeys.set_control_mode(mode)[source]

Change the control mode of the keyboard manually

Parameters

mode (int) – New control mode to set (ControlMode)

Returns

Result code (ResultCode)

Return type

int

masterkeys.set_device(model)[source]

Set the device to be controlled by the library to the specified model

Parameters

model (int) – Model to be controlled by the library. Only one device is supported in the Python library. Only the first found device of the specified model is controlled.

Returns

Result code (ResultCode)

Return type

int

Raises

TypeError upon invalid argument type

masterkeys.set_effect(effect)[source]

Set the effect to be active on the controlled keyboard

Parameters

effect (int) – Effect number to set to be active (Effect)

Returns

Result code (ResultCode)

Return type

int

Raises

TypeError upon invalid argument type

masterkeys.set_effect_details(effect, direction=0, speed=96, amount=0, foreground=(255, 255, 255), background=(0, 0, 0))[source]

Set an effect with custom parameters

For more details about the parameters, please see the libmk documentation.

Parameters
  • effect (int) – Effect number (Effect)

  • direction (int) – Direction of the animation of the effect

  • speed (int) – Speed of the animation of the effect

  • amount (int) – Amount/intensity of the effect

  • foreground (Tuple[int, int, int]) – Foreground color of the effect

  • background (Tuple[int, int, int]) – Background color of the effect

Returns

Result code (ResultCode)

Return type

int

masterkeys.set_full_led_color(r, g, b)[source]

Set the color of all the LEDs on the keyboard to a single color

Parameters
  • r (int) – red color byte

  • g (int) – green color byte

  • b (int) – blue color byte

Returns

Result code (ResultCode)

Return type

int

masterkeys.set_ind_led_color(row, col, r, g, b)[source]

Set the color of a single, individual key on the keyboard

Parameters
  • row (int) – zero-indexed row index < MAX_ROWS

  • col (int) – zero-indexed column index < MAX_COLS

  • r (int) – red color byte

  • g (int) – green color byte

  • b (int) – blue color byte

Returns

Result code (ResultCode)

Return type

int

Raises

TypeError upon invalid argument type