Re: Passing keypress events



This is sort of what I have now, but I want to get rid of this. This approach will
force me to hardcode accellerators. I want to use the dynamic rebinding (or however
is is called :-) ) from gtk in the menu (select a menu item with the mouse without
clicking on it, press backspace or delete, and press the key you want to set the 
shortcut to). This is so that users will be able to remap keys that are used in the
command line apps that they use inside the terminal to keys that are not used.
Otherwise I'll have to make a complete configuration dialog to set these key bindings,
and then keep track of that (actually that's what I have now, but this is duplicate 
effort and more difficult for users). So, I need a way to send keypresses to some 
widget that will process the currently set accelerators, and will call the functions
that are associated with those menu items... The question is, which widget is that...

cheers,

roel 


Can someone tell me how to process a keypress event to make it look like a 
keyboard shortcut? I'm building an app that has a zvtterm in it, and the 
zvtterm prevents keyboard shortcuts from working (because all shortcuts could 
also be used by the application in the term). Anyway, I'd like the shortcuts to 
be handled anyway, so want to catch the keypresses and then I want to send them 
to the menubar to process them. Problem is, sending them directly to the menu 
bar doesn't work :-( Which is the widget that handles the shortcuts? And can I 
just pass the keypress event to it with gtk_widget_event? Thanks for all hints 
in the right direction.
 Catch the keypress event in your terminal widget.
 gtk_signal_connect(GTK_OBJECT(your_terminal), "key_press_event",
      GTK_SIGNAL_FUNC(keypress_cb), NULL);
void
keypress_cb(GtkWidget *widget, GdkEventKey *event)
{
      switch(event->keyval)
      {
              case 'c':
                      gtk_signal_emit_by_name(GTK_OBJECT(your_menu_item), "activate-item");
                      break;
/* if you want to check for control masks */
      if(event->state & GDK_CONTROL_MASK)
      {
              switch(event->keyval)
              {
                      case 'q':
                              quit_cb(NULL);
                              /* you can call the function directly instead of activating the
                               * menu
                               */
                              break;





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]