Send arrow keys via QProcess in any platform
-
Hi! Is there a way to send through a QProcess pipe the arrow keys, without be aware of the actual platfor?
I launch an external program in this way:QProcess *m_process = new QProcess(this); m_process->start("program");
and I would like to do something like:
m_process->write(Qt::Key_Left);
As far as I know the actual bytes I have to send depend on the platform, don't they?
-
@Mark81
there is no Qt-crossplatform way. You will have to specify the native implementation yourself. Also you need to figure out how to access the window handle of the newly created process. And then send the (native) key event/message to this window handle. -
@Mark81 said in Send arrow keys via QProcess in any platform:
ehm... two opposite answers :o)
Qt::Key_Left is a costant, true, but it doesn't hold the actual code for keys. I.e. under linux arrow left is \esc [ D.The
Qt::Key_*
constants are just used inside the Qt framework. The are mapped when the native key event is received. And from there on only the enum constants are used for convenience/cross-platform reasons of course.So such a feature you want to achieve goes way beyond a framework such as Qt and requires you to do the hard work yourself.
-
@m.sue said in Send arrow keys via QProcess in any platform:
the question is: what do you want to achieve? Remotely controll another application i.e. let it make a "key left" movement without a user being in front of the keyboard that presses the relevant key?
Exactly.
-
@Mark81 Then do you really need Qt? there are already mature tools to do those kind of things, for windows: http://ahkscript.org/ and for linux: http://www.semicomplete.com/projects/xdotool/
-
@Mark81: You could also use the QTest module. There is a function
keypress
there that does the trick: http://doc.qt.io/qt-5/qtest.html. This function even expects a platform independent Qt::Key parameter.
You would have to establish the communication (protocol) by yourself, though.
-Michael. -
@m.sue
well the problem isn't to send a KeyEvent inside your application, but to send a native keyevent from one process to separate process (not even necessarily Qt) -
@VRonin said in Send arrow keys via QProcess in any platform:
@Mark81 Then do you really need Qt? there are already mature tools to do those kind of things, for windows: http://ahkscript.org/ and for linux: http://www.semicomplete.com/projects/xdotool/
I don't need Qt for this. But I have a quite large application that does a lot of things. One of those, is to launch external applications and send them keystrokes as you would type in front of a keyboard.