1

Possible Duplicate:
Qt 4.7.4: Is there a way to find out the status of CAPS LOCK?

How to detect capslock key status in qt on mac os x. I have tried

Display * d = XOpenDisplay((char*)0);

bool caps_state = false;
if (d)
 {
  unsigned n;
  XkbGetIndicatorState(d, XkbUseCoreKbd, &n);
  caps_state = (n & 0x01) == 1;
 }
 return caps_state;

but it giving me following error:

Undefined symbols for architecture x86_64:

"_XOpenDisplay", referenced from: .o myclass::GetCapslockState()

  myclass::keyEvent(QKeyEvent*)     

"_XkbGetIndicatorState", referenced from: .o

  myclass::GetCapslockState()       in .o
  myclass::keyEvent(QKeyEvent*)      in .o

ld: symbol(s) not found for architecture x86_64 collect2: ld returned 1 exit status

I am new to qt devlopment. I am not getting why it is showing me this error. I have included "#include " header file. If anyone knows please help me.

Community
  • 1
  • 1
  • Look at this other question: http://stackoverflow.com/questions/9830905/qt-4-7-4-is-there-a-way-to-find-out-the-status-of-caps-lock – Spidey Dec 03 '12 at 16:04
  • You're using X11 symbols on OS X. Using X11 is a bad on OS X in general (abysmal user experience, and not even installed by default). Also, Qt won't link against the X libraries you'd need here by default. – Frank Osterfeld Dec 03 '12 at 20:06

1 Answers1

1

You can detect changes to keys with:

QWidget::keyPressEvent()
// and
QWidget::keyReleaseEvent()

These could be used to determine the state in some situations, like if you know the state of caps lock at program initialization or if you assume or require a certain state. However, there is no platform-independent means I know of to outright query the current state of caps lock. You will need to use platform-dependent means. Be sure to support the case where caps lock state doesn't exist or cannot be detected.

Charles Burns
  • 10,310
  • 7
  • 64
  • 81