Discussion:
[directfb-dev] Question about gdk_event_put for keypress event
JuanZhang
2006-02-18 01:34:30 UTC
Permalink
Hi, I am planning to fake keypress events using GTK library but
encounter some problems. Your help will be greatly appreciated.

Suppose I want to fake a keyboard 'a' press. What I do is follows:

GdkEvent event;
new_event.key.type = GDK_KEY_PRESS;
new_event.key.window = NULL;
new_event.key.send_event = 0;
new_event.key.time = GDK_CURRENT_TIME;
new_event.key.keyval = 97;
new_event.key.state = 0;
new_event.key.length = 0;
new_event.key.string = 0;
new_event.key.hardware_keycode = 0;
new_event.key.group = 0;
gdk_event_put((gpointer)&new_event);

Question I:
There is not at all a 'a' key press on the program. Until I set the
'new_event.key.window' equals the main window, it invokes the 'a' press.
Could you explain me that why the new_event.key.window is very
important? Could I get the focued window using some GTK function without
setting it explicitly? If not, is there a better way to get the
new_event.key.window?

Question II:
When I set the 'new_event.key.window' equals the main window, and the
new_event.key.keyval = 97, it invokes the 'a' press. But when I changed
new_event.key.keyval = 65289 to try the 'TAB' press, there is no
reaction. So 'TAB' press is different from 'a' press? What else should I
do to simulate 'TAB' press?


Thank you very much for your time and help!!!!!

Best,
Jully
Mike Emmel
2006-02-18 05:01:55 UTC
Permalink
The window is the focus window for the event you must set it of your
synthesizing the event
the gdk events are created after reading the current focus owner.

And yes there is a way to ask for the current focus owner.

The best way to simulate a tab is to capture the real event and read
off the values.
There are a few keyboard functions in gdk.

As far as the names of these functions I don't remember there exact
names and would
have to look at the documentation.

I'd suggest you do two things first try and find and example of
synthetic key events
generated a good place to look would be a soft keyboard program there
are a few floating around for gtk. Next I think there may be examples
in the docs.

Googling gave quite a few

http://www.google.com/search?q=gtk+soft+keyboard&start=0&ie=utf-8&oe=utf-8&client=firefox&rls=org.mozilla:en-US:unofficial

hits
Post by JuanZhang
Hi, I am planning to fake keypress events using GTK library but
encounter some problems. Your help will be greatly appreciated.
GdkEvent event;
new_event.key.type = GDK_KEY_PRESS;
new_event.key.window = NULL;
new_event.key.send_event = 0;
new_event.key.time = GDK_CURRENT_TIME;
new_event.key.keyval = 97;
new_event.key.state = 0;
new_event.key.length = 0;
new_event.key.string = 0;
new_event.key.hardware_keycode = 0;
new_event.key.group = 0;
gdk_event_put((gpointer)&new_event);
There is not at all a 'a' key press on the program. Until I set the
'new_event.key.window' equals the main window, it invokes the 'a' press.
Could you explain me that why the new_event.key.window is very
important? Could I get the focued window using some GTK function without
setting it explicitly? If not, is there a better way to get the
new_event.key.window?
When I set the 'new_event.key.window' equals the main window, and the
new_event.key.keyval = 97, it invokes the 'a' press. But when I changed
new_event.key.keyval = 65289 to try the 'TAB' press, there is no
reaction. So 'TAB' press is different from 'a' press? What else should I
do to simulate 'TAB' press?
Thank you very much for your time and help!!!!!
Best,
Jully
_______________________________________________
directfb-dev mailing list
http://mail.directfb.org/cgi-bin/mailman/listinfo/directfb-dev
Loading...