in reply to Use Gtk3::Gdk to intercept keypresses

[Disclaimer: I'm not a user of Gtk3. The following is based on its documentation.]

Firstly, a note on your error messages. The code

Gtk3::Gdk->keyval_name($event->keyval)

passes the class name, Gtk3::Gdk, as the first argument to keyval_name(). It's equivalent to

keyval_name('Gtk3::Gdk', $event->keyval)

From the messages, it's discarding $event->keyval, leaving

keyval_name('Gtk3::Gdk')

Presumably, $event->keyval returns a number, which seems to be what keyval_name() wants; however, its getting a string, hence: "Argument "Gtk3::Gdk" isn't numeric ...".

You might try:

Gtk3::Gdk::keyval_name($event->keyval)

However, before doing that, I suggest you look at the "Porting from Gtk2 to Gtk3" section of the Gtk3 documentation. It has some information on Keysyms; although, I don't know if that helps you directly with this issue. Other parts may also be useful if you are indeed porting a current Gtk2 application to Gtk3.

— Ken

Replies are listed 'Best First'.
Re^2: Use Gtk3::Gdk to intercept keypresses
by Anonymous Monk on Feb 13, 2019 at 09:36 UTC

    Using this:

    Gtk3::Gdk::keyval_name($event->keyval)

    instead of this:

    Gtk3::Gdk->keyval_name($event->keyval)

    ...was the first thing I tried, and for some inexplicable reason, it produces the same error message.

    I had also checked the Gtk2 > Gtk3 migration documents. The change to Keysyms seems to be a red herring; the test code translates a value like 65478 into a keycode like f10, which bypasses the corresponding key symbol GDK_F10 entirely.

      "The change to Keysyms seems to be a red herring; ..."

      Fair enough. I didn't spend any time investigating that avenue, but was somewhat doubtful, hence: "... although, I don't know if that helps you directly ...".

      From your follow-up post:

      "Correction: Gtk3::Gdk::keyval_name does work."

      Glad to hear it. I don't know if that's the best solution — as stated, "I'm not a user of Gtk3." — but at least it is a solution. Others may come up with something better.

      — Ken

      Correction: Gtk3::Gdk::keyval_name does work. I was getting the same error message because my code contained two ->keyval_name calls, only one of which had been updated.

        ?Have you tried $event->keyval_name