Re: Get ascii code from GdkEventKey-Keyval



I don't know if you're using it, but if not you might install a key
snooper with gtk_key_snooper install().  If so, I assume this is your
handler function.
I did a similar thing, and you might have a look at the gdk function
 gdk_keyval_name() which converts a key value to a symbolic name,  or

 gdk_keyval_from_name(), which converts a key name to an actual key
value.

Reference manual is 
 developer.gnome.org/doc/API/2.0/gdk

Good Luck,
Don

Hi, everyone.

This is my first attempt to ask something here... err... hello ^_^

I've got Mandrake 8 (I think) "upgraded" to 9.2. This "upgrading" was made 
manually and not as well as I wanted, but that's another story. I'm saying 
this only to tell that I'm still programming with gdk 1.2 (or 1.3, I mean 
it's not 2.x).

Got a code like:

void key_pressed (GtkWidget *widget, GdkEvent *event, gpointer func_data)
{
      GdkEventKey *keyev;

      keyev = event;

      if (event->type == GDK_KEY_PRESS)
      {
              switch (keyev->keyval)

/* A thing I don't understand: you can't access a "keyval" for directly
"event", i've got to "move" event to a GdkEventKey before */

              {
                      case GDK_Return: 
                      somewhere = ev_ok; somearg = 0; break;
              case GDK_Escape: 
                      somwehere = ev_cancel; somearg = 0; break;
              case GDK_F1:
                      somewhere = ev_help; somearg = 0; break;
              /* and so */
              }
      }
}

As you can see I Scan the "keyval". If it's a "special key" it stores 
"somewhere" = some "special" code for me, and somearg=0.

I want (if possible) that for each number / character, "somwehere" = 
ev_key  and  somearg = the ASCII code for this key (I want to print later 
sprintf (somearg) for instance).

That is (my english is not good and my brain worst), I want to "catch" the
key pressed (I've done it! Gracias, Miguel P!); but if the key is just a
letter/number (A, B, ..., Z, 5, 8) just store a "ev_key". I though about:

case GDK_f: somewhere = ev_ok; somearg = "f"; break;

but it's a little hard doing it for each letter, number... and I think 
it's far better readable any code as 

... default: 
       somewhere = ev_character; 
       somearg = get_ascii_code(evtecla->keyval);
       break;


Have i explained it clearly? I hope so!

Regards and thanks in advance,

.-:Namarie:-.
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list





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