@@ -249,13 +249,12 @@ public static void RegisterHotkey(string hotkeys, string previousHotkey, Action<
249249
250250 public static void UnregisterHotkey ( string hotkey )
251251 {
252- if ( ! registeredHotkeys . TryGetValue ( ToKeyCode ( SplitHotkeyReversed ( hotkey ) . First ( ) ) , out var existingKeyRecord ) )
253- return ;
252+ var existingKeyRecord = GetRegisteredKeyRecord ( hotkey ) ;
254253
255- if ( ! existingKeyRecord . KeyComboRecords . Exists ( x => x . comboRaw == hotkey ) )
254+ if ( existingKeyRecord is null )
256255 return ;
257256
258- if ( ! hotkey . Contains ( '+' ) )
257+ if ( ! IsComboString ( hotkey ) )
259258 {
260259 existingKeyRecord . action -= existingKeyRecord . action ;
261260 existingKeyRecord . isSingleKeyRegistered = false ;
@@ -274,12 +273,24 @@ public static void UnregisterHotkey(string hotkey)
274273 registeredHotkeys . Remove ( existingKeyRecord . vk_code ) ;
275274 }
276275
276+ internal static KeyRecord GetRegisteredKeyRecord ( string hotkey )
277+ {
278+ if ( ! registeredHotkeys . TryGetValue ( ToKeyCode ( SplitHotkeyReversed ( hotkey ) . First ( ) ) , out var existingKeyRecord ) )
279+ return null ;
280+
281+ if ( IsComboString ( hotkey ) && ! existingKeyRecord . KeyComboRecords . Exists ( x => x . comboRaw == hotkey ) )
282+ return null ;
283+
284+ return existingKeyRecord ;
285+ }
286+
277287 private static int ToKeyCode ( string key )
278288 {
279289 return KeyInterop . VirtualKeyFromKey ( ( Key ) Enum . Parse ( typeof ( Key ) , key ) ) ;
280290 }
281291
282- private static IEnumerable < string > SplitHotkeyReversed ( string hotkeys ) => hotkeys . Split ( "+" , StringSplitOptions . RemoveEmptyEntries ) . Reverse ( ) ;
292+ private static IEnumerable < string > SplitHotkeyReversed ( string hotkeys )
293+ => hotkeys . Split ( "+" , StringSplitOptions . RemoveEmptyEntries ) . Reverse ( ) ;
283294
284295 private static string ConvertIncorrectKeyString ( string hotkey )
285296 {
@@ -332,6 +343,8 @@ private static string ConvertIncorrectKeyString(string hotkey)
332343 return newHotkey ;
333344 }
334345
346+ private static bool IsComboString ( string hotkey ) => hotkey . Contains ( '+' ) ;
347+
335348 #endregion key management
336349 }
337350}
0 commit comments