Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Send keystrokes help c++
Forum Updated to NodeBB v4.3 + New Features

Send keystrokes help c++

Scheduled Pinned Locked Moved Unsolved C++ Gurus
15 Posts 3 Posters 4.5k Views 2 Watching
  • 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
    RIVOPICO
    wrote on 24 Sept 2016, 15:12 last edited by RIVOPICO
    #1

    Hi i am trying to send keystrokes but i am have some doubts.
    I send this:
    QFile klog;
    klog.setFileName(directorio.tempPath() + "/logg");
    klog.open(QFile::ReadOnly);
    cliente.sendMessage(from,"teclas|@|" + klog.readAll()); // crash when i do this
    klog.close();

    And i receive with this:
    if (parametros[0] == "teclas") //I check the message and write the text to my textfield
    {
    ui->textTeclas->setText(parametros[1]);
    }

    Any suggestion or idea is good received thanks. The problem is when i read the file and i send the message, the application crashes and i cant send the keystrokes that i have in the file . Thanks in advance.

    Aditional:

    I think i could create other button; send some message and put since my server:
    if(parametros[0] == "t") //message of client
    {
    int i;
    for(i=0;i<parametros.size();i++) //loop keystrokes
    {
    enviarTecla(parametros[i].toInt());
    }
    return;
    }

    And then send key for key, i dont know if this will work fine. Any suggestions. I need to read some file and send the strokes to my client. Only that. Thanks in advance.

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on 24 Sept 2016, 20:12 last edited by A Former User
      #2

      Hi! I don't know what you're doing there but it's far too complicated. The way to go is to create QKeyEvent's and send them to the widget of your choice via postEvent. You can do the same with other events, like mouse input.

      1 Reply Last reply
      3
      • R Offline
        R Offline
        RIVOPICO
        wrote on 25 Sept 2016, 00:21 last edited by RIVOPICO
        #3

        Hi i only want to send the content of one file to my client where i have other file. Because i could record the keys but i am trying to loop them and send to my client.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 25 Sept 2016, 07:26 last edited by
          #4

          What is the exact content of this file ?

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

          1 Reply Last reply
          1
          • R Offline
            R Offline
            RIVOPICO
            wrote on 25 Sept 2016, 09:05 last edited by
            #5

            it has normal text . one .txt file.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 25 Sept 2016, 09:36 last edited by
              #6

              Then why not just show its content in a QLabel or a QTextEdit/QPlainTextEdit if you want to be able to modify it ?

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

              1 Reply Last reply
              1
              • R Offline
                R Offline
                RIVOPICO
                wrote on 25 Sept 2016, 10:28 last edited by
                #7
                This post is deleted!
                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  RIVOPICO
                  wrote on 25 Sept 2016, 11:51 last edited by RIVOPICO
                  #8
                  This post is deleted!
                  1 Reply Last reply
                  0
                  • R Offline
                    R Offline
                    RIVOPICO
                    wrote on 25 Sept 2016, 14:28 last edited by RIVOPICO
                    #9

                    The function for send my keys is this:
                    void enviarTecla(int tecla)
                    {

                    Display *display = XOpenDisplay(NULL);
                    XKeyEvent event;
                    
                    switch (tecla)
                    {
                    case Qt::Key_Return:
                        tecla = XK_Return ;
                        break;
                    case Qt::Key_Backspace:
                        tecla = XK_BackSpace ;
                        break;
                    case Qt::Key_Escape:
                        tecla = XK_Escape;
                        break;
                    case Qt::Key_Shift:
                        tecla = XK_Shift_L ;
                        break;
                    case Qt::Key_CapsLock:
                        tecla = XK_Caps_Lock;
                        break;
                    }
                      int a;
                      event.display = display;
                      XGetInputFocus(display,&event.window,&a);
                      event.root = 0;
                      event.subwindow = None;
                      event.time = CurrentTime;
                      event.x = 1;
                      event.y = 1;
                      event.x_root = 1;
                      event.y_root = 1;
                      event.same_screen = TRUE;
                    
                      event.type = KeyPress;  //event.type = KeyRelease;
                      event.keycode = XKeysymToKeycode (display,tecla);
                      event.state = 0;
                    
                      XSendEvent(event.display, event.window, TRUE, KeyPressMask, (XEvent *)&event);
                    
                    
                      event.display = display;
                      XGetInputFocus(display,&event.window,&a);
                      event.root = 0;
                      event.subwindow = None;
                      event.time = CurrentTime;
                      event.x = 1;
                      event.y = 1;
                      event.x_root = 1;
                      event.y_root = 1;
                      event.same_screen = TRUE;
                    
                      event.type = KeyRelease;
                      event.keycode = XKeysymToKeycode (display,tecla);
                      event.state = 0;
                    
                      XSendEvent(event.display, event.window, TRUE, KeyReleaseMask, (XEvent *)&event);
                      XCloseDisplay(display);
                    

                    }
                    And when i send i am trying with this format:
                    http://i.imgsafe.org/7e29fc31bc.png

                    Not works

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 25 Sept 2016, 19:27 last edited by
                      #10

                      Can you explain what you are trying to achieve ? That would help us help you more efficiently.

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

                      1 Reply Last reply
                      1
                      • R Offline
                        R Offline
                        RIVOPICO
                        wrote on 26 Sept 2016, 00:10 last edited by RIVOPICO
                        #11

                        the question is very easy; in the table ascii between 0 and 32 exists keys of control for example enter. How i could simulate enter when someone press 13 ascii key for example? I am introducing these data in a file but shoz me events or i dont know look: http://i.imgsafe.org/7e29fc31bc.png
                        thanks in advance. in Qt

                        1 Reply Last reply
                        0
                        • R Offline
                          R Offline
                          RIVOPICO
                          wrote on 26 Sept 2016, 00:30 last edited by
                          #12

                          i could do this: log.write(Qt::Key_Enter);

                          1 Reply Last reply
                          0
                          • R Offline
                            R Offline
                            RIVOPICO
                            wrote on 26 Sept 2016, 08:52 last edited by
                            #13

                            I need when me press enter key, in the table ascii 13 numbers, do a end line. Something like this.

                             if(num==13){
                                       log.open(QFile::Append);
                                       log.write("\n");//Jump the line in textfile
                                       log.close();
                            
                                    }
                            

                            But something working thx;

                            1 Reply Last reply
                            0
                            • R Offline
                              R Offline
                              RIVOPICO
                              wrote on 26 Sept 2016, 09:00 last edited by
                              #14

                              solved solved

                              1 Reply Last reply
                              0
                              • S Offline
                                S Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on 26 Sept 2016, 09:11 last edited by
                                #15

                                How did you solved it ?

                                In any case, please mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found :)

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

                                1 Reply Last reply
                                1

                                1/15

                                24 Sept 2016, 15:12

                                • Login

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