Skip to content

Commit 41e9d2a

Browse files
committed
Fixed wrong CGSession used with the events posted.
1 parent c5c8dd9 commit 41e9d2a

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

Sources/SendKeysLib/KeyPresser.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ public class KeyPresser {
2121
let keyDownEvent = try! createKeyEvent(key: key, modifiers: modifiers, keyDown: true)
2222

2323
if self.application == nil {
24-
keyDownEvent?.post(tap: CGEventTapLocation.cghidEventTap)
24+
keyDownEvent?.post(tap: CGEventTapLocation.cgSessionEventTap)
2525
} else {
2626
if #available(OSX 10.11, *) {
2727
keyDownEvent?.postToPid(self.application!.processIdentifier)
2828
} else {
29-
keyDownEvent?.post(tap: CGEventTapLocation.cghidEventTap)
29+
keyDownEvent?.post(tap: CGEventTapLocation.cgSessionEventTap)
3030
}
3131
}
3232

@@ -37,12 +37,12 @@ public class KeyPresser {
3737
let keyUpEvent = try! createKeyEvent(key: key, modifiers: modifiers, keyDown: false)
3838

3939
if self.application == nil {
40-
keyUpEvent?.post(tap: CGEventTapLocation.cghidEventTap)
40+
keyUpEvent?.post(tap: CGEventTapLocation.cgSessionEventTap)
4141
} else {
4242
if #available(OSX 10.11, *) {
4343
keyUpEvent?.postToPid(self.application!.processIdentifier)
4444
} else {
45-
keyUpEvent?.post(tap: CGEventTapLocation.cghidEventTap)
45+
keyUpEvent?.post(tap: CGEventTapLocation.cgSessionEventTap)
4646
}
4747
}
4848

@@ -54,12 +54,12 @@ public class KeyPresser {
5454
key: key, modifiers: modifiers, keyDown: false, parentEventSource: CGEventSource(event: event))
5555

5656
if self.application == nil {
57-
keyUpEvent?.post(tap: CGEventTapLocation.cghidEventTap)
57+
keyUpEvent?.post(tap: CGEventTapLocation.cgSessionEventTap)
5858
} else {
5959
if #available(OSX 10.11, *) {
6060
keyUpEvent?.postToPid(self.application!.processIdentifier)
6161
} else {
62-
keyUpEvent?.post(tap: CGEventTapLocation.cghidEventTap)
62+
keyUpEvent?.post(tap: CGEventTapLocation.cgSessionEventTap)
6363
}
6464
}
6565

Sources/SendKeysLib/MouseController.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ class MouseController {
6767
mouseEventSource: nil, mouseType: downMouseType, mouseCursorPosition: resolvedLocation, mouseButton: button)
6868
downEvent?.setIntegerValueField(.mouseEventClickState, value: Int64(clickCount))
6969
downEvent?.flags = flags
70-
downEvent?.post(tap: CGEventTapLocation.cghidEventTap)
70+
downEvent?.post(tap: CGEventTapLocation.cgSessionEventTap)
7171
let eventSource = CGEventSource(event: downEvent)
7272

7373
let upEvent = CGEvent(
7474
mouseEventSource: eventSource, mouseType: upMouseType, mouseCursorPosition: resolvedLocation,
7575
mouseButton: button)
76-
upEvent?.post(tap: CGEventTapLocation.cghidEventTap)
76+
upEvent?.post(tap: CGEventTapLocation.cgSessionEventTap)
7777
}
7878

7979
func down(_ location: CGPoint?, button: CGMouseButton, flags: CGEventFlags) {
@@ -83,7 +83,7 @@ class MouseController {
8383
let downEvent = CGEvent(
8484
mouseEventSource: nil, mouseType: downMouseType, mouseCursorPosition: resolvedLocation, mouseButton: button)
8585
downEvent?.flags = flags
86-
downEvent?.post(tap: CGEventTapLocation.cghidEventTap)
86+
downEvent?.post(tap: CGEventTapLocation.cgSessionEventTap)
8787

8888
downButtons.insert(button)
8989
}
@@ -95,7 +95,7 @@ class MouseController {
9595
let upEvent = CGEvent(
9696
mouseEventSource: nil, mouseType: upMouseType, mouseCursorPosition: resolvedLocation,
9797
mouseButton: button)
98-
upEvent?.post(tap: CGEventTapLocation.cghidEventTap)
98+
upEvent?.post(tap: CGEventTapLocation.cgSessionEventTap)
9999
downButtons.remove(button)
100100
}
101101

@@ -118,7 +118,7 @@ class MouseController {
118118
mouseEventSource: nil, mouseType: downMouseType, mouseCursorPosition: resolvedStart, mouseButton: button
119119
)
120120
downEvent?.flags = flags
121-
downEvent?.post(tap: CGEventTapLocation.cghidEventTap)
121+
downEvent?.post(tap: CGEventTapLocation.cgSessionEventTap)
122122
eventSource = CGEventSource(event: downEvent)
123123
}
124124

@@ -127,7 +127,7 @@ class MouseController {
127127
if !downButtons.contains(button) {
128128
let upEvent = CGEvent(
129129
mouseEventSource: eventSource, mouseType: upMouseType, mouseCursorPosition: end, mouseButton: button)
130-
upEvent?.post(tap: CGEventTapLocation.cghidEventTap)
130+
upEvent?.post(tap: CGEventTapLocation.cgSessionEventTap)
131131
}
132132
}
133133

@@ -188,7 +188,7 @@ class MouseController {
188188
event?.setIntegerValueField(field, value: Int64(amount * -1))
189189
event?.flags = flags
190190

191-
event?.post(tap: CGEventTapLocation.cghidEventTap)
191+
event?.post(tap: CGEventTapLocation.cgSessionEventTap)
192192
} else {
193193
fatalError("Scrolling is only available on 10.13 or later\n")
194194
}
@@ -207,7 +207,7 @@ class MouseController {
207207
mouseEventSource: eventSource, mouseType: moveType, mouseCursorPosition: location,
208208
mouseButton: button ?? CGMouseButton.left)
209209
moveEvent?.flags = flags
210-
moveEvent?.post(tap: CGEventTapLocation.cghidEventTap)
210+
moveEvent?.post(tap: CGEventTapLocation.cgSessionEventTap)
211211
}
212212

213213
private func getEventType(_ mouseType: mouseEventType, _ button: CGMouseButton? = nil) -> CGEventType {

Sources/SendKeysLib/MousePosition.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class MousePosition: ParsableCommand {
113113

114114
guard
115115
let eventTap = CGEvent.tapCreate(
116-
tap: .cghidEventTap, place: .tailAppendEventTap, options: .defaultTap,
116+
tap: .cgSessionEventTap, place: .tailAppendEventTap, options: .defaultTap,
117117
eventsOfInterest: CGEventMask(eventMask),
118118
callback: {
119119
(proxy: CGEventTapProxy, eventType: CGEventType, event: CGEvent, refcon: UnsafeMutableRawPointer?)

Sources/SendKeysLib/TerminationListener.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class TerminationListener {
4242

4343
guard
4444
let eventTap = CGEvent.tapCreate(
45-
tap: .cghidEventTap, place: .tailAppendEventTap, options: .defaultTap,
45+
tap: .cgSessionEventTap, place: .tailAppendEventTap, options: .defaultTap,
4646
eventsOfInterest: CGEventMask(eventMask),
4747
callback: {
4848
(proxy: CGEventTapProxy, eventType: CGEventType, event: CGEvent, refcon: UnsafeMutableRawPointer?)

0 commit comments

Comments
 (0)