Questions tagged [cgeventtap]

79 questions
1
vote
1 answer

CGEventCreateKeyboardEvent on Desktop vs MacBook

Ola Folks, Once again I want to drink from the pool of knowledge shared by people using SO. I have written a small app for OSX that sends key events to an application. I am targeting OSX 10.5.x and newer. However, the problem exists when I build for…
ISDi
  • 165
  • 1
  • 2
  • 9
1
vote
0 answers

Intercept function-key strokes on Mac

I want to intercept function-key strokes in MacOS, not Fx keys, but specifically Volume Up/Down and Mute. Obviously, this should be done in a global way, not only when my program is frontmost. I read this can be achieved using a CGEventTap, but it…
Teejay
  • 7,210
  • 10
  • 45
  • 76
1
vote
1 answer

CGEventTapCreate and CFMachPortCreateRunLoopSource fails EXC_BAD_ACCESS

I am trying to tap into the HID events of OSX. I found a snippet for testing it. However my code always seem to fail with EXC_BAD_ACCESS at the CFMachPortCreateRunLoopSource line. It seems that downEventTap is null. Reading the documentation tells…
David Karlsson
  • 9,396
  • 9
  • 58
  • 103
1
vote
3 answers

Virtual keypress goes to wrong application

I have the following code to send virtual keypresses to a process given its pid NSRunningApplication* app = [NSRunningApplication runningApplicationWithProcessIdentifier: pid]; [app activateWithOptions:…
Pavan Manjunath
  • 27,404
  • 12
  • 99
  • 125
1
vote
1 answer

Stop Intercepting Keyboard Input While App Running - CGEventTap

What is the correct way to stop watching keyboard event taps using CGEventTap? I am building a simple background app that converts the output of specific keys. Thanks to this excellent post on CGEventTap, I've been able to enable the key conversion.…
DenVog
  • 4,226
  • 3
  • 43
  • 72
1
vote
1 answer

Mountain Lion Login Window CGEvent fails

I have an app which uses CGEvent taps to catch key presses and mouse events. Example .. CGEventTapCreate(kCGHIDEventTap, kCGTailAppendEventTap, 1, eventMask, keyUp, @"mydata"); I also generate events. Everything works…
drunknbass
  • 1,662
  • 1
  • 13
  • 19
0
votes
1 answer

Handling CGEventTaps in an NPAPI plugin

I'm trying to create an NPAPI plugin to listen to the Media Keys on a macbook and pass that to javascript to control things like pandora or soundcloud. I'm using Spotify's SPMediaKeyTap library, which just wraps CGEventTap running on a separate…
msfeldstein
  • 1,080
  • 1
  • 9
  • 18
0
votes
1 answer

Detecting internal or external devices in event tap

I am using an event tap in a Mac app to detect key presses and mouse movements. For the next step I would like to distinguish between an internal keyboard/trackpad and an external keyboard/mouse/trackpad. Does any one have any idea how to do this?
xizor
  • 1,554
  • 2
  • 16
  • 35
0
votes
0 answers

CGEventTapCreate returns NULL in macOS Ventura (13.4.1)

Intercepting keystrokes on macOS is a recurrent nightmare. I wrote this code 4 years ago and it worked. A couple of years on, macOS updated and it broke. This fixed it: CGEventTapCreate returns null in macOS Mojave Now it's broken again. …
P i
  • 29,020
  • 36
  • 159
  • 267
0
votes
1 answer

Safe to set CGEvent user data field?

The CGEvent type allows setting integer values for a specified list CGEventFields, one of which is the eventSourceUserData field. Is it safe to set this field to any value as determined by the program sending the event? Background / Use Case A…
0
votes
0 answers

CGEvent Key Listener for a text snippet app (Mac OS - Swift)

I am relatively new to Swift and currently working on a text snippet app. For that, the app should run in the background (as a menu bar application), get the pressed keys and append them to a string. The following implementation works fine but is…
0
votes
1 answer

CGEventTapCreate detecting multiple keyboard inputs

I'm working on a macOS menubar app that locks any mouse events. What I'm trying to achieve is that after sending mouse events to the CGEventRef based callback, I cannot click anywhere (naturally) but the problem is I cannot quit the loop because of…
Ömürcan Cengiz
  • 2,085
  • 3
  • 22
  • 28
0
votes
1 answer

How to suppress function keys in macOS / Quartz / pynput?

The example given in the pynput documentation is: def darwin_intercept(event_type, event): import Quartz length, chars = Quartz.CGEventKeyboardGetUnicodeString( event, 100, None, None) if length > 0 and chars == 'x': #…
Bernd
  • 11
  • 3
0
votes
1 answer

Cannot send a keystroke in swift gui application on macOS 11.6 (Big Sur) - "Command Line Tool" works

I want to use Swift (Xcode 13.2.1) to send a Cmd-C and Cmd-V to copy selected text in macOS 11.6 (Big Sur) as described in several StackOverflow posts (e.g. How to obtain the selected text from the frontmost application in macOS?). I was carefully…
floek
  • 31
  • 4
0
votes
1 answer

Catch mouse events with CGEvent.tapCreate in Swift on MacOS

I am novice Swift coder trying to catch mouse events as well as keyboard events. It seems I am only doing the latter. The main goal is to allow for «tap-to-click» with Magic Mouse 2 and avoid its loud clicking sound. Fully working sample…
Andreas F
  • 133
  • 1
  • 8