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

Unclear how to hookup text input with SDL #239

Closed
TimothyWrightSoftware opened this issue Jun 2, 2015 · 5 comments
Closed

Unclear how to hookup text input with SDL #239

TimothyWrightSoftware opened this issue Jun 2, 2015 · 5 comments

Comments

@TimothyWrightSoftware
Copy link

Added this code:

    ImGuiIO& io = ImGui::GetIO();
    io.KeyMap[ImGuiKey_Tab] = SDLK_TAB;                 
    io.KeyMap[ImGuiKey_LeftArrow] = SDLK_LEFT;
    io.KeyMap[ImGuiKey_RightArrow] = SDLK_RIGHT;
    io.KeyMap[ImGuiKey_UpArrow] = SDLK_UP;
    io.KeyMap[ImGuiKey_DownArrow] = SDLK_DOWN;
    io.KeyMap[ImGuiKey_Home] = SDLK_HOME;
    io.KeyMap[ImGuiKey_End] = SDLK_END;
    io.KeyMap[ImGuiKey_Delete] = SDLK_DELETE;
    io.KeyMap[ImGuiKey_Backspace] = SDLK_BACKSPACE;
    io.KeyMap[ImGuiKey_Enter] = SDLK_KP_ENTER;
    io.KeyMap[ImGuiKey_Escape] = SDLK_ESCAPE;
    io.KeyMap[ImGuiKey_A] = SDLK_a;
    io.KeyMap[ImGuiKey_C] = SDLK_c;
    io.KeyMap[ImGuiKey_V] = SDLK_v;
    io.KeyMap[ImGuiKey_X] = SDLK_x;
    io.KeyMap[ImGuiKey_Y] = SDLK_y;
    io.KeyMap[ImGuiKey_Z] = SDLK_z;

I get this assert:

Assertion failed: key_index >= 0 && key_index < ((int)(sizeof(g.IO.KeysDown)/sizeof(*g.IO.KeysDown))), file c:\game_dev\opengl_tests\gui_test\src\imgui.cpp, line 2850

Also, the application just crashes. Not really sure how to proceed.

@TimothyWrightSoftware
Copy link
Author

On a side note, when I'm done with all this I'd be happy to give you a pull request with the example SDL code so other's crazy like me don't have to go through the extra pain.

@ocornut
Copy link
Owner

ocornut commented Jun 2, 2015

The values are used as indices into the KeyDown[] away which is arbitrary 512 long. Recent SDL uses value with bit 30 set so that'll fail to be used as an index.

Solution 1
Use the SDL_SCANCODE_* values.

Solution 2
Uses small indices, e.g you can set the mapping table like that:

    ImGuiIO& io = ImGui::GetIO();
    io.KeyMap[ImGuiKey_Tab] = ImGuiKey_Tab;                 
    io.KeyMap[ImGuiKey_LeftArrow] = ImGuiKey_LeftArrow;
    io.KeyMap[ImGuiKey_RightArrow] = ImGuiKey_RightArrow;
[...]

And then update the io.KeysDown[] array using those as indices.

Solution 3
I need to change the keyboard system anyway allow passing keyboard presses as events, but it likely won't be done soon.

There's already two PR for SDL.
More recent one
#233
Old one (was quite incomplete to start with)
#58

@TimothyWrightSoftware
Copy link
Author

Well that example will be useful. SCANCODEs it is.

@ocornut
Copy link
Owner

ocornut commented Jun 2, 2015

Sorry I haven't merged an SDL example yet, I'm swamped.

@TimothyWrightSoftware
Copy link
Author

No Problem. It's documented, so someone else can find this bug report and get there. It you didn't make such a good library you wouldn't have this problem. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants