3

I need to simulate keyPress on my Qt application (I'm 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 have to link a library but I don't know which ?

Thank you

Nico

user729194
  • 43
  • 6

2 Answers2

4

Add this line to your .pro file:

LIBS += -framework ApplicationServices
Stephen Chu
  • 12,724
  • 1
  • 35
  • 46
2

You need to link the Application Services framework. For instance,

clang -framework ApplicationServices yoursourcefile.c

(-framework is a linker flag)