Use CGEvent with Qt on Mac Os X

I need to simulate keyPress in my Qt application (I am on mac Os X 10.6).

I wrote this code:

#include <ApplicationServices/ApplicationServices.h> ... CGEventRef mkey = CGEventCreateKeyboardEvent(NULL, (CGKeyCode)46, true); CGEventPost(kCGAnnotatedSessionEventTap, mkey); CFRelease(mkey); ... 

But there is an error:

 Undefined symbols: "_CGEventCreateKeyboardEvent", referenced from: SimuleEvent::PressControl(QString) in simuleevent.o "_CGEventPost", referenced from: SimuleEvent::PressControl(QString) in simuleevent.o "_CFRelease", referenced from: SimuleEvent::PressControl(QString) in simuleevent.o 

I think I need to link the library, but I don’t know what?

thanks

Niko

0
source share
2 answers

Add this line to your .pro file:

 LIBS += -framework ApplicationServices 
+2
source

You need to link the application structure. For instance,

 clang -framework ApplicationServices yoursourcefile.c 

( -framework - linker flag)

0
source

Source: https://habr.com/ru/post/1397973/


All Articles