@@ -101,7 +101,7 @@ bool KeyMapping::hasMeta() const
101101 return keys.meta != KEY_CODE ::KEY_IGNORE ;
102102}
103103
104- bool KeyMapping::toString (char * pOutStr ) const
104+ std::string KeyMapping::toString () const
105105{
106106 // Figure out if the keycode is for mouse or keyboard and print the name of
107107 // the respective key/mouse button to `asciiSub`
@@ -115,23 +115,21 @@ bool KeyMapping::toString(char* pOutStr) const
115115 mouseKeyCodeToString (keys.input .value .mouseKeyCode , (char *)&asciiSub, 20 );
116116 break ;
117117 default :
118- strcpy (asciiSub, " NOT VALID" );
119118 debug (LOG_WZ , " Encountered invalid key mapping source %u while converting mapping to string!" , static_cast <unsigned int >(keys.input .source ));
120- return true ;
119+ return std::string ( " NOT VALID " ) ;
121120 }
122121
123122 if (hasMeta ())
124123 {
125124 char asciiMeta[20 ] = " \0 " ;
126125 keyScanToString (keys.meta , (char *)&asciiMeta, 20 );
127126
128- sprintf (pOutStr, " %s %s" , asciiMeta, asciiSub);
127+ return astringf ( " %s %s" , asciiMeta, asciiSub);
129128 }
130129 else
131130 {
132- sprintf (pOutStr, " %s " , asciiSub);
131+ return std::string ( asciiSub);
133132 }
134- return true ;
135133}
136134
137135
@@ -185,10 +183,10 @@ KeyMapping& KeyMappings::add(const KeyCombination keys, const KeyFunctionInfo& i
185183 return keyMappings.back ();
186184}
187185
188- nonstd::optional<std::reference_wrapper<KeyMapping>> KeyMappings::get (const KeyFunctionInfo& info , const KeyMappingSlot slot)
186+ nonstd::optional<std::reference_wrapper<KeyMapping>> KeyMappings::get (const std::string& name , const KeyMappingSlot slot)
189187{
190- auto mapping = std::find_if (keyMappings.begin (), keyMappings.end (), [&info , slot](const KeyMapping& mapping) {
191- return mapping.info .name == info. name && mapping.slot == slot;
188+ auto mapping = std::find_if (keyMappings.begin (), keyMappings.end (), [&name , slot](const KeyMapping& mapping) {
189+ return mapping.info .name == name && mapping.slot == slot;
192190 });
193191 if (mapping != keyMappings.end ())
194192 {
@@ -198,6 +196,11 @@ nonstd::optional<std::reference_wrapper<KeyMapping>> KeyMappings::get(const KeyF
198196 return nonstd::nullopt ;
199197}
200198
199+ nonstd::optional<std::reference_wrapper<KeyMapping>> KeyMappings::get (const KeyFunctionInfo& info, const KeyMappingSlot slot)
200+ {
201+ return get (info.name , slot);
202+ }
203+
201204std::vector<std::reference_wrapper<KeyMapping>> KeyMappings::find (const KEY_CODE meta, const KeyMappingInput input)
202205{
203206 std::vector<std::reference_wrapper<KeyMapping>> matches;
0 commit comments