def init(): global corsair_sdk corsair_sdk = CueSdk() connected = corsair_sdk.connect() corsair_sdk.request_control() if not connected: err = corsair_sdk.get_last_error() print("Handshake failed: %s" % err) return global corsair_all_leds corsair_all_leds = get_available_leds()
else: df['modify_x'] = [ mouse_length if d == 'keyboard' else 0 for d in df['device_type'] ] df['x'] = df['x'] + df['modify_x'] df = df.drop(['modify_x'], axis=1) # sdk function expects coordinates in tuples df['xy'] = list(zip(df['x'], df['y'])) # target size to reshape on screen image to, based on coords of keyboard/mouse image_size = (int(df['x'].max() + 1), int(df['y'].max() + 1)) # main sdk.request_control() print("Press ctrl+c to stop") try: while True: # take a screenshot image = ImageGrab.grab() # downscale image = image.resize((16, 8), resample=Image.BILINEAR) # upscale image = image.resize(image_size, resample=Image.NEAREST) df['rgb'] = df['xy'].apply(image.getpixel) for d in device_list: rgb = df[df['device_type'] == d].to_dict()['rgb'] sdk.set_led_colors_buffer_by_device_index(device_list[d], rgb)