Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Send arrow keys via QProcess in any platform
QtWS25 Last Chance

Send arrow keys via QProcess in any platform

Scheduled Pinned Locked Moved General and Desktop
keyarrowkeysqprocesslinuxwindows 7
11 Posts 5 Posters 5.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Mark81

    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?

    K Offline
    K Offline
    koahnig
    wrote on last edited by
    #2

    @Mark81

    Not sure what youare trying to do there, but why would it matter?
    Your process started with QProcess runs on the same platform as your application.

    Qt::Key_Left is a constant

    Vote the answer(s) that helped you to solve your issue(s)

    1 Reply Last reply
    0
    • M Mark81

      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?

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #3

      @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.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      1
      • M Offline
        M Offline
        Mark81
        wrote on last edited by
        #4

        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.

        raven-worxR 1 Reply Last reply
        0
        • m.sueM Offline
          m.sueM Offline
          m.sue
          wrote on last edited by
          #5

          Hi,
          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?
          -Michael.

          M 1 Reply Last reply
          0
          • M Mark81

            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.

            raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #6

            @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.

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            1
            • m.sueM m.sue

              Hi,
              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?
              -Michael.

              M Offline
              M Offline
              Mark81
              wrote on last edited by
              #7

              @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.

              VRoninV 1 Reply Last reply
              0
              • M Mark81

                @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.

                VRoninV Offline
                VRoninV Offline
                VRonin
                wrote on last edited by
                #8

                @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/

                "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                ~Napoleon Bonaparte

                On a crusade to banish setIndexWidget() from the holy land of Qt

                M 1 Reply Last reply
                2
                • m.sueM Offline
                  m.sueM Offline
                  m.sue
                  wrote on last edited by
                  #9

                  @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.

                  raven-worxR 1 Reply Last reply
                  1
                  • m.sueM m.sue

                    @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.

                    raven-worxR Offline
                    raven-worxR Offline
                    raven-worx
                    Moderators
                    wrote on last edited by
                    #10

                    @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)

                    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                    If you have a question please use the forum so others can benefit from the solution in the future

                    1 Reply Last reply
                    0
                    • VRoninV VRonin

                      @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/

                      M Offline
                      M Offline
                      Mark81
                      wrote on last edited by Mark81
                      #11

                      @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.

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved