View Full Version : Best way to send keycodes - emulate keyboard press
Hi Guys!
Has anybody a idea how to send a keycode from my application in the background to the acutally running application in the foreground?
I would prefer a way that works similar at Maemo5 and MeeGo Tablet / Handset. It should feel for the target application like a normal hardware keyboard press.
What is the mostly common linux way to do this?
Hi Guys!
Has anybody a idea how to send a keycode from my application in the background to the acutally running application in the foreground?
I would prefer a way that works similar at Maemo5 and MeeGo Tablet / Handset. It should feel for the target application like a normal hardware keyboard press.
What is the mostly common linux way to do this?
xte maybe?
xte maybe?
Yes, xte (http://manpages.ubuntu.com/manpages/dapper/man1/xte.1.html) would be a good idea. But sadly not aviable at maemo or MeeGo.
I would if possible anyway prefer a proper working Qt class. But the only thing I found was QWSServer (http://doc.qt.nokia.com/latest/qwsserver.html) and sendKeyEvent. Sadly only for Qt Embedded. :(
No one? :(
xte is somwhere, qwerty12 used it in an early version of 'headphone-control'. It may not be in the repos, you just have to find it.
Maybe on that kumatux site?
At worst just get the debian armel package and extract the binary strait out of it.
xte is somwhere
I'm currently able to send "strings" using xvkbd
Sadly, it seems, it supports exactly as xte only strings. So I have to translate from the keycode to the string and call the shell command afterwards.
It works but feels very ugly, is very slow and resource hungry.
I found (http://talk.maemo.org/showpost.php?p=970024&postcount=211) this piece of code:
#include <X11/extensions/XTest.h>
#include <stdio.h>
#define KEY_DOWN True
#define KEY_UP False
#define KEY_MOD 37
int main(int argc, char *argv[]) {
int i;
char c;
Display *dpy = XOpenDisplay(NULL);
if (!dpy) return 1;
for (i=1; i<argc; i++) {
c=atoi (argv[i]);
printf ("<%u>\n", c);
XTestFakeKeyEvent(dpy, c, KEY_DOWN, CurrentTime);
XTestFakeKeyEvent(dpy, c, KEY_UP, CurrentTime);
}
XCloseDisplay(dpy);
return 0;
}
The "X11/extensions/XTest.h" is breaking my neck immediately in the first line. ;)
I guess my C++ skills are still to weak. (learing since several months) Am I able to include this and XTestFakeKeyEvent in my Qt Project without bending over backwards?
At MeeGo there is a elegant way to send keycodes using DBus: maliit.org (http://wiki.maliit.org/Documentation)
But it seems this works only on MeeGo, not Fremantle maemo5. :(
Whats the difference to the non-extension XSendEvent (http://tronche.com/gui/x/xlib/event-handling/XSendEvent.html)?
Mentalist Traceur
2011-07-29, 04:43
I compiled xdotool before for the N900 - not .deb packaged let alone in the repositories, but I made a thread about it. (It does exactly what you want, if you're okay with doing it through the command line or having your app do it through the command line.)
Look under my account's statistics, all threads posted by me. It's called "[Announce] xdotool" or something like that.
I compiled xdotool before for the N900 - not .deb packaged let alone in the repositories, but I made a thread about it. (It does exactly what you want, if you're okay with doing it through the command line or having your app do it through the command line.)
THANKS A LOT! :)
My small application works now. Not perfect, but rudimentary. Glad to see that I got my idea working. Will try to package your bin (http://talk.maemo.org/showthread.php?t=70076) into my package. But I'm still searching for a better solution that accepts keycodes directly and not thru Characters. Preferential without using the commandline. Many combinations are still not working and I expect many language settings related problems in the near future...
Will create a new Thread as soon as I have the packaging done. :)
Mentalist Traceur
2011-07-29, 21:12
THANKS A LOT! :)
My small application works now. Not perfect, but rudimentary. Glad to see that I got my idea working. Will try to package your bin (http://talk.maemo.org/showthread.php?t=70076) into my package. But I'm still searching for a better solution that accepts keycodes directly and not thru Characters. Preferential without using the commandline. Many kombinations are still not working and I expect many language settings related problems in the near future...
Will create a new Thread as soon as I have the packaging done. :)
If you'd like, I'll just package xdotool and put it up in the repository - I don't think the autobuilder will let you put your app without all the source code in the normal way into the repos anyway, so one of us will have to do it eventually anyway - I might as well figure out how to package it and put it into the repos. It'll take a few days though, most likely.
Problem - there is already some xdotool in repository. Although I'm not sure it's optified or whatsnot. So, with Mentalist maintaining it, we would be probably much more happier penguins.
Problem - there is already some xdotool in repository. Although I'm not sure it's optified or whatsnot. So, with Mentalist maintaining it, we would be probably much more happier penguins.
Ouh ****. Thanks! :) Just uploaded my first package to autobuilder. Will try to create a dependency and do it this way. I hate this part of development... :p
EDIT: checked, xdotool from repos seems optified - sadly its only at extra-devel. :( But I'm far away from a stable release, too... :D
So, the packaging is done and I created a thread about my small project.
Here is what I'm currently developing:
TcpIpKeyboard (http://talk.maemo.org/showthread.php?t=75331) is a Application to share the Keyboard from a Windows or Linux Desktop PC, Netbook or Laptop with the N9 handset thru a simple TCP/IP connection.
http://sites.google.com/site/helexmeegoprojects/tcpkeyboard/shematics.png
But the 2-do-List is still overwhelming... so it's a Alpha preview teaser to introduce the concept. ;)
Mentalist Traceur
2011-07-30, 02:12
Problem - there is already some xdotool in repository. Although I'm not sure it's optified or whatsnot. So, with Mentalist maintaining it, we would be probably much more happier penguins.
I just checked the dates - when I packaged xdotool, it wasn't in the repos at the time - the other guy packaged it 2 months after I made that thread. I'm not going to jump on maintaining it just yet given that - xdotool is in the libs section, and all the non-user section packages get auto-promoted when the things that depend on them get rpomoted. So whenever you push your package to extras-testing and extras, xdotool will auto-promote with it.
Eureka!
I got the XTestFakeKeyEvent working at Qt:
First, this works only at the Maemo target, not the Simulator. So:
#ifdef Q_WS_MAEMO_5
#include <X11/Xlib.h>
#include <X11/keysym.h>
#include <X11/extensions/XTest.h>
#endif
Now you are able to send a keycode:
unsigned int ukeycode = XKeysymToKeycode(QX11Info::display(), KeySym);
bool ret = XTestFakeKeyEvent(QX11Info::display(), ukeycode, state, 0);
state is the press state: true = pressed / false = released
And finally this was the reason I lost some hairs - Include this into your *.pro file:
LIBS = -lX11 -lXtst
It works a lot faster and less recource hungry than calling the external binary xdotool.
Sadly I got a lot of problems to translate keycodes from a windows desktop pc to a linux maemo 5 device. And sometimes it suddenly stops working. I still have to figure out why. :confused:
If someone has some tipps, I would be glad to read it. :)
Ah, and by the way. How to disable the keyboard repeat rate at Qt QML? Any Ideas?
vBulletin® v3.8.8, Copyright ©2000-2025, vBulletin Solutions, Inc.