@@ -35,17 +35,8 @@ static KeyboardShortcut()
3535 /// </summary>
3636 public static readonly KeyboardShortcut Empty = new ( ) ;
3737
38- /// <summary>
39- /// All KeyCode values that can be used in a keyboard shortcut.
40- /// </summary>
41- public static readonly IEnumerable < KeyCode > AllKeyCodes = ( KeyCode [ ] ) Enum . GetValues ( typeof ( KeyCode ) ) ;
42-
4338 // Don't block hotkeys if mouse is being pressed, e.g. when shooting and trying to strafe
44- private static readonly KeyCode [ ] _modifierBlockKeyCodes = AllKeyCodes . Except ( new [ ]
45- {
46- KeyCode . Mouse0 , KeyCode . Mouse1 , KeyCode . Mouse2 , KeyCode . Mouse3 , KeyCode . Mouse4 , KeyCode . Mouse5 ,
47- KeyCode . Mouse6 , KeyCode . None
48- } ) . ToArray ( ) ;
39+ private static KeyCode [ ] modifierBlockKeyCodes ;
4940
5041 private readonly KeyCode [ ] _allKeys ;
5142
@@ -122,7 +113,7 @@ public bool IsDown()
122113 var mainKey = MainKey ;
123114 if ( mainKey == KeyCode . None ) return false ;
124115
125- return Input . GetKeyDown ( mainKey ) && ModifierKeyTest ( ) ;
116+ return UnityInput . Current . GetKeyDown ( mainKey ) && ModifierKeyTest ( ) ;
126117 }
127118
128119 /// <summary>
@@ -133,7 +124,7 @@ public bool IsPressed()
133124 var mainKey = MainKey ;
134125 if ( mainKey == KeyCode . None ) return false ;
135126
136- return Input . GetKey ( mainKey ) && ModifierKeyTest ( ) ;
127+ return UnityInput . Current . GetKey ( mainKey ) && ModifierKeyTest ( ) ;
137128 }
138129
139130 /// <summary>
@@ -144,18 +135,23 @@ public bool IsUp()
144135 var mainKey = MainKey ;
145136 if ( mainKey == KeyCode . None ) return false ;
146137
147- return Input . GetKeyUp ( mainKey ) && ModifierKeyTest ( ) ;
138+ return UnityInput . Current . GetKeyUp ( mainKey ) && ModifierKeyTest ( ) ;
148139 }
149140
150141 private bool ModifierKeyTest ( )
151142 {
152143 var allKeys = _allKeys ;
153144 var mainKey = MainKey ;
154145
155- var allModifiersPressed = allKeys . All ( c => c == mainKey || Input . GetKey ( c ) ) ;
146+ var allModifiersPressed = allKeys . All ( c => c == mainKey || UnityInput . Current . GetKey ( c ) ) ;
156147 if ( ! allModifiersPressed ) return false ;
157148
158- var noOtherModifiersPressed = _modifierBlockKeyCodes . All ( c => ! Input . GetKey ( c ) || allKeys . Contains ( c ) ) ;
149+ // Lazy init to make sure the game is initialized, and we're in main thread before calling UnityInput.Current
150+ modifierBlockKeyCodes ??= UnityInput . Current . SupportedKeyCodes . Except ( [ KeyCode . Mouse0 , KeyCode . Mouse1 ,
151+ KeyCode . Mouse2 , KeyCode . Mouse3 , KeyCode . Mouse4 , KeyCode . Mouse5 , KeyCode . Mouse6 , KeyCode . None
152+ ] ) . ToArray ( ) ;
153+
154+ bool noOtherModifiersPressed = modifierBlockKeyCodes . All ( c => ! UnityInput . Current . GetKey ( c ) || allKeys . Contains ( c ) ) ;
159155 return noOtherModifiersPressed ;
160156 }
161157
0 commit comments