@@ -193,32 +193,37 @@ class GameController {
193193 }
194194
195195 func buttonPressHandler( config: KeyMap ) {
196- let source = CGEventSource ( stateID: . hidSystemState)
196+ DispatchQueue . main. async {
197+ let source = CGEventSource ( stateID: . hidSystemState)
197198
198- if config. keyCode >= 0 {
199- DispatchQueue . main. async {
199+ if config. keyCode >= 0 {
200+ metaKeyEvent ( config: config, keyDown: true )
201+
200202 let event = CGEvent ( keyboardEventSource: source, virtualKey: CGKeyCode ( config. keyCode) , keyDown: true )
201203 event? . flags = CGEventFlags ( rawValue: CGEventFlags . RawValue ( config. modifiers) )
202204 event? . post ( tap: . cghidEventTap)
203205 }
204- }
205206
206- if config. mouseButton >= 0 {
207- let mousePos = NSEvent . mouseLocation
208- let cursorPos = CGPoint ( x: mousePos. x, y: NSScreen . main!. frame. maxY - mousePos. y)
207+ if config. mouseButton >= 0 {
208+ let mousePos = NSEvent . mouseLocation
209+ let cursorPos = CGPoint ( x: mousePos. x, y: NSScreen . main!. frame. maxY - mousePos. y)
209210
210- var event : CGEvent ?
211- if config. mouseButton == 0 {
212- event = CGEvent ( mouseEventSource: source, mouseType: . leftMouseDown, mouseCursorPosition: cursorPos, mouseButton: . left)
213- self . isLeftDragging = true
214- } else if config. mouseButton == 1 {
215- event = CGEvent ( mouseEventSource: source, mouseType: . rightMouseDown, mouseCursorPosition: cursorPos, mouseButton: . right)
216- self . isRightDragging = true
217- } else if config. mouseButton == 2 {
218- event = CGEvent ( mouseEventSource: source, mouseType: . otherMouseDown, mouseCursorPosition: cursorPos, mouseButton: . center)
219- self . isCenterDragging = true
211+ metaKeyEvent ( config: config, keyDown: true )
212+
213+ var event : CGEvent ?
214+ if config. mouseButton == 0 {
215+ event = CGEvent ( mouseEventSource: source, mouseType: . leftMouseDown, mouseCursorPosition: cursorPos, mouseButton: . left)
216+ self . isLeftDragging = true
217+ } else if config. mouseButton == 1 {
218+ event = CGEvent ( mouseEventSource: source, mouseType: . rightMouseDown, mouseCursorPosition: cursorPos, mouseButton: . right)
219+ self . isRightDragging = true
220+ } else if config. mouseButton == 2 {
221+ event = CGEvent ( mouseEventSource: source, mouseType: . otherMouseDown, mouseCursorPosition: cursorPos, mouseButton: . center)
222+ self . isCenterDragging = true
223+ }
224+ event? . flags = CGEventFlags ( rawValue: CGEventFlags . RawValue ( config. modifiers) )
225+ event? . post ( tap: . cghidEventTap)
220226 }
221- event? . post ( tap: . cghidEventTap)
222227 }
223228 }
224229
@@ -228,32 +233,34 @@ class GameController {
228233 }
229234
230235 func buttonReleaseHandler( config: KeyMap ) {
231- let source = CGEventSource ( stateID: . hidSystemState)
232-
233- if config. keyCode >= 0 {
234- DispatchQueue . main. async {
235- let event = CGEvent ( keyboardEventSource: source, virtualKey: CGKeyCode ( config. keyCode) , keyDown: false )
236- event? . flags = CGEventFlags ( rawValue: CGEventFlags . RawValue ( config. modifiers) )
237- event? . post ( tap: . cghidEventTap)
236+ DispatchQueue . main. async {
237+ let source = CGEventSource ( stateID: . hidSystemState)
238+
239+ if config. keyCode >= 0 {
240+ let event = CGEvent ( keyboardEventSource: source, virtualKey: CGKeyCode ( config. keyCode) , keyDown: false )
241+ event? . flags = CGEventFlags ( rawValue: CGEventFlags . RawValue ( config. modifiers) )
242+ event? . post ( tap: . cghidEventTap)
243+
244+ metaKeyEvent ( config: config, keyDown: false )
238245 }
239- }
240246
241- if config. mouseButton >= 0 {
242- let mousePos = NSEvent . mouseLocation
243- let cursorPos = CGPoint ( x: mousePos. x, y: NSScreen . main!. frame. maxY - mousePos. y)
244-
245- var event : CGEvent ?
246- if config. mouseButton == 0 {
247- event = CGEvent ( mouseEventSource: source, mouseType: . leftMouseUp, mouseCursorPosition: cursorPos, mouseButton: . left)
248- self . isLeftDragging = false
249- } else if config. mouseButton == 1 {
250- event = CGEvent ( mouseEventSource: source, mouseType: . rightMouseUp, mouseCursorPosition: cursorPos, mouseButton: . right)
251- self . isRightDragging = false
252- } else if config. mouseButton == 2 {
253- event = CGEvent ( mouseEventSource: source, mouseType: . otherMouseUp, mouseCursorPosition: cursorPos, mouseButton: . center)
254- self . isCenterDragging = false
247+ if config. mouseButton >= 0 {
248+ let mousePos = NSEvent . mouseLocation
249+ let cursorPos = CGPoint ( x: mousePos. x, y: NSScreen . main!. frame. maxY - mousePos. y)
250+
251+ var event : CGEvent ?
252+ if config. mouseButton == 0 {
253+ event = CGEvent ( mouseEventSource: source, mouseType: . leftMouseUp, mouseCursorPosition: cursorPos, mouseButton: . left)
254+ self . isLeftDragging = false
255+ } else if config. mouseButton == 1 {
256+ event = CGEvent ( mouseEventSource: source, mouseType: . rightMouseUp, mouseCursorPosition: cursorPos, mouseButton: . right)
257+ self . isRightDragging = false
258+ } else if config. mouseButton == 2 {
259+ event = CGEvent ( mouseEventSource: source, mouseType: . otherMouseUp, mouseCursorPosition: cursorPos, mouseButton: . center)
260+ self . isCenterDragging = false
261+ }
262+ event? . post ( tap: . cghidEventTap)
255263 }
256- event? . post ( tap: . cghidEventTap)
257264 }
258265 }
259266
@@ -337,7 +344,6 @@ class GameController {
337344 func batteryChangeHandler( newState: JoyCon . BatteryStatus , oldState: JoyCon . BatteryStatus ) {
338345 self . updateControllerIcon ( )
339346
340- Swift . print ( " *** battery change: \( oldState. rawValue) -> \( newState. rawValue) " )
341347 if newState == . full && oldState != . unknown {
342348 AppNotifications . notifyBatteryFullCharge ( self )
343349 }
0 commit comments