Results 1 to 6 of 6

Thread: Help with this: send keystrokes

  1. #1
    Join Date
    Sep 2016
    Posts
    78
    Thanked 1 Time in 1 Post
    Qt products
    Qt5

    Question Help with this: send keystrokes

    Hi i am trying to send keystrokes but i am have some doubts.
    I send this:
    Qt Code:
    1. QFile klog;
    2. klog.setFileName(directorio.tempPath() + "/logg");
    3. klog.open(QFile::ReadOnly);
    4. cliente.sendMessage(from,"teclas|@|" + klog.readAll()); // crash when i do this
    5. klog.close();
    To copy to clipboard, switch view to plain text mode 
    And i receive with this:
    Qt Code:
    1. if (parametros[0] == "teclas") //I check the message and write the text to my textfield
    2. {
    3. ui->textTeclas->setText(parametros[1]);
    4. }
    To copy to clipboard, switch view to plain text mode 
    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:
    Qt Code:
    1. if(parametros[0] == "t") //message of client
    2. {
    3. int i;
    4. for(i=0;i<parametros.size();i++) //loop keystrokes
    5. {
    6. enviarTecla(parametros[i].toInt());
    7. }
    8. return;
    9. }
    To copy to clipboard, switch view to plain text mode 
    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.
    Last edited by anda_skoa; 25th September 2016 at 09:47. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Help with this: send keystrokes

    What have you done so far to analyze the crash?
    Does the file reading or the message sending part of that line crash?

    Cheers,
    _

  3. #3
    Join Date
    Sep 2016
    Posts
    78
    Thanked 1 Time in 1 Post
    Qt products
    Qt5

    Default Re: Help with this: send keystrokes

    It's because write me a Strange symbole maybe it is not a char i dont know. I capture keys and when i capture space, write me Strange symbole.
    For this i included when i write space, included only space but i didnt get the purpose.
    . When i send this symbole like char , crash.
    In my function i included this. For example when someone press space key write only a space. But still write me a Strange symbole.
    Code:
    void MainWindow::escucharTeclas()
    {
    /** Esta función comprueba que teclas hay pulsadas y las guarda en un archivo **/
    char num;
    num = comprobarTeclas();
    if(num != 0)
    {
    if(num==32){
    log.open(QFile::Append);
    log.write(" ");
    cadenaa.clear();
    log.close();
    }
    else
    {
    log.open(QFile::Append);
    cadenaa.append(num);
    log.write(cadenaa);
    cadenaa.clear();
    log.close();
    }
    }
    }
    Last edited by davinciomare; 25th September 2016 at 13:22.

  4. #4
    Join Date
    Sep 2016
    Posts
    78
    Thanked 1 Time in 1 Post
    Qt products
    Qt5

    Default Re: Help with this: send keystrokes

    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
    Last edited by davinciomare; 25th September 2016 at 15:57.

  5. #5
    Join Date
    Sep 2016
    Posts
    78
    Thanked 1 Time in 1 Post
    Qt products
    Qt5

    Default Re: Help with this: send keystrokes

    solved solved thx

  6. #6
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    507
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Help with this: send keystrokes

    It would be helpful if you mentioned what solved your problem.

    Ginsengelf

Similar Threads

  1. send key even to other aplication
    By peter.mlich in forum Qt Programming
    Replies: 1
    Last Post: 21st May 2015, 14:25
  2. keystrokes problem
    By cafu1007 in forum Qt Programming
    Replies: 9
    Last Post: 26th May 2011, 03:08
  3. send signal from 1 gui to another gui
    By tho97 in forum Qt Programming
    Replies: 3
    Last Post: 5th December 2007, 21:21
  4. Send a key to process
    By Nyphel in forum Qt Programming
    Replies: 2
    Last Post: 9th July 2007, 17:37
  5. Sending keystrokes to other Applications (Windows XP)
    By skainz in forum Qt Programming
    Replies: 1
    Last Post: 11th May 2007, 09:51

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.