0

I am writing a Cocoa Objective-C application for the macOS, and I am using this very good answer here to be notified of window position changes in other applications. Within my app, I can use the event returned by [NSApp currentEvent] to determine the key modifiers. How can I ascertain the same for another app that I am monitoring ? To be simple, I would like to know if a window of an application was moved or resized while pressing the command (or option) key. Many thanks for any help.

GrahamTheDev
  • 22,724
  • 2
  • 32
  • 64
Alfonso Tesauro
  • 1,730
  • 13
  • 21
  • Why do you want to know? The modifiers can change while dragging. – Willeke Oct 15 '20 at 08:49
  • Thanks Willeke for your interest, I am aware that modifiers can change, so my provisional solution is to use the API https://developer.apple.com/documentation/appkit/nsevent/1535472-addglobalmonitorforeventsmatchin?language=objc and observe matching mask NSEventMaskFlagsChanged, then set an ivar to true or false according to the pressed or unpressed state of the command key. This works well and I will probably post it as an answer. Do you see anything against this approach ? Thanks – Alfonso Tesauro Oct 15 '20 at 09:06
  • `NSEvent.modifierFlags` returns the currently pressed modifier flags. – Willeke Oct 15 '20 at 09:13
  • You are absolutely right, I had never used the modifierFlags directly on NSEvent, I always used [NSApp currentEvent] so I did not know about it. Yours should be the accepted answer. Thanks – Alfonso Tesauro Oct 15 '20 at 09:18
  • Removed the "accessibility" tag as that is related to people with disabilities being able to use your products and services. Hope you don't mind. – GrahamTheDev Oct 15 '20 at 10:37
  • Thanks a lot for your interest and help, I did not notice accessibility was used here with another meaning, sorry – Alfonso Tesauro Oct 15 '20 at 10:47

0 Answers0