@@ -13,18 +13,7 @@ public class HotkeyModel
1313 public bool Win { get ; set ; }
1414 public bool Ctrl { get ; set ; }
1515
16- private Key charKey = Key . None ;
17- public Key CharKey
18- {
19- get => charKey ;
20- set
21- {
22- if ( ValidateHotkey ( value ) )
23- {
24- charKey = value ;
25- }
26- }
27- }
16+ public Key CharKey { get ; set ; } = Key . None ;
2817
2918 private static readonly Dictionary < Key , string > specialSymbolDictionary = new Dictionary < Key , string >
3019 {
@@ -149,32 +138,36 @@ public override string ToString()
149138 return string . Join ( " + " , keys ) ;
150139 }
151140
152- private bool ValidateHotkey ( Key key )
141+ public bool Validate ( )
153142 {
154- HashSet < Key > invalidKeys = new ( )
155- {
156- Key . LeftAlt , Key . RightAlt ,
157- Key . LeftCtrl , Key . RightCtrl ,
158- Key . LeftShift , Key . RightShift ,
159- Key . LWin , Key . RWin ,
160- } ;
161-
162- if ( invalidKeys . Contains ( key ) )
163- {
164- return false ;
165- }
166- if ( ModifierKeys == ModifierKeys . None )
167- {
168- return key >= Key . F1 && key <= Key . F24 ;
143+ switch ( CharKey )
144+ {
145+ case Key . LeftAlt :
146+ case Key . RightAlt :
147+ case Key . LeftCtrl :
148+ case Key . RightCtrl :
149+ case Key . LeftShift :
150+ case Key . RightShift :
151+ case Key . LWin :
152+ case Key . RWin :
153+ return false ;
154+ default :
155+ if ( ModifierKeys == ModifierKeys . None )
156+ {
157+ return CharKey >= Key . F1 && CharKey <= Key . F24 ;
158+ }
159+ else
160+ {
161+ return CharKey != Key . None ;
162+ }
169163 }
170- return true ;
171164 }
172165
173166 public override bool Equals ( object obj )
174167 {
175168 if ( obj is HotkeyModel other )
176169 {
177- return ModifierKeys == other . ModifierKeys && CharKey == other . charKey ;
170+ return ModifierKeys == other . ModifierKeys && CharKey == other . CharKey ;
178171 }
179172 else
180173 {
0 commit comments