pthom / imgui_bundle

Dear ImGui Bundle: an extensive set of Ready-to-use widgets and libraries, based on ImGui. Start your first app in 5 lines of code, or less. Whether you prefer Python or C++, this pack has your back!
https://pthom.github.io/imgui_bundle/
MIT License
590 stars 62 forks source link

Handling system key mappings for imgui.is_key_down() #190

Closed bgribble closed 3 months ago

bgribble commented 3 months ago

Hi, I'm moving an app that was originally written in Gtk/Clutter in Python to Dear ImGui. I started with pyimgui but I really need to use implot and a nodes-and-links package such as imnodes or imgui_node_editor so imgui_bundle seems just right.

My app does a lot of keyboard handling for custom mappings of all kinds of key combos so I am using this basic approach (pulled from a suggestion by ocornut) to find out all the keys that are down:

def keys_down():
    keys = []
    for index in range(512, int(imgui.Key.count)):
        key_down = imgui.is_key_down(imgui.Key(index))
        if key_down:
            keys.append(imgui.Key(index))
    return set(keys)

This mostly works, but only give me the keys whose scancodes are pressed down -- i.e. I have shift lock and control swapped at the window manager level, and when I press the key that's marked "Caps lock" on my keyboard I get imgui.Key.caps_lock even though that's actually the control key for me.

Is there a layer of representation I can access that has the keys as other windows see them, rather than just the scan codes?

pthom commented 3 months ago

Hello,

This issue is more related to Dear ImGui in itself. May be you should have a look at this issue which summarizes recent changes in the keyboard api, as well as the other issues related to keyboard mapping within ImGui.