0

I'm trying to send key events to a display event if it is not in the foreground.

At the moment i'm doing the following:

Display *d_;
d_ = XOpenDisplay(NULL);
system(QString("xdotool key Shift+F8").toStdString().c_str());
XFlush(d_);
XCloseDisplay(d_);

Though this is not working when the display is not focused.

So my questions are:

  1. How can I send the key event to the display when it's not focused.
  2. Is there a nicer way for sending a keystroke than starting a tool via shell?
  3. Why do I have to open a new Display before using the shell command?

I'm using Qt and the code should run on Linux.

Josch
  • 121
  • 1
  • 3
  • 9
  • Do you have control over the foreground display when the target display is in the background?? – UmNyobe Mar 06 '13 at 10:35
  • 1
    for q2: http://stackoverflow.com/questions/1108926/produce-keyboard-events-key-hits – UmNyobe Mar 06 '13 at 10:35
  • I actually don't knwo if I have control. What do I need to do for having it? The display is focused on startup, so basically my code is operating with that display. I don't have any PIDs though. – Josch Mar 06 '13 at 10:40
  • 1
    sure: system("xdotool key Shift+F8"); :-) – qPCR4vir Mar 06 '13 at 10:50
  • This means xdotool must be installed on the executing machine :-), I'm looking for a function which is on any X machine. – Josch Mar 06 '13 at 11:45
  • Did you consider to use XGrabKey to register hot keys? Or what you need is not hot key? – ixSci Mar 06 '13 at 12:07
  • I don't think XGrabKey will help me here. XGrabKey is for fetching results, not for sending, right? – Josch Mar 07 '13 at 12:50

0 Answers0