Questions tagged [cgeventtap]
79 questions
0
votes
0 answers
Mouse event with CGEventCreateMouseEvent does not respect coordinates when screen zoomed in
I have a simple Objective C function used to perform mouse events (single clicks):
void click(CGPoint pt, int clickCount) {
CGEventRef theEvent = CGEventCreateMouseEvent(NULL, kCGEventLeftMouseDown, pt, kCGMouseButtonLeft);
…

Pablo Matias Gomez
- 6,614
- 7
- 38
- 72
0
votes
2 answers
CGEvent NSKeyDown only working if app is front most?
I am trying to automate some tasks (there's no applescript support) so I have to use CGEvents and post these events. Mouse clicking works fine, but NSKeyDown (enter) only works if I click on the app in the dock(which makes it front most…

user635064
- 6,219
- 12
- 54
- 100
0
votes
0 answers
Macos Application hangs when using NSDistributedNotificationCenter and CFRunLoopAddSource
I have MacOS application built using Qt. There I have created NSDistributedNotificationCenter to be notified when accessibility settings change (observing "com.apple.accessibility.api" ). Also I have CFRunLoopAddSource to monitor key pressed…

RuLoViC
- 825
- 7
- 23
0
votes
1 answer
Returning a `CGEvent` of my own creation in `NSEventTap`
Documentation for CGEventTapCallBack
here states:
CGEventRef event
The incoming event. This event is owned by the caller,
and you do not need to release it.
What happens if I wish to eat the event, and return NULL? Should I CFRelease…

P i
- 29,020
- 36
- 159
- 267
0
votes
1 answer
Is it safe to create `NSEvent object` then `CGEventPost` the `[ev CGEvent]` then exit the method?
I have the following Objective-C snippet:
void toggle()
{
NSEvent* down_event = [NSEvent keyEventWithType: NSEventTypeKeyDown
location: NSZeroPoint
modifierFlags:…

P i
- 29,020
- 36
- 159
- 267
0
votes
0 answers
How do I get the Process Serial Number of my own process?
I am trying to install an event tap for my own process to intercept mouse events.
For this I found the function CGEventTapCreateForPSN which expects a process' serial number as its first parameter. How do I get the PSN of my own process?…

user3700562
- 693
- 11
- 23
0
votes
1 answer
Crash When Accessing refcon:UnsafeMutableRawPointer? Inside CGEventTap Callback
I have a myCGEventCallback function for CGEventTap that takes parameter "refcon:UnsafeMutableRawPointer?".
I pass my main ViewController as a pointer to the callback using
let pointer =…

jl303
- 1,461
- 15
- 27
0
votes
0 answers
Sending keystroke event 'paste' to a specific application Mac
i am using a code to simulate a 'Paste ' to the frontmost application using carbon on MacOS. Now, i need to do that to a specific application not in frontmost. I am using this code so far with the use of PostToPsn :
ProcessSerialNumber psn;
…

hugo411
- 320
- 1
- 12
- 29
0
votes
1 answer
(Mac) creating keyboard events causes memory leaks
My app's memory usage goes up permanently, each time I create a keyboard event using Quartz Event Services.
The following is the problematic code inside of an infinite loop:
int keyCode = 0;
BOOL keyDownBool = FALSE;
while (TRUE) {
/*…

simsula
- 147
- 7
0
votes
0 answers
Waiting for an programmatic key press to be processed
Someone posted a snippet of code for programmatically pressing a key :
- (void)postCommandAndKey:(CGKeyCode)key {
CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStateCombinedSessionState);
CGEventRef keyDown =…

Arno Breker
- 35
- 5
0
votes
1 answer
CGEventTap mouse event position overwrite only possible when running app as root user?
I am developing a macOS app which takes control of the cursor. I am using a CGEvent Tap and I am adding some arithmetic to the CGEvents in order to offset the final mouse position. Although the app is in principle working as expected, in some cases…

fy data
- 195
- 1
- 9
0
votes
1 answer
Swift 3 CFRunLoopRun in Thread?
I just made a simple testing app to display keycode of keystrokes along with modifiers. It works fine for 3 keystrokes, then the app crashes. When it crashes, debug console just shows (LLDB) at the end. Any suggestion what might be causing this?…

jl303
- 1,461
- 15
- 27
0
votes
1 answer
CGEventRef KeyHandler - Xcode - Mac
So I have an app that when you press the numbers on your keyboard on top, it normally types the symbols.
But with the app it types the numbers.
But if I run it in xcode, everything works fine, but when i open the app outside of xcode it doesn't…

Damian Van de Kauter
- 15
- 1
- 9
0
votes
1 answer
NSWindow frozen while simulating mouse down event
After receiving a mouse down event, my NSWindow is frozen. I'm unable to capture which threads hang in Xcode. I'm using the following code to simulate a mouse event:
CGEventSourceRef eventSource =…

boopathy
- 427
- 2
- 9
- 20
0
votes
1 answer
Get window id from a click listener with CGEventTap (objective-c)
I'm trying to listen to all mouse clicks that the user makes. I need to know which window the user has clicked on (presumably by its CGWindowID). I am listening to all clicks through a CGEventTap, but now I can't find out how to get the window that…

torpedro
- 494
- 5
- 13