An object sent along to your app from macOS that contains information about an input action such as a mouse click or a key press.
Questions tagged [nsevent]
221 questions
24
votes
3 answers
Modify NSEvent to send a different key than the one that was pressed
I'm trying to create an OS X keyboard hook for assistive technology purposes (i.e. don't worry, not a keylogger).
When a user presses a key, I want to prevent the real keypress and send a fake keypress (character of my choosing) instead.
I have the…

ck_
- 3,719
- 10
- 49
- 76
22
votes
4 answers
Check modifierFlags of NSEvent if a certain modifier was pressed but no other
I just experimented with the addLocalMonitorForEventsMatchingMask:handler: method in NSEvent and came across the following question: How do I find out if only certain modifiers were pressed?
A short example to set this question into context: I…

Florian Pilz
- 8,002
- 4
- 22
- 30
21
votes
3 answers
Getting [NSEvent mouseLocation] in view coordination system
I have an NSView that is catching a mouseDown event.
I'm getting the coordination of the mouse click using:
- (void)mouseDown:(NSEvent *)theEvent {
NSPoint touchPoint = [NSEvent mouseLocation];
//Rest of code
}
However, this sets clickPoint…

Niv
- 2,294
- 5
- 29
- 41
15
votes
1 answer
Detect left and right mouse click on NSView
In Swift: I created a simple NSView and now want to execute different functions, depending on which mouseButton is pressed (left or right). how can I detect this?

ixany
- 5,433
- 9
- 41
- 65
12
votes
3 answers
macOS App: handling key combinations bound to global keyboard shortcuts
In some apps, it makes sense for the app to directly handle keyboard shortcuts which are otherwise bound to system wide combinations. For example, ⌘-Space (normally Spotlight) or ⌘-Tab (normally app switcher). This works in various Mac apps, such as…

pmdj
- 22,018
- 3
- 52
- 103
12
votes
2 answers
How to determine pressed modifier keys when a Cocoa app is started?
In an app I'm developing, a database is used to store all user data, usually located somewhere in Library/Application Support. In order to enable the user to switch the database, I want to implement a functionality similar to iTunes or iPhoto, where…

C. S. Hammersmith
- 468
- 4
- 16
9
votes
5 answers
How to pass scroll events to parent NSScrollView
I need fixed-size NSTextViews inside a larger scrolling window. IB requires that the textviews be inside their own NSScrollViews, even though their min/max sizes are fixed so that they won’t actually scroll. When trackpad gestures are made within…

Wienke
- 3,723
- 27
- 40
9
votes
5 answers
Mac Cocoa: How to differentiate if a NSScrollWheel event is from a mouse or trackpad?
In my application, I want the scrolling to happen, only with scroll wheel action from a mouse and not from the two finger gesture on a trackpad. Basically, I am trying to determine if the scrollWheelEvent is generated from the mouse or trackpad,…

AProgrammer
- 389
- 3
- 9
8
votes
0 answers
How to properly add global NSEvent listener for pressure events in Swift OS X application?
I'm pretty new in OS X programming and I'm trying to write an application that will capture Force Click event at system-wide context.
Based on various sources I wrote down code listed below:
var lastClickStage = -1
func checkAssistanceSettings ()…

Fellrond
- 211
- 1
- 7
8
votes
1 answer
How to deal with first responder and a NSPopover
I’m trying to replicate the behaviour of the search field in iTunes, for looking up stock symbols and names. Specifically, as you start typing in the search field a popover appears with the filtered items. For the most part I have this working…

Cory
- 2,302
- 20
- 33
8
votes
2 answers
Map NSEvent keyCode to virtual key code
NSEvent keyCode gives a keyboard scan code, which is a hardware specific code representing the physical key. I want to convert the scan code to a virtual key code, which is the logical key based on the users keyboard layout (QWERTY, AZERTY, etc).
In…

NateS
- 5,751
- 4
- 49
- 59
8
votes
3 answers
Is there a way to differentiate between left and right Shift keys being pressed?
I can recognize when the user presses any Shift key with this code:
-(void)flagsChanged:(NSEvent *)theEvent
{
if ([theEvent modifierFlags] & NSShiftKeyMask)
//. . .
}
but is there any way to distinguish whether it was the right or left…
user437064
7
votes
1 answer
Send NSEvent to background app
I need to send the key combo ^⌘C to a background app with the bundle identifier com.company.app. The key combo should then activate a menu item in that application.
Unfortunately, I have no clue how to do that. Some research pointed me to the…

Fabian Kreiser
- 8,307
- 1
- 34
- 60
7
votes
2 answers
Mouse Events Bleeding Through NSView
I have an NSView which covers its parent window's content view. This view has a click event handler which removes it from the content view. Inside this view, I have another view. When I drag the mouse in this inner view, the mouse events are applied…

Maz
- 3,375
- 1
- 22
- 27
7
votes
1 answer
Cocoa Listen to Keyboard command+up Event
I am working on a macOS app and I would like to handle a local hotkey event (command + up arrow key) in a NSViewController.
Here's how I do it with Swift:
override func keyDown(with event: NSEvent) {
let modifierkeys =…

hklel
- 1,624
- 23
- 45