Skip to content

key_sdk

Classes:

Name Description
GkeyCode

Represent a structure that defines the layout of G key codes.

GkeySdkManager

G-key SDK manager.

LogiGkeyCBContext

A class representing the Logitech G-Key Callback Context.

GkeyCode

Bases: Structure

Represent a structure that defines the layout of G key codes.

GkeySdkManager

GkeySdkManager(
    callback: Callable[[int, int, int, int], None],
)

G-key SDK manager.

Create G-key SDK manager.

Parameters:

Name Type Description Default

callback

Callable[[int, int, int, int], None]

callback handler

required

Methods:

Name Description
callback

Receive callback events for G-key button pushes.

logi_gkey_init

Make the necessary initializations.

logi_gkey_is_keyboard_gkey_pressed

Indicate whether a keyboard G-key is currently being pressed.

logi_gkey_is_keyboard_gkey_string

Return a G-key-specific friendly string.

logi_gkey_is_mouse_pressed

Indicate whether a mouse button is currently being pressed.

logi_gkey_is_mouse_string

Return a button-specific friendly string.

logi_gkey_shutdown

Unload the corresponding DLL and frees up any allocated resources.

Source code in src/dcspy/sdk/key_sdk.py
40
41
42
43
44
45
46
47
48
49
50
51
def __init__(self, callback: Callable[[int, int, int, int], None]) -> None:
    """
    Create G-key SDK manager.

    :param callback: callback handler
    """
    self.key_dll: CDLL = load_dll(KeyDll)  # type: ignore[assignment]
    self.gkey_context = LogiGkeyCBContext()
    self.user_callback = callback
    self.gkey_context.gkeyCallBack = GKEY_CALLBACK(self.callback)
    self.gkey_context.gkeyContext = c_void_p()
    self.gkey_context_ptr = pointer(self.gkey_context)

callback

callback(
    g_key_code: GkeyCode,
    gkey_or_button_str: str,
    context: int | None = None,
) -> None

Receive callback events for G-key button pushes.

This function is called whenever a G-key event occurs. This then calls the callback handler provided by the user.

Parameters:

Name Type Description Default

g_key_code

GkeyCode

The gkey code object representing the current gkey event.

required

gkey_or_button_str

str

The string representation of the gkey or button being pressed.

required

context

int | None

The context in which the gkey event occurred.

None
Source code in src/dcspy/sdk/key_sdk.py
53
54
55
56
57
58
59
60
61
62
63
64
65
def callback(self, g_key_code: GkeyCode, gkey_or_button_str: str, context: int | None = None) -> None:
    """
    Receive callback events for G-key button pushes.

    This function is called whenever a G-key event occurs.
    This then calls the callback handler provided by the user.

    :param g_key_code: The gkey code object representing the current gkey event.
    :param gkey_or_button_str: The string representation of the gkey or button being pressed.
    :param context: The context in which the gkey event occurred.
    """
    LOG.debug(f'Gkey callback: gkey {gkey_or_button_str}, key code: {g_key_code} {context=}')
    self.user_callback(g_key_code.keyIdx, g_key_code.mState, g_key_code.keyDown, g_key_code.mouse)

logi_gkey_init

logi_gkey_init() -> bool

Make the necessary initializations.

It must be called before your application can see G-key/button events.

Returns:

Type Description
bool

If the function succeeds, it returns True. Otherwise, False.

Source code in src/dcspy/sdk/key_sdk.py
67
68
69
70
71
72
73
74
75
76
77
78
79
def logi_gkey_init(self) -> bool:
    """
    Make the necessary initializations.

    It must be called before your application can see G-key/button events.
    :return: If the function succeeds, it returns True. Otherwise, False.
    """
    with suppress(AttributeError):
        self.key_dll.LogiGkeyInit.restype = c_bool
        self.key_dll.LogiGkeyInit.argtypes = [POINTER(LogiGkeyCBContext)]

        return self.key_dll.LogiGkeyInit(self.gkey_context_ptr)
    return False

logi_gkey_is_keyboard_gkey_pressed

logi_gkey_is_keyboard_gkey_pressed(
    g_key: int, mode: int
) -> bool

Indicate whether a keyboard G-key is currently being pressed.

Parameters:

Name Type Description Default

g_key

int

Number of the G-key to check, example between 1 and 29 for G13

required

mode

int

Number of the mode currently selected, example 1, 2 or 3

required

Returns:

Type Description
bool

True if the specified G-key for the specified Mode is currently being pressed, False otherwise

Source code in src/dcspy/sdk/key_sdk.py
86
87
88
89
90
91
92
93
94
95
96
def logi_gkey_is_keyboard_gkey_pressed(self, g_key: int, mode: int) -> bool:
    """
    Indicate whether a keyboard G-key is currently being pressed.

    :param g_key: Number of the G-key to check, example between 1 and 29 for G13
    :param mode: Number of the mode currently selected, example 1, 2 or 3
    :return: True if the specified G-key for the specified Mode is currently being pressed, False otherwise
    """
    with suppress(AttributeError):
        return self.key_dll.LogiGkeyIsKeyboardGkeyPressed(g_key, mode)
    return False

logi_gkey_is_keyboard_gkey_string

logi_gkey_is_keyboard_gkey_string(
    g_key: int, mode: int
) -> str

Return a G-key-specific friendly string.

Parameters:

Name Type Description Default

g_key

int

Number of the G-key to check, example between 1 and 29 for G13

required

mode

int

Number of the mode currently selected (1, 2 or 3)

required

Returns:

Type Description
str

Friendly string for specified G-key and Mode number, example 'G5/M1'

Source code in src/dcspy/sdk/key_sdk.py
 98
 99
100
101
102
103
104
105
106
107
108
def logi_gkey_is_keyboard_gkey_string(self, g_key: int, mode: int) -> str:
    """
    Return a G-key-specific friendly string.

    :param g_key: Number of the G-key to check, example between 1 and 29 for G13
    :param mode: Number of the mode currently selected (1, 2 or 3)
    :return: Friendly string for specified G-key and Mode number, example 'G5/M1'
    """
    with suppress(AttributeError):
        return self.key_dll.LogiGkeyGetKeyboardGkeyString(g_key, mode)
    return ''

logi_gkey_is_mouse_pressed

logi_gkey_is_mouse_pressed(button_number: int) -> bool

Indicate whether a mouse button is currently being pressed.

Parameters:

Name Type Description Default

button_number

int

Number of the buttons to check, example between 6 and 20 for G600

required

Returns:

Type Description
bool

True if the specified button is currently being pressed, False otherwise

Source code in src/dcspy/sdk/key_sdk.py
110
111
112
113
114
115
116
117
118
119
def logi_gkey_is_mouse_pressed(self, button_number: int) -> bool:
    """
    Indicate whether a mouse button is currently being pressed.

    :param button_number: Number of the buttons to check, example between 6 and 20 for G600
    :return: True if the specified button is currently being pressed, False otherwise
    """
    with suppress(AttributeError):
        return self.key_dll.LogiGkeyIsMousePressed(button_number)
    return False

logi_gkey_is_mouse_string

logi_gkey_is_mouse_string(button_number: int) -> str

Return a button-specific friendly string.

Parameters:

Name Type Description Default

button_number

int

Number of the button to check, example between 6 and 20 for G600

required

Returns:

Type Description
str

Friendly string for specified button number, example 'Mouse Btn 8'

Source code in src/dcspy/sdk/key_sdk.py
121
122
123
124
125
126
127
128
129
130
def logi_gkey_is_mouse_string(self, button_number: int) -> str:
    """
    Return a button-specific friendly string.

    :param button_number: Number of the button to check, example between 6 and 20 for G600
    :return: Friendly string for specified button number, example 'Mouse Btn 8'
    """
    with suppress(AttributeError):
        return self.key_dll.LogiGkeyGetMouseString(button_number)
    return ''

logi_gkey_shutdown

logi_gkey_shutdown() -> None

Unload the corresponding DLL and frees up any allocated resources.

Source code in src/dcspy/sdk/key_sdk.py
81
82
83
84
def logi_gkey_shutdown(self) -> None:
    """Unload the corresponding DLL and frees up any allocated resources."""
    with suppress(AttributeError):
        self.key_dll.LogiGkeyShutdown()

LogiGkeyCBContext

Bases: Structure

A class representing the Logitech G-Key Callback Context.