cgeventtap

CGEventTap blocks application input

丶灬走出姿态 提交于 2019-12-05 17:24:29
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 completely. I can drag the main window for the app, but the red/yellow/green window buttons are greyed out. And the DemoApp's menu is unclickable as well. This seems really strange to me, and I've been unable to figure it out. Examples of using event taps are few and far between, so any advice is greatly appreciated. #import "DemoAppDelegate.h"

Event taps: Varying results with CGEventPost, kCGSessionEventTap, kCGAnnotatedSessionEventTap, CGEventTapPostEvent

送分小仙女□ 提交于 2019-12-05 15:23:20
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 being seen only by some applications. My test applications are Opera, Firefox, Quicksilver, and Xcode. Here are the different techniques I've tried within my event tap callback, with results. I'm expecting an action (the "correct response") from each app; "system beep" means the nothing-is-bound-to-that-key system sound. Create a new event, and return

CGEventCreateKeyboardEvent and CGEventTapLocation

岁酱吖の 提交于 2019-12-05 04:05:24
问题 I'm having a hard time dealing with custom keyboard events. I want to be able to send any key with / without kCGEventFlagMasks like command, alt, ctrl, shift... e.g. I want to send the current frontmost app, let's assume it's TextEdit, the key combo cmd+t, which should show the font window. But currently only t is added to the current document of TextEdit. I tried posting the event with custom set CGEventFlags and alternatively generating keyDown and keyUp events for cmd around the t event.

CGEventCreateKeyboardEvent and CGEventTapLocation

白昼怎懂夜的黑 提交于 2019-12-03 22:09:14
I'm having a hard time dealing with custom keyboard events. I want to be able to send any key with / without kCGEventFlagMasks like command, alt, ctrl, shift... e.g. I want to send the current frontmost app, let's assume it's TextEdit, the key combo cmd+t, which should show the font window. But currently only t is added to the current document of TextEdit. I tried posting the event with custom set CGEventFlags and alternatively generating keyDown and keyUp events for cmd around the t event. The free app Key Codes shows me when I use the CGEventFlags set, that cmd+t has been pressed, but this

CGEventTapCreateForPSN in Mavericks+ (GetCurrentProcess deprecated)

我们两清 提交于 2019-12-03 16:05:11
问题 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 way, and using the event tap works. Specifically, this code does what I want. GetCurrentProcess(&psn); CFMachPortRef eventTap = CGEventTapCreateForPSN( &psn, kCGHeadInsertEventTap, kCGEventTapOptionDefault, CGEventMaskBit(kCGEventKeyDown) |

CGEventTapCreateForPSN in Mavericks+ (GetCurrentProcess deprecated)

守給你的承諾、 提交于 2019-12-03 05:18:07
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 way, and using the event tap works. Specifically, this code does what I want. GetCurrentProcess(&psn); CFMachPortRef eventTap = CGEventTapCreateForPSN( &psn, kCGHeadInsertEventTap, kCGEventTapOptionDefault, CGEventMaskBit(kCGEventKeyDown) | CGEventMaskBit(kCGEventKeyUp), eventCallback, userInfo); And my callback is handled nicely, with the events

Simulate/Toggle CAPS LOCK programatically in OS X

孤者浪人 提交于 2019-11-28 12:52:53
I have seen many post on this topic. But haven't found a clear answer anywhere. Is there a way to toggle CAPS LOCK in Objective-C or C code? I am not looking for a solution using X11 libs. I am not bothered about the LED on/off status. But just the functionality of CAPS LOCK (changing the case of letters and printing the special characters on number keys). Why is CGEvent not supporting this the way it does for other keys? var ioConnect: io_connect_t = .init(0) let ioService = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching(kIOHIDSystemClass)) IOServiceOpen(ioService, mach

Performing a double click using CGEventCreateMouseEvent()

浪子不回头ぞ 提交于 2019-11-27 18:51:14
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, type); CGEventPost(kCGHIDEventTap, theEvent); CFRelease(theEvent); } void LeftClick(const CGPoint point) { PostMouseEvent(kCGMouseButtonLeft, kCGEventMouseMoved, point); NSLog(@"Click!"); PostMouseEvent(kCGMouseButtonLeft, kCGEventLeftMouseDown, point); PostMouseEvent(kCGMouseButtonLeft, kCGEventLeftMouseUp, point); } I can use basically the same code

How do you use CGEventTapCreate in Swift?

两盒软妹~` 提交于 2019-11-27 13:22:44
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: https://developer.apple.com/library/prerelease/mac/documentation/Carbon/Reference/QuartzEventServicesRef/index.html#//apple_ref/c/func/CGEventTapCreate Here is how the CGEventTapCallBack is defined: typealias CGEventTapCallBack = CFunctionPointer<((CGEventTapProxy, CGEventType, CGEvent!, UnsafeMutablePointer<Void>) -> Unmanaged<CGEvent>!)> Here is how I've written the block: let eventTapCallBackBlock : @objc_block

Simulate/Toggle CAPS LOCK programatically in OS X

心不动则不痛 提交于 2019-11-27 07:27:02
问题 I have seen many post on this topic. But haven't found a clear answer anywhere. Is there a way to toggle CAPS LOCK in Objective-C or C code? I am not looking for a solution using X11 libs. I am not bothered about the LED on/off status. But just the functionality of CAPS LOCK (changing the case of letters and printing the special characters on number keys). Why is CGEvent not supporting this the way it does for other keys? 回答1: var ioConnect: io_connect_t = .init(0) let ioService =