maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   Best way to send keycodes - emulate keyboard press (https://talk.maemo.org/showthread.php?t=75080)

helex 2011-07-19 18:39

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?

vi_ 2011-07-19 18:52

Re: Best way to send keycodes - emulate keyboard press
 
Quote:

Originally Posted by helex (Post 1054292)
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?

helex 2011-07-19 19:03

Re: Best way to send keycodes - emulate keyboard press
 
Quote:

Originally Posted by vi_ (Post 1054300)
xte maybe?

Yes, xte 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 and sendKeyEvent. Sadly only for Qt Embedded. :(

helex 2011-07-21 19:32

Re: Best way to send keycodes - emulate keyboard press
 
No one? :(

vi_ 2011-07-21 19:38

Re: Best way to send keycodes - emulate keyboard press
 
Quote:

Originally Posted by helex (Post 1055669)
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.

helex 2011-07-28 21:49

Re: Best way to send keycodes - emulate keyboard press
 
Quote:

Originally Posted by vi_ (Post 1055673)
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 this piece of code:

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
But it seems this works only on MeeGo, not Fremantle maemo5. :(

Pillum 2011-07-29 01:33

Re: Best way to send keycodes - emulate keyboard press
 
Whats the difference to the non-extension XSendEvent?

Mentalist Traceur 2011-07-29 04:43

Re: Best way to send keycodes - emulate keyboard press
 
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.

helex 2011-07-29 20:49

Re: Best way to send keycodes - emulate keyboard press
 
Quote:

Originally Posted by Mentalist Traceur (Post 1060359)
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 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

Re: Best way to send keycodes - emulate keyboard press
 
Quote:

Originally Posted by helex (Post 1060787)
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 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.


All times are GMT. The time now is 21:26.

vBulletin® Version 3.8.8