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. Click and hold LMB
QtWS25 Last Chance

Click and hold LMB

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt creatorqt5
22 Posts 5 Posters 1.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.
  • R Offline
    R Offline
    rktech
    wrote on 3 Aug 2020, 18:02 last edited by rktech 8 Mar 2020, 18:06
    #1

    Hello,
    is there any way in QT to simulate a click and hold of left mouse button? I am looking for easiest solution.
    Thanks
    rktech

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 3 Aug 2020, 18:28 last edited by
      #2

      Hi,

      In what context ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      R 1 Reply Last reply 3 Aug 2020, 18:47
      1
      • S SGaist
        3 Aug 2020, 18:28

        Hi,

        In what context ?

        R Offline
        R Offline
        rktech
        wrote on 3 Aug 2020, 18:47 last edited by
        #3

        @SGaist This is the only thing, that I need to do, click, hold for 5 seconds and release. So the context doesn't matter.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 3 Aug 2020, 18:52 last edited by
          #4

          Yes it is. Do you need to do that for testing purpose ? Is it for automation ? Are you doing targeting your own application ? Another one ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          R 1 Reply Last reply 3 Aug 2020, 19:00
          0
          • S SGaist
            3 Aug 2020, 18:52

            Yes it is. Do you need to do that for testing purpose ? Is it for automation ? Are you doing targeting your own application ? Another one ?

            R Offline
            R Offline
            rktech
            wrote on 3 Aug 2020, 19:00 last edited by
            #5

            @SGaist It is for bot for game.

            M 1 Reply Last reply 3 Aug 2020, 19:06
            0
            • R rktech
              3 Aug 2020, 19:00

              @SGaist It is for bot for game.

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 3 Aug 2020, 19:06 last edited by
              #6

              @rktech
              So you try to do that to OTHER application correct ?

              so while you can do that internal in Qt app like

               QMouseEvent *mEvnPress = new QMouseEvent(QEvent::MouseButtonPress, QPoint(10, 10), Qt::LeftButton,
                                                           Qt::LeftButton, Qt::NoModifier);
                  QMouseEvent *mEvnRelease = new QMouseEvent(QEvent::MouseButtonRelease, QPoint(10, 10),
                                                             Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
                  QCoreApplication::sendEvent(pWidget, mEvnPress);
              
                  QTimer::singleShot( 5000, [pWidget, mEvnRelease]() {
                      QCoreApplication::sendEvent(pWidget, mEvnRelease);
                  });
              

              It wont work for outside.

              You must use native OS calls to do that.

              Is this on windows only ?
              or you need to work on linux / macos too ?

              R 2 Replies Last reply 3 Aug 2020, 19:18
              0
              • M mrjj
                3 Aug 2020, 19:06

                @rktech
                So you try to do that to OTHER application correct ?

                so while you can do that internal in Qt app like

                 QMouseEvent *mEvnPress = new QMouseEvent(QEvent::MouseButtonPress, QPoint(10, 10), Qt::LeftButton,
                                                             Qt::LeftButton, Qt::NoModifier);
                    QMouseEvent *mEvnRelease = new QMouseEvent(QEvent::MouseButtonRelease, QPoint(10, 10),
                                                               Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
                    QCoreApplication::sendEvent(pWidget, mEvnPress);
                
                    QTimer::singleShot( 5000, [pWidget, mEvnRelease]() {
                        QCoreApplication::sendEvent(pWidget, mEvnRelease);
                    });
                

                It wont work for outside.

                You must use native OS calls to do that.

                Is this on windows only ?
                or you need to work on linux / macos too ?

                R Offline
                R Offline
                rktech
                wrote on 3 Aug 2020, 19:18 last edited by
                #7

                @mrjj It is for game, and yes, I have win only.

                1 Reply Last reply
                0
                • F Offline
                  F Offline
                  fcarney
                  wrote on 3 Aug 2020, 19:20 last edited by
                  #8

                  https://pywinauto.github.io/

                  C++ is a perfectly valid school of magic.

                  1 Reply Last reply
                  1
                  • R Offline
                    R Offline
                    rktech
                    wrote on 3 Aug 2020, 19:21 last edited by rktech 8 Mar 2020, 19:21
                    #9

                    @fcarney need to use it in qt c++;

                    F 1 Reply Last reply 3 Aug 2020, 19:23
                    0
                    • R rktech
                      3 Aug 2020, 19:21

                      @fcarney need to use it in qt c++;

                      F Offline
                      F Offline
                      fcarney
                      wrote on 3 Aug 2020, 19:23 last edited by
                      #10

                      @rktech said in Click and hold LMB:

                      need to use it in qt c++;

                      Then search for a framework for app automation in C++. I don't think Qt is designed for that.

                      C++ is a perfectly valid school of magic.

                      1 Reply Last reply
                      2
                      • M Offline
                        M Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on 3 Aug 2020, 19:46 last edited by
                        #11

                        Hi
                        You have to use native API
                        https://stackoverflow.com/questions/7492529/how-to-simulate-a-mouse-movement

                        I would check first with autoit3
                        https://www.autoitscript.com/site/
                        if it cant click on your game, you wont be able too either.

                        1 Reply Last reply
                        2
                        • P Offline
                          P Offline
                          Pl45m4
                          wrote on 4 Aug 2020, 09:54 last edited by Pl45m4 8 Apr 2020, 10:14
                          #12

                          I've never heard that AI or bots in games need to take control of keyboard or mouse... In most cases, you can bypass it and make direct inputs...
                          What should your 5s-click trigger? What do you want to achieve?

                          EDIT:

                          Is it for a bot in your game or 3rd party software and you want to write a bot in Qt? (my suggestion above only works, if you have full access to the code, which isn't the case when you are not using your own game...)


                          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                          ~E. W. Dijkstra

                          R 1 Reply Last reply 4 Aug 2020, 17:35
                          0
                          • P Pl45m4
                            4 Aug 2020, 09:54

                            I've never heard that AI or bots in games need to take control of keyboard or mouse... In most cases, you can bypass it and make direct inputs...
                            What should your 5s-click trigger? What do you want to achieve?

                            EDIT:

                            Is it for a bot in your game or 3rd party software and you want to write a bot in Qt? (my suggestion above only works, if you have full access to the code, which isn't the case when you are not using your own game...)

                            R Offline
                            R Offline
                            rktech
                            wrote on 4 Aug 2020, 17:35 last edited by
                            #13

                            @Pl45m4 said in Click and hold LMB:

                            I've never heard that AI or bots in games need to take control of keyboard or mouse... In most cases, you can bypass it and make direct inputs...
                            What should your 5s-click trigger? What do you want to achieve?

                            EDIT:

                            Is it for a bot in your game or 3rd party software and you want to write a bot in Qt? (my suggestion above only works, if you have full access to the code, which isn't the case when you are not using your own game...)

                            Of course it's not my own game.

                            F 1 Reply Last reply 4 Aug 2020, 17:44
                            0
                            • R rktech
                              4 Aug 2020, 17:35

                              @Pl45m4 said in Click and hold LMB:

                              I've never heard that AI or bots in games need to take control of keyboard or mouse... In most cases, you can bypass it and make direct inputs...
                              What should your 5s-click trigger? What do you want to achieve?

                              EDIT:

                              Is it for a bot in your game or 3rd party software and you want to write a bot in Qt? (my suggestion above only works, if you have full access to the code, which isn't the case when you are not using your own game...)

                              Of course it's not my own game.

                              F Offline
                              F Offline
                              fcarney
                              wrote on 4 Aug 2020, 17:44 last edited by
                              #14

                              @rktech Where does the requirement that it must be C++ and Qt come from?

                              C++ is a perfectly valid school of magic.

                              R 1 Reply Last reply 4 Aug 2020, 17:46
                              0
                              • M mrjj
                                3 Aug 2020, 19:06

                                @rktech
                                So you try to do that to OTHER application correct ?

                                so while you can do that internal in Qt app like

                                 QMouseEvent *mEvnPress = new QMouseEvent(QEvent::MouseButtonPress, QPoint(10, 10), Qt::LeftButton,
                                                                             Qt::LeftButton, Qt::NoModifier);
                                    QMouseEvent *mEvnRelease = new QMouseEvent(QEvent::MouseButtonRelease, QPoint(10, 10),
                                                                               Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
                                    QCoreApplication::sendEvent(pWidget, mEvnPress);
                                
                                    QTimer::singleShot( 5000, [pWidget, mEvnRelease]() {
                                        QCoreApplication::sendEvent(pWidget, mEvnRelease);
                                    });
                                

                                It wont work for outside.

                                You must use native OS calls to do that.

                                Is this on windows only ?
                                or you need to work on linux / macos too ?

                                R Offline
                                R Offline
                                rktech
                                wrote on 4 Aug 2020, 17:45 last edited by
                                #15

                                @mrjj said in Click and hold LMB:

                                @rktech
                                So you try to do that to OTHER application correct ?

                                so while you can do that internal in Qt app like

                                 QMouseEvent *mEvnPress = new QMouseEvent(QEvent::MouseButtonPress, QPoint(10, 10), Qt::LeftButton,
                                                                             Qt::LeftButton, Qt::NoModifier);
                                    QMouseEvent *mEvnRelease = new QMouseEvent(QEvent::MouseButtonRelease, QPoint(10, 10),
                                                                               Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
                                    QCoreApplication::sendEvent(pWidget, mEvnPress);
                                
                                    QTimer::singleShot( 5000, [pWidget, mEvnRelease]() {
                                        QCoreApplication::sendEvent(pWidget, mEvnRelease);
                                    });
                                

                                It wont work for outside.

                                You must use native OS calls to do that.

                                Is this on windows only ?
                                or you need to work on linux / macos too ?

                                use of undeclared identifier 'pWidget'

                                M 1 Reply Last reply 4 Aug 2020, 19:07
                                0
                                • F fcarney
                                  4 Aug 2020, 17:44

                                  @rktech Where does the requirement that it must be C++ and Qt come from?

                                  R Offline
                                  R Offline
                                  rktech
                                  wrote on 4 Aug 2020, 17:46 last edited by
                                  #16

                                  @fcarney It is not a requirement, but I want some high-level language.

                                  F 1 Reply Last reply 4 Aug 2020, 17:53
                                  0
                                  • R rktech
                                    4 Aug 2020, 17:46

                                    @fcarney It is not a requirement, but I want some high-level language.

                                    F Offline
                                    F Offline
                                    fcarney
                                    wrote on 4 Aug 2020, 17:53 last edited by
                                    #17

                                    @rktech said in Click and hold LMB:

                                    It is not a requirement, but I want some high-level language.

                                    I have used that python library I pointed to you. I have automated games at home and applications at work with that library. It has functions to find the process, interface to widgets if available, it also has raw clicks based upon position. It already has all the function calls figured out for the windows platform. It is also extremely easy to use compared to a C++ solution. You most likely will not find a widget set in a game. Since they are rendering to opengl or directx. So raw clicks is your best bet.

                                    If you pursue a C++ solution you will have to either find an automation library or dig through the windows api to find the calls to do click events or key events.

                                    You could create a python based qt application and use that automation library for the backend portion of the app.

                                    C++ is a perfectly valid school of magic.

                                    R 1 Reply Last reply 4 Aug 2020, 17:54
                                    0
                                    • F fcarney
                                      4 Aug 2020, 17:53

                                      @rktech said in Click and hold LMB:

                                      It is not a requirement, but I want some high-level language.

                                      I have used that python library I pointed to you. I have automated games at home and applications at work with that library. It has functions to find the process, interface to widgets if available, it also has raw clicks based upon position. It already has all the function calls figured out for the windows platform. It is also extremely easy to use compared to a C++ solution. You most likely will not find a widget set in a game. Since they are rendering to opengl or directx. So raw clicks is your best bet.

                                      If you pursue a C++ solution you will have to either find an automation library or dig through the windows api to find the calls to do click events or key events.

                                      You could create a python based qt application and use that automation library for the backend portion of the app.

                                      R Offline
                                      R Offline
                                      rktech
                                      wrote on 4 Aug 2020, 17:54 last edited by
                                      #18

                                      @fcarney The problem is, that I don't know Python.

                                      S 1 Reply Last reply 4 Aug 2020, 17:55
                                      0
                                      • R rktech
                                        4 Aug 2020, 17:54

                                        @fcarney The problem is, that I don't know Python.

                                        S Offline
                                        S Offline
                                        SGaist
                                        Lifetime Qt Champion
                                        wrote on 4 Aug 2020, 17:55 last edited by
                                        #19

                                        @rktech said in Click and hold LMB:

                                        @fcarney The problem is, that I don't know Python.

                                        It's maybe a good time to learn :-)

                                        Interested in AI ? www.idiap.ch
                                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                        R 1 Reply Last reply 4 Aug 2020, 17:58
                                        1
                                        • S SGaist
                                          4 Aug 2020, 17:55

                                          @rktech said in Click and hold LMB:

                                          @fcarney The problem is, that I don't know Python.

                                          It's maybe a good time to learn :-)

                                          R Offline
                                          R Offline
                                          rktech
                                          wrote on 4 Aug 2020, 17:58 last edited by
                                          #20

                                          @SGaist said in Click and hold LMB:

                                          It's maybe a good time to learn :-)

                                          I don't like the syntax, that's the problem.

                                          M 1 Reply Last reply 4 Aug 2020, 19:10
                                          0

                                          9/22

                                          3 Aug 2020, 19:21

                                          • Login

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