Add more button mapping options

This commit is contained in:
dokutan 2021-03-29 00:29:34 +02:00
parent 40eef1cf1b
commit f1e8ac1af7
3 changed files with 28 additions and 10 deletions

View file

@ -33,19 +33,23 @@ const uint8_t rd_mouse::_c_dpi_2_min = 0x00, rd_mouse::_c_dpi_2_max = 0x01;
//name → keycode //name → keycode
std::map< std::string, std::array<uint8_t, 4> > rd_mouse::_c_keycodes = { std::map< std::string, std::array<uint8_t, 4> > rd_mouse::_c_keycodes = {
{ "forward", { 0x85, 0x00, 0x00, 0x00 } },
{ "backward", { 0x84, 0x00, 0x00, 0x00 } },
{ "dpi+", { 0x8a, 0x00, 0x00, 0x00 } },
{ "dpi-", { 0x89, 0x00, 0x00, 0x00 } },
{ "dpi-cycle", { 0x88, 0x00, 0x00, 0x00 } },
{ "report_rate+", { 0x97, 0x00, 0x00, 0x00 } },
{ "report_rate-", { 0x98, 0x00, 0x00, 0x00 } },
{ "scroll_up", { 0x8b, 0x00, 0x00, 0x00 } },
{ "scroll_down", { 0x8c, 0x00, 0x00, 0x00 } },
{ "left", { 0x81, 0x00, 0x00, 0x00 } }, { "left", { 0x81, 0x00, 0x00, 0x00 } },
{ "right", { 0x82, 0x00, 0x00, 0x00 } }, { "right", { 0x82, 0x00, 0x00, 0x00 } },
{ "middle", { 0x83, 0x00, 0x00, 0x00 } }, { "middle", { 0x83, 0x00, 0x00, 0x00 } },
{ "backward", { 0x84, 0x00, 0x00, 0x00 } },
{ "forward", { 0x85, 0x00, 0x00, 0x00 } },
{ "dpi-cycle", { 0x88, 0x00, 0x00, 0x00 } },
{ "dpi-", { 0x89, 0x00, 0x00, 0x00 } },
{ "dpi+", { 0x8a, 0x00, 0x00, 0x00 } },
{ "scroll_up", { 0x8b, 0x00, 0x00, 0x00 } },
{ "scroll_down", { 0x8c, 0x00, 0x00, 0x00 } },
{ "profile_switch", { 0x8d, 0x00, 0x00, 0x00 } }, { "profile_switch", { 0x8d, 0x00, 0x00, 0x00 } },
{ "profile+", { 0x94, 0x00, 0x00, 0x00 } },
{ "profile-", { 0x95, 0x00, 0x00, 0x00 } },
{ "report_rate+", { 0x97, 0x00, 0x00, 0x00 } },
{ "report_rate-", { 0x98, 0x00, 0x00, 0x00 } },
{ "dpi_led_toggle", { 0x9b, 0x01, 0x00, 0x00 } },
{ "reset_settings", { 0x9b, 0x02, 0x00, 0x00 } },
{ "led_mode_switch", { 0x9b, 0x04, 0x00, 0x00 } }, { "led_mode_switch", { 0x9b, 0x04, 0x00, 0x00 } },
{ "none", { 0x00, 0x00, 0x00, 0x00 } }, { "none", { 0x00, 0x00, 0x00, 0x00 } },
{ "media_play", { 0x8e, 0x01, 0xcd, 0x00 } }, { "media_play", { 0x8e, 0x01, 0xcd, 0x00 } },

View file

@ -778,8 +778,16 @@ int rd_mouse::_i_decode_button_mapping( std::array<uint8_t, 4>& bytes, std::stri
int rd_mouse::_i_encode_button_mapping( std::string& mapping, std::array<uint8_t, 4>& bytes ){ int rd_mouse::_i_encode_button_mapping( std::string& mapping, std::array<uint8_t, 4>& bytes ){
// raw byte values
if( std::regex_match( mapping, std::regex("0x[0-9a-fA-F]{8}") ) ){
bytes[0] = std::stoi( mapping.substr(2, 2) , 0, 16 );
bytes[1] = std::stoi( mapping.substr(4, 2) , 0, 16 );
bytes[2] = std::stoi( mapping.substr(6, 2) , 0, 16 );
bytes[3] = std::stoi( mapping.substr(8, 2) , 0, 16 );
// is string in _c_keycodes? mousebuttons/special functions and media controls // is string in _c_keycodes? mousebuttons/special functions and media controls
if( _c_keycodes.find(mapping) != _c_keycodes.end() ){ } else if( _c_keycodes.find(mapping) != _c_keycodes.end() ){
bytes[0] = _c_keycodes[mapping][0]; bytes[0] = _c_keycodes[mapping][0];
bytes[1] = _c_keycodes[mapping][1]; bytes[1] = _c_keycodes[mapping][1];

View file

@ -19,6 +19,8 @@ A button on the mouse can be mapped to one function out of the following categor
- Media controls (only available for compatibility, use the Media_* keyboard keys if possible) - Media controls (only available for compatibility, use the Media_* keyboard keys if possible)
- Example: ``media_play`` - Example: ``media_play``
Additionally it is possible to specify the raw bytes of the mapping, this is intended for debugging and testing. Example: ``0x11aa22bb``
The following sections list all valid button mappings. The following sections list all valid button mappings.
## Media controls ## Media controls
@ -61,7 +63,11 @@ left
right right
middle middle
profile_switch profile_switch
profile+
profile-
led_mode_switch led_mode_switch
dpi_led_toggle
reset_settings
none none
## Compatibility functions (these are only handled by the official software and are mostly redundant) ## Compatibility functions (these are only handled by the official software and are mostly redundant)