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. How to get other window's text input cursor position ?
Forum Updated to NodeBB v4.3 + New Features

How to get other window's text input cursor position ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 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.
  • S Offline
    S Offline
    Soul
    wrote on 25 Jul 2018, 03:37 last edited by aha_1980
    #1

    I want to make an input tool with QT, but I don't know how to get other application's text input cursor posion.
    Any idea ? Please help ~

    A champion is someone who gets up even when he can´t.

    J 1 Reply Last reply 25 Jul 2018, 04:45
    0
    • S Soul
      25 Jul 2018, 03:37

      I want to make an input tool with QT, but I don't know how to get other application's text input cursor posion.
      Any idea ? Please help ~

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 25 Jul 2018, 04:45 last edited by
      #2

      @Soul Can you please explain better what you want to do?
      Do you want to implement a virtual keyboard?
      There is already one implemented with Qt.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Soul
        wrote on 25 Jul 2018, 06:30 last edited by
        #3

        Hi @jsulm
        For example: Window A has an textEdit control . When my mouse clicked on the textEdit , there where be a cursor indicate I can input text. My Qt-aplication job is to show a window fllow the cursor. Just like the IME .

        A champion is someone who gets up even when he can´t.

        J 1 Reply Last reply 25 Jul 2018, 06:41
        0
        • S Soul
          25 Jul 2018, 06:30

          Hi @jsulm
          For example: Window A has an textEdit control . When my mouse clicked on the textEdit , there where be a cursor indicate I can input text. My Qt-aplication job is to show a window fllow the cursor. Just like the IME .

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 25 Jul 2018, 06:41 last edited by
          #4

          @Soul Would this Window A be a window of your application or another application (another process)?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Soul
            wrote on 25 Jul 2018, 08:39 last edited by
            #5

            @jsulm The window A is another process.

            A champion is someone who gets up even when he can´t.

            J 1 Reply Last reply 25 Jul 2018, 08:48
            0
            • S Soul
              25 Jul 2018, 08:39

              @jsulm The window A is another process.

              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 25 Jul 2018, 08:48 last edited by
              #6

              @Soul I don't think you can do this with Qt. You will need to use OS native APIs.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1
              • S Offline
                S Offline
                Soul
                wrote on 25 Jul 2018, 08:52 last edited by
                #7

                @jsulm Do you have any suggestions ? The application only runs on windows.

                A champion is someone who gets up even when he can´t.

                J 1 Reply Last reply 25 Jul 2018, 08:55
                0
                • S Soul
                  25 Jul 2018, 08:52

                  @jsulm Do you have any suggestions ? The application only runs on windows.

                  J Offline
                  J Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 25 Jul 2018, 08:55 last edited by
                  #8

                  @Soul Windows API, but I'm not expert in this area.

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  2
                  • S Offline
                    S Offline
                    SamurayH
                    wrote on 27 Jul 2018, 23:26 last edited by
                    #9

                    Hi @Soul,
                    To get the textCursorPos or the caretPos you'll have to use native OS apis as @jsulm had already mentioned. I can help you to achieve that on Windows only, let have a look at this sample :

                    • First open a new Qt Application project, choose a title, and then let everything as default.
                    • Then go to the .pro file and add this line : QT += concurrent widgets,
                      this line doesn't have any relation with our goal, it's just needed for the sample that I will describe above. If you're not familiar with QtConcurrent or Qt&Multithreading, I recommend you to learn about that, especially QtConcurrent.
                    • And finally make the main.cpp look like that, and hit RUN:
                    #include "mainwindow.h"
                    #include <QApplication>
                    #include <QDebug>
                    #include <QtConcurrent>
                    
                    #include <windows.h>
                    
                    int main(int argc, char *argv[])
                    {
                        QApplication a(argc, argv);
                    
                        QtConcurrent::run([=]()
                        {
                          forever
                          {
                             AttachThreadInput(GetCurrentThreadId(),GetWindowThreadProcessId(GetForegroundWindow(),0), true);
                    
                             POINT caretPos, cCaretPos;
                             GetCaretPos(&caretPos);
                             GetCaretPos(&cCaretPos);
                             ClientToScreen(GetFocus(),&cCaretPos);
                             qDebug() << caretPos.x << "," << caretPos.y << " - " << cCaretPos.x << "," << cCaretPos.y;
                          }
                        });
                        
                        return a.exec();
                    }
                    

                    If you want a further explanation of all of that, replay YES.

                    "قال رسول الله صلى الله عليه وسلم : " أحب الناس إلى الله أنفعهم للناس

                    1 Reply Last reply
                    1

                    1/9

                    25 Jul 2018, 03:37

                    • Login

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