Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dpg.add_key_press_handler doesn't fire for Numpad Enter #2457

Open
mrmaffen opened this issue Dec 30, 2024 · 0 comments
Open

dpg.add_key_press_handler doesn't fire for Numpad Enter #2457

mrmaffen opened this issue Dec 30, 2024 · 0 comments
Labels
state: pending not addressed yet type: bug bug

Comments

@mrmaffen
Copy link

Version of Dear PyGui

Version: 2.0.0
Operating System: Windows 10

My Issue/Question

onEnterPressed is only called when pressing the Return-button. Using Enter on the numpad doesn't seem to work. I have looked for a way to bind another handler to the Enter button but could only find mvKey_Return in the list. Shouldn't mvKey_Return refer to both "Return" and "Enter" anyways? I'm pretty sure that's how it worked in the past, but I'm not sure what changed tbh.

My current workaround as suggested by v-ein on Discord: I'm using 627 as a hardcoded key code for my KeypadEnter callback.

dpg.add_key_press_handler(627, callback=onEnterPressed) # hardcode workaround for missing ImGuiKey_KeypadEnter

Here's @v-ein's comment since the explanation he gave is relevant for this issue:

v-ein — Yesterday at 22:34
For some reason DPG does not export the ImGui constant for this key (ImGuiKey_KeypadEnter) - not sure why, maybe there were portability issues... You can hardcode it yourself but this will break in a future version of DPG:

mvKey_NumPadEnter = 627 # the value obtained from key_press_handler

Alternatively, you can build your own DPG and add the corresponding constant to src/mvContext.cpp.

Or you can open an issue on GitHub and see if somebody checks if this constant leads to any unanticipated issues, and adds it if everything is fine.

Proposed solution therefore would be to either:

  1. make ImGuiKey_KeypadEnter accessible and bind it to "mvKey_NumPadEnter"
  2. mvKey_NumPadEnter = 627 # hardcode it and ask the gods if they intend to make this break in a horrible and insidious way

To Reproduce

Run the test script, try pressing Return and Enter

Expected behavior

Both buttons should lead to the callback function "onEnterPressed" being called

Standalone, minimal, complete and verifiable example

# Here's some code anyone can copy and paste to reproduce your issue
import dearpygui.dearpygui as dpg

def onEnterPressed():
  print ("onEnterPressed")

dpg.create_context()
dpg.create_viewport(title='Custom Title', width=600, height=300)

with dpg.handler_registry():
    dpg.add_key_press_handler(dpg.mvKey_Return, callback=onEnterPressed)

dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()
@mrmaffen mrmaffen added state: pending not addressed yet type: bug bug labels Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state: pending not addressed yet type: bug bug
Projects
None yet
Development

No branches or pull requests

1 participant