Connect Gtk's key event with button pressed?
I want to make connection with GTK's keyborad event and button event.
When I press a key, I want that a button in the window also has a status of being pressed, I have try to emit signals to do this, but has no effect: Code:
#include <gtk/gtk.h> thanks. |
I'm not absolutly sure if I understood the task you're trying to do (sorry, my english). For example, in your window is a buttom which should be activated when you press "Ctrl + A", right?
If so, you're looking for GtkToggleButton. There's a function gtk_toggle_button_set_active(), which may be called from your keyboard event to activate the buttom. Hope this helps. |
I does not mean shortcuts, for example, I want to write a screen keyboard, so the buttons must respond to the key events. When I press "k" on the real keyborad, one button "k" in the window must act just like been pressed.
Or write a digital calculator, when I press a number key, the button in the window must also "been pressed" at the same time. thanks. |
I see. I just checked the usual button and it looks as if pressed when you click it with your mouse.
So, what about using gtk_button_pressed()? Looks like an obvious choice to me. For example, pressing "k" would call gtk_buttom_pressed() associated with the buttom, and releasing "k" would call gtk_buttom_released(). I think, this should model the effect, you want. An even more simple way seems to use gtk_buttom_clicked(). However, I'm not very familar with C, so consider this a suggestion. |
No effect, and the document say it's also "emit signal".
I want to trace into this gtk functions with gdb, how can I do this? Or any other way? thanks. |
I read some source code of gtk, and achieve at last by this way:
Code:
g_signal_emit_by_name(G_OBJECT(button), "activate", NULL); |
Cool. Please do us all a favour then, and post the complete code, instead of letting others figure out if you needed to change others parts, too.
|
All times are GMT -5. The time now is 07:48 PM. |