JuanZhang
2006-02-18 01:34:30 UTC
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
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