Re: Key handling problems



On Thu, 18 Sep 2008, Perriman wrote:

      I'm trying to check if a user press some keys. I want to check
If the user press control+j. I'm having problems with it. I paste my
code:

guint key = self->priv->key;
              
if ((event->state & self->priv->mod) == self->priv->mod &&
      event->keyval == key) 
{
      xxxxxxxxx
}

Currently this code do:

1.- If the user has NumLk enabled works fine
2.- If the user has lock caps enable it doesn't work because the j is
not j is J (upper)
3.- The control check works fine
4.- If I press contro+alt+j works (It may fail because I want to
check control+j not control+alt+j)
5.- If I press contro+shift+j doesn't work because the j is not J but
the state check sais true

I have tried 1000 ways to do it, I have see a lot of code but I have
not luck

Can you help me? I'm desperated :(

If you're attaching to the "key_press_event" on some widget, you 
can do something like this in your callback:

gboolean
catch_ctrl_j (GtkWidget *w, GdkEventKey *key, gpointer p)
{
    GdkModifierType mods;

    gdk_window_get_pointer(w->window, NULL, NULL, &mods);
    
    /* make the j/J case insensitive? */
    if (gdk_keyval_to_upper(key->keyval) == GDK_J) {
        if (mods & GDK_CONTROL_MASK) {
            printf("Got ctrl-j");
            if (mods & GDK_MOD1_MASK) {
                printf("Got ctrl-alt-j");
            }
        }
    }
    
    return FALSE;
}

If you'e handling the keystroke and don't want the default handler 
invoked, then return TRUE instead.

--
Allin Cottrell
Department of Economics
Wake Forest University, NC



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