Example #1
0
    def set_color_all(self, color):

        for region in REGION_KEYCODES.keys():

            keycodes = REGION_KEYCODES[region]
            n = len(keycodes)
            colors_values = [color] * n
            colors_map = dict(zip(keycodes, colors_values))

            key_colors_packet = make_key_colors_packet(region, colors_map)
            self._hid_keyboard.send_feature_report(key_colors_packet)
Example #2
0
    def set_random_color_all(self):

        for region in REGION_KEYCODES.keys():

            keycodes = REGION_KEYCODES[region]
            n = len(keycodes)
            colors_values = []
            for i in range(n):
                r = random.randint(0, 255)
                g = random.randint(0, 255)
                b = random.randint(0, 255)
                colors_values.append([r, g, b])
            colors_map = dict(zip(keycodes, colors_values))

            key_colors_packet = make_key_colors_packet(region, colors_map)
            self._hid_keyboard.send_feature_report(key_colors_packet)
Example #3
0
    def set_colors(self, linux_colors_map):

        # Translating from Linux keycodes to MSI's own encoding
        linux_keycodes = linux_colors_map.keys()
        colors = linux_colors_map.values()
        msi_keycodes = [self._msi_keymap[k] for k in linux_keycodes]
        msi_colors_map = dict(zip(msi_keycodes, colors))

        # Sorting requested keycodes by keyboard region
        maps_sorted_by_region = {}
        for keycode in msi_colors_map.keys():
            for region in REGION_KEYCODES.keys():
                if keycode in REGION_KEYCODES[region]:
                    if region not in maps_sorted_by_region.keys():
                        maps_sorted_by_region[region] = {}
                    maps_sorted_by_region[region][keycode] = msi_colors_map[keycode]

        # Sending color commands by region
        for region, region_colors_map in maps_sorted_by_region.items():
            key_colors_packet = make_key_colors_packet(region, region_colors_map)
            self._hid_keyboard.send_feature_report(key_colors_packet)