2

I wrote a small GTK+ 2+ program (in Python) that responds to a button click by sending a gtk.Event to simulate a key press. It works fine on every version of Ubuntu that I have including Kubuntu, but it fails on every version of Lubuntu.

On Lubuntu, the character that gets transmitted by the Event is determined by event.hardware_keycode; event.keyval doesn't matter. On every other platform, the character is determined by event.keyval and event.hardware_keycode doesn't matter.

The problem is that as far as I can tell it is not possible to specify Unicode characters through event.hardware_keycode because they do not have a corresponding key. Unicode works fine on other platforms using keyval.

Does anyone know how to get Lubuntu to behave the same as Ubuntu in this regard? If not, can anyone suggest a better place to post this question?

Here's a simple test program, as requested by Sneetsher:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import gtk

class KeyPressTest:
    def __init__(self):
        button = gtk.Button("Test")
        button.connect('clicked', self.on_button_clicked)
        button.set_can_focus(False)
        entry = gtk.Entry()
        vbox = gtk.VBox()
        vbox.pack_start(button)
        vbox.pack_start(entry, expand=False)
        window = gtk.Window()
        window.connect('destroy', lambda w: gtk.main_quit())
        window.add(vbox)
        window.show_all()

    def on_button_clicked(self, button):
        # Lubuntu ignores keyval, so you get "a" in the entry when you click
        # the button.  Ubuntu ignores hardware_keycode, so you get À.  I could
        # make the program work on all platforms by specifying both, but what
        # is hardware_keycode for unicode characters?
        event = gtk.gdk.Event(gtk.gdk.KEY_PRESS)
        event.keyval = int(gtk.gdk.unicode_to_keyval(ord(unicode(u"À"))))
        event.hardware_keycode = 38  # hardware keycode for "a"
        event.window = button.get_window()
        event.put()

if __name__ == "__main__":
    u = KeyPressTest()
    gtk.main()

Here's the answer: Lubuntu has an environment variable set to specify the input method:

GTK_IM_MODULE=xim

Unset that variable and the program above works.

2
  • Exactly, I've end up with same results, Used im-config to set a ibus as default input system. You better post an answer. Avoid putting it within question post. See About
    – user.dz
    Jan 6, 2015 at 22:55
  • Jeffrey, could you post an answer.
    – user.dz
    Jan 17, 2015 at 8:28

1 Answer 1

0

There is no hardware_keycode for a unicode character unless you can type it by pressing a key. See xmodmap about mapping a unicode character to a physical keyboard key. Enjoy.

1
  • I think the same positions on the keyboard correspond to the same keycodes on international keyboards as well.
    – Henry
    Feb 9, 2015 at 10:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .