@@ -2,7 +2,7 @@ import Foundation
2
2
import GameController
3
3
import UIKit
4
4
5
- final class PlayInput : NSObject {
5
+ class PlayInput {
6
6
static let shared = PlayInput ( )
7
7
var actions = [ Action] ( )
8
8
var timeoutForBind = true
@@ -52,10 +52,10 @@ final class PlayInput: NSObject {
52
52
EditorController . shared. setKeyCode ( keyCode. rawValue)
53
53
}
54
54
}
55
- keyboard. button ( forKeyCode: GCKeyCode ( rawValue : 227 ) ) ? . pressedChangedHandler = { _, _, pressed in
55
+ keyboard. button ( forKeyCode: . leftGUI ) ? . pressedChangedHandler = { _, _, pressed in
56
56
PlayInput . lCmdPressed = pressed
57
57
}
58
- keyboard. button ( forKeyCode: GCKeyCode ( rawValue : 231 ) ) ? . pressedChangedHandler = { _, _, pressed in
58
+ keyboard. button ( forKeyCode: . rightGUI ) ? . pressedChangedHandler = { _, _, pressed in
59
59
PlayInput . rCmdPressed = pressed
60
60
}
61
61
keyboard. button ( forKeyCode: . leftAlt) ? . pressedChangedHandler = { _, _, pressed in
@@ -68,8 +68,6 @@ final class PlayInput: NSObject {
68
68
}
69
69
70
70
static public func cmdPressed( ) -> Bool {
71
- // return keyboard.button(forKeyCode: GCKeyCode(rawValue: 227))!.isPressed
72
- // || keyboard.button(forKeyCode: GCKeyCode(rawValue: 231))!.isPressed
73
71
return lCmdPressed || rCmdPressed
74
72
}
75
73
@@ -85,8 +83,8 @@ final class PlayInput: NSObject {
85
83
}
86
84
87
85
private static let FORBIDDEN : [ GCKeyCode ] = [
88
- GCKeyCode . init ( rawValue : 227 ) , // LCmd
89
- GCKeyCode . init ( rawValue : 231 ) , // RCmd
86
+ . leftGUI ,
87
+ . rightGUI ,
90
88
. leftAlt,
91
89
. rightAlt,
92
90
. printScreen
@@ -125,18 +123,13 @@ final class PlayInput: NSObject {
125
123
}
126
124
127
125
setup ( )
128
- // fix beep sound
129
- eliminateRedundantKeyPressEvents ( )
126
+
127
+ // Fix beep sound
128
+ AKInterface . shared!
129
+ . eliminateRedundantKeyPressEvents ( { self . dontIgnore ( ) } )
130
130
}
131
131
132
- private func eliminateRedundantKeyPressEvents( ) {
133
- // TODO later: should not be hard-coded
134
- let NSEventMaskKeyDown : UInt64 = 1024
135
- Dynamic . NSEvent. addLocalMonitorForEventsMatchingMask ( NSEventMaskKeyDown, handler: { event in
136
- if ( mode. visible && !EditorController. shared. editorMode) || PlayInput . cmdPressed ( ) {
137
- return event
138
- }
139
- return nil
140
- } as ResponseBlock )
132
+ func dontIgnore( ) -> Bool {
133
+ ( mode. visible && !EditorController. shared. editorMode) || PlayInput . cmdPressed ( )
141
134
}
142
135
}
0 commit comments