(setting_info, mapping)
return packet
Called by the :class:`rivalcfg.mouse.Mouse` class when processing a
    "buttons" type setting.

    :param dict setting_info: The information dict of the setting from the
                              device profile.
    :param str,dict mapping: The mapping of the mouse buttons.
    :rtype: [int]
Called by the :class:`rivalcfg.mouse.Mouse` class when processing a
    "buttons" type setting.
Called by the : class : rivalcfg . mouse . Mouse class when processing a buttons type setting .
def process_value(setting_info, mapping):
    """Called by the :class:`rivalcfg.mouse.Mouse` class when processing a
    "buttons" type setting.

    :param dict setting_info: The information dict of the setting from the
                              device profile.
    :param str,dict mapping: The mapping of the mouse buttons.
    :rtype: [int]
    """
    # -- Parse input values

    if type(mapping) in [str, _unicode_type] and REGEXP_PARAM_STRING.match(mapping):
        is_valid, reason = is_buttons(mapping, setting_info)
        if not is_valid:
            raise ValueError(reason)
        mapping = parse_param_string(mapping)
    elif type(mapping) in [str, _unicode_type] and mapping.lower() == "default":
        mapping = {"buttons": {}}
    elif type(mapping) is dict:
        pass
    else:
        raise ValueError("Invalid input value '%s'" % str(mapping))

    # -- Initialize mouse buttons

    buttons = {k.lower(): dict(v) for k, v in setting_info["buttons"].items()}

    # -- Initialise special values

    button_keyboard = setting_info["button_keyboard"]
    button_multimedia = setting_info["button_multimedia"]

    button_special = {}

    if setting_info["button_disable"] is not None:
        button_special["disable"] = setting_info["button_disable"]
        button_special["disabled"] = setting_info["button_disable"]

    if setting_info["button_dpi_switch"] is not None:
        button_special["dpi"] = setting_info["button_dpi_switch"]

    if setting_info["button_scroll_up"] is not None:
        button_special["scrollup"] = setting_info["button_scroll_up"]

    if setting_info["button_scroll_down"] is not None:
        button_special["scrolldown"] = setting_info["button_scroll_down"]
        button_special["scrolldwn"] = setting_info["button_scroll_down"]
        button_special["scrolldn"] = setting_info["button_scroll_down"]

    # -- Initialize keyboard layout

    keyboard_layout = {}
    keyboard_layout_name = "qwerty"

    if button_keyboard is not None:
        if "layout" in mapping["buttons"]:
            keyboard_layout_name = mapping["buttons"]["layout"].lower()

        if keyboard_layout_name not in LAYOUTS:
            raise ValueError("Unsupported layout '%s'" % keyboard_layout_name)

        keyboard_layout = build_layout(LAYOUTS[keyboard_layout_name])

    mm_layout = build_layout(layout_multimedia)

    # -- Craft packet

    packet_length = len(buttons) * setting_info["button_field_length"]
    packet = [0x00] * packet_length

    for button, value in [(k.lower(), v) for k, v in mapping["buttons"].items()]:
        if button == "layout":
            continue
        if button not in buttons:
            raise ValueError("Unknown button name '%s'" % button)
        buttons[button]["value"] = value

    for button, data in buttons.items():
        value = data["default"]
        if "value" in data and data["value"].lower() != "default":
            value = data["value"]
        value = value.lower()

        if value in buttons:
            packet[data["offset"]] = buttons[value]["id"]
        elif value in button_special:
            packet[data["offset"]] = button_special[value]
        elif value in mm_layout:
            packet[data["offset"]] = button_multimedia
            packet[data["offset"] + 1] = mm_layout[value]
        elif value in keyboard_layout:
            packet[data["offset"]] = button_keyboard
            packet[data["offset"] + 1] = keyboard_layout[value]
        else:
            raise ValueError("Unknown button, key or action '%s'" % value)

    return packet
def process_value ( setting_info , mapping ) : # -- Parse input values if type ( mapping ) in [ str , _unicode_type ] and REGEXP_PARAM_STRING . match ( mapping ) : is_valid , reason = is_buttons ( mapping , setting_info ) if not is_valid : raise ValueError ( reason ) mapping = parse_param_string ( mapping ) elif type ( mapping ) in [ str , _unicode_type ] and mapping . lower ( ) == "default" : mapping = { "buttons" : { } } elif type ( mapping ) is dict : pass else : raise ValueError ( "Invalid input value '%s'" % str ( mapping ) ) # -- Initialize mouse buttons buttons = { k . lower ( ) : dict ( v ) for k , v in setting_info [ "buttons" ] . items ( ) } # -- Initialise special values button_keyboard = setting_info [ "button_keyboard" ] button_multimedia = setting_info [ "button_multimedia" ] button_special = { } if setting_info [ "button_disable" ] is not None : button_special [ "disable" ] = setting_info [ "button_disable" ] button_special [ "disabled" ] = setting_info [ "button_disable" ] if setting_info [ "button_dpi_switch" ] is not None : button_special [ "dpi" ] = setting_info [ "button_dpi_switch" ] if setting_info [ "button_scroll_up" ] is not None : button_special [ "scrollup" ] = setting_info [ "button_scroll_up" ] if setting_info [ "button_scroll_down" ] is not None : button_special [ "scrolldown" ] = setting_info [ "button_scroll_down" ] button_special [ "scrolldwn" ] = setting_info [ "button_scroll_down" ] button_special [ "scrolldn" ] = setting_info [ "button_scroll_down" ] # -- Initialize keyboard layout keyboard_layout = { } keyboard_layout_name = "qwerty" if button_keyboard is not None : if "layout" in mapping [ "buttons" ] : keyboard_layout_name = mapping [ "buttons" ] [ "layout" ] . lower ( ) if keyboard_layout_name not in LAYOUTS : raise ValueError ( "Unsupported layout '%s'" % keyboard_layout_name ) keyboard_layout = build_layout ( LAYOUTS [ keyboard_layout_name ] ) mm_layout = build_layout ( layout_multimedia ) # -- Craft packet packet_length = len ( buttons ) * setting_info [ "button_field_length" ] packet = [ 0x00 ] * packet_length for button , value in [ ( k . lower ( ) , v ) for k , v in mapping [ "buttons" ] . items ( ) ] : if button == "layout" : continue if button not in buttons : raise ValueError ( "Unknown button name '%s'" % button ) buttons [ button ] [ "value" ] = value for button , data in buttons . items ( ) : value = data [ "default" ] if "value" in data and data [ "value" ] . lower ( ) != "default" : value = data [ "value" ] value = value . lower ( ) if value in buttons : packet [ data [ "offset" ] ] = buttons [ value ] [ "id" ] elif value in button_special : packet [ data [ "offset" ] ] = button_special [ value ] elif value in mm_layout : packet [ data [ "offset" ] ] = button_multimedia packet [ data [ "offset" ] + 1 ] = mm_layout [ value ] elif value in keyboard_layout : packet [ data [ "offset" ] ] = button_keyboard packet [ data [ "offset" ] + 1 ] = keyboard_layout [ value ] else : raise ValueError ( "Unknown button, key or action '%s'" % value ) return packet