@@ -13,18 +13,7 @@ public class HotkeyModel
13
13
public bool Win { get ; set ; }
14
14
public bool Ctrl { get ; set ; }
15
15
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 ;
28
17
29
18
private static readonly Dictionary < Key , string > specialSymbolDictionary = new Dictionary < Key , string >
30
19
{
@@ -149,32 +138,36 @@ public override string ToString()
149
138
return string . Join ( " + " , keys ) ;
150
139
}
151
140
152
- private bool ValidateHotkey ( Key key )
141
+ public bool Validate ( )
153
142
{
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
+ }
169
163
}
170
- return true ;
171
164
}
172
165
173
166
public override bool Equals ( object obj )
174
167
{
175
168
if ( obj is HotkeyModel other )
176
169
{
177
- return ModifierKeys == other . ModifierKeys && CharKey == other . charKey ;
170
+ return ModifierKeys == other . ModifierKeys && CharKey == other . CharKey ;
178
171
}
179
172
else
180
173
{
0 commit comments