Questions tagged [cgeventtap]
79 questions
20
votes
2 answers
Performing a double click using CGEventCreateMouseEvent()
I'm using the following code to simulate a click of the mouse:
void PostMouseEvent(CGMouseButton button, CGEventType type, const CGPoint point)
{
CGEventRef theEvent = CGEventCreateMouseEvent(NULL, type, point, button);
CGEventSetType(theEvent,…

Uri
- 1,275
- 6
- 17
- 26
15
votes
2 answers
CGEventTapCreateForPSN in Mavericks+ (GetCurrentProcess deprecated)
I am using CGEventTapCreateForPSN to trap and filter keys for my application. I'm not interested in intercepting events for other applications. I'm pretty sure an event tap is too heavy handed for my purpose, but I've been unable to find a better…

Jody Hagins
- 27,943
- 6
- 58
- 87
14
votes
1 answer
How do you use CGEventTapCreate in Swift?
Has anyone managed to get this function to work in Swift?
Here is a reference SO post from last year: Using CGEventTapCreate Trouble with parameters in Swift
Apple Doc:…

chrisp
- 2,181
- 4
- 27
- 35
5
votes
1 answer
Event taps: Varying results with CGEventPost, kCGSessionEventTap, kCGAnnotatedSessionEventTap, CGEventTapPostEvent
I'm running into a thorny problem with posting an event from an event tap. I'm tapping for NSSystemDefined at kCGHIDEventTap, then replacing the event with a new one. The problem I'm running in to is that depending on how I post the event, it's…

kevingessner
- 18,559
- 5
- 43
- 63
5
votes
1 answer
CGEventTapCreate returns null in macOS Mojave
I'm completely stuck with logic that's been working for many years now. I'm using this to listen to keyboard events (hotkeys) while the app is in background.
CFMachPortRef eventTap = CGEventTapCreate(kCGSessionEventTap,
…

Tiago
- 1,984
- 1
- 21
- 43
5
votes
1 answer
Cocoa: Simulating Command+Tab in CGEvent
I want to simulate Application Switcher in my app and I think CGEvent maybe can do that.
Well, after learning some basic information about CGEvent, I can simulate the key press Command + Tab. But the Application Switcher window just flashing by and…

Duelsol
- 149
- 9
5
votes
1 answer
Can't block capslock with CGEventTap
I'm using Quartz CGEventTap in an attempt to globally intercept capslock presses and block them (to have them do something useful instead). I succesfully detect capslock presses but have so far been unable to block them. My code (originating from…

Thor Frølich
- 664
- 5
- 18
5
votes
2 answers
Why Doesn't Key Down Event Mask Work, but Mask All Does?
I have a basic keystroke converter app in development. The conversion works with the following:
CFRunLoopSourceRef runLoopSource = NULL;
CFMachPortRef eventTap = CGEventTapCreate(kCGHIDEventTap, kCGHeadInsertEventTap, kCGEventTapOptionDefault,…

DenVog
- 4,226
- 3
- 43
- 72
4
votes
1 answer
CGEventTap blocks application input
I'm trying to use CGCreateEventTap to monitor global mouse clicks, however when I do this it seems to block interaction with my own app. Mouse clicks in other running apps work fine, but my own app (that is the DemoAppDelegate app) does not respond…

azymm
- 312
- 1
- 8
4
votes
0 answers
Keyboard and Mouse Simulation failed in macOS Pre-login Window
I am a newbie to launch agent and daemons.I have created a pre-login agent and it will launch my application when login window open.I can simulate the keyboard and mouse events with CGEventPost in the user session. Please refer the code
//For…

boopathy
- 427
- 2
- 9
- 20
4
votes
1 answer
Relaunch OS X app to execute CGEventTapCreate() when AXIsProcessTrusted() is true
One of my app's feature is detect keyDown event and do someting for some specific keys.
So, I use CGEventTapCreate to solve my problem and my code is like this:
if let tap = CGEventTapCreate(.CGHIDEventTap, .HeadInsertEventTap, .Default,…

Duelsol
- 149
- 9
4
votes
2 answers
Strange behaviour when posting CGEvent to PSN
EDIT - not getting much input on this so here's the skinny. I'm posting keyboard events to a PSN. I then switch to another window, post some more events (this time tat session level) and switch back to the first window. When I start posting to…

Ben Packard
- 26,102
- 25
- 102
- 183
4
votes
1 answer
OS X Intercept Keyboard Events to Password Forms Elements
I am currently creating a c program that counts all of the keys I press in a day and sorts the key types by amount, so I can tell which ones I press most often. It was more of a side project than anything else but I have become annoyed with the fact…

735Tesla
- 3,162
- 4
- 34
- 57
4
votes
2 answers
NSEvent `subtype` equivalent for CGEvent?
NSEvent has a method to get the event's subtype:
Getting Custom Event Information
– data1
– data2
– subtype
Can this same subtype be accessed from a CGEvent without first converting it to an NSEvent?
CGEventRef eventCG = ...;
NSEvent…

pkamb
- 33,281
- 23
- 160
- 191
3
votes
1 answer
Sending CGEvents keystrokes to background apps
I am trying to send enter key to a background app like this:
CGEventRef a = CGEventCreateKeyboardEvent(eventSource, 36, true);
CGEventRef b = CGEventCreateKeyboardEvent(eventSource, 36, false);
CGEventPostToPSN(&psn, a);
CGEventPostToPSN(&psn,…

Joe
- 33
- 3