From b5fdf73aa03e33c35249997d07da223f1f70343b Mon Sep 17 00:00:00 2001 From: Looki2000 Date: Sat, 23 Mar 2024 02:21:01 +0100 Subject: [PATCH] added LogiSteeringInitializeWithWindow --- logidrivepy/functions.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/logidrivepy/functions.py b/logidrivepy/functions.py index de14d3f..395a2ee 100644 --- a/logidrivepy/functions.py +++ b/logidrivepy/functions.py @@ -18,6 +18,11 @@ def __init__(self, dll_path, structs, use_gui=True): self.LogiSteeringInitialize.argtypes = [ctypes.c_bool] self.LogiSteeringInitialize.restype = ctypes.c_bool + # LogiSteeringInitializeWithWindow + self.LogiSteeringInitializeWithWindow = self.logi_dll.LogiSteeringInitializeWithWindow + self.LogiSteeringInitializeWithWindow.argtypes = [ctypes.c_bool, ctypes.c_long] + self.LogiSteeringInitializeWithWindow.restype = ctypes.c_bool + # LogiUpdate self.LogiUpdate = self.logi_dll.LogiUpdate self.LogiUpdate.argtypes = [] @@ -263,6 +268,34 @@ def steering_initialize(self, ignore_xinput_controllers=True): """ return self.LogiSteeringInitialize(ignore_xinput_controllers) + def steering_initialize_with_window(self, ignore_xinput_controllers=True, hwnd=None): + """ + Initializes the steering system with a window handle if certain conditions are met. + In contrast to the steering_initialize function, this one allows reading wheel inputs even + when focused on some different, specific window like a Pygame window by providing the hwnd. + + Args: + - ignore_xinput_controllers (bool, optional): If true, X-input controllers are ignored. Default is True. + - hwnd (long): The window handle. + + Returns: + - bool: Returns True if: + * No other instance is running, and + * The window handle is found. + Otherwise, returns False. + + Note: + - This is a part of the Logitech G Hub APIs. Make sure to install the necessary drivers and libraries. + + Example using Pygame: + >>> hwnd = pygame.display.get_wm_info()["window"] + >>> steering_initialize_with_window(ignore_xinput_controllers=False, hwnd) + """ + if hwnd is None: + raise Exception("Window handle was not provided.") + + return self.LogiSteeringInitializeWithWindow(ignore_xinput_controllers, hwnd) + def logi_update(self): """ Updates forces and controller connections, if the main window handler is found. This function needs to be