Comments (3)
I've solved this issue in my code by using the SDL2 "scancodes" instead of the key codes. If anyone else is using SDL2 this is how I have it setup:
//
// setup SDL2 keymapping
//
io.KeyMap[ImGuiKey_Tab] = SDL_GetScancodeFromKey( SDLK_TAB );
io.KeyMap[ImGuiKey_LeftArrow] = SDL_GetScancodeFromKey( SDLK_LEFT );
io.KeyMap[ImGuiKey_RightArrow] = SDL_GetScancodeFromKey( SDLK_RIGHT );
io.KeyMap[ImGuiKey_UpArrow] = SDL_GetScancodeFromKey( SDLK_UP );
io.KeyMap[ImGuiKey_DownArrow] = SDL_GetScancodeFromKey( SDLK_DOWN );
io.KeyMap[ImGuiKey_Home] = SDL_GetScancodeFromKey( SDLK_HOME );
io.KeyMap[ImGuiKey_End] = SDL_GetScancodeFromKey( SDLK_END );
io.KeyMap[ImGuiKey_Delete] = SDL_GetScancodeFromKey( SDLK_DELETE );
io.KeyMap[ImGuiKey_Backspace] = SDL_GetScancodeFromKey( SDLK_BACKSPACE );
io.KeyMap[ImGuiKey_Enter] = SDL_GetScancodeFromKey( SDLK_RETURN );
io.KeyMap[ImGuiKey_Escape] = SDL_GetScancodeFromKey( 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;
And then later I parse the events more or less like this (some code missing)
case SDL_KEYDOWN:
case SDL_KEYUP:
{
SDL_Scancode key = SDL_GetScancodeFromKey(_keycode);
if (key>=0 && key<512)
{
SDL_Keymod modstate = SDL_GetModState();
ImGuiIO& io = ImGui::GetIO();
if (bPressed)
{
io.KeysDown[key] = true;
}
else
{
io.KeysDown[key] = false;
}
io.KeyCtrl = (modstate & KMOD_CTRL) != 0;
io.KeyShift = (modstate & KMOD_SHIFT) != 0;
}
}
//
case SDL_TEXTINPUT:
{
for (uint i=0; i<text.length(); i++)
{
uint32_t keycode = text[i];
if (keycode>=32 && keycode<=255)
{
//printable ASCII characters
ImGui::GetIO().AddInputCharacter( (char)keycode );
}
}
}
from imgui.
I'll close this for now. The issue you reported is valid and still exist but until we find a library where key values cannot fit within 0..512 i don't think it is worth fixing.
(I don't have an idea for a fix that would be lightweight and not confusing for the most common user atm)
from imgui.
At worse one can easily store the 17 keys that ImGui use in a contiguous array and just pass that to ImGui.
So instead of doing
io.KeyMap[ImGuiKey_Tab] = SDL_GetScancodeFromKey( SDLK_TAB );
io.KeyMap[ImGuiKey_LeftArrow] = SDL_GetScancodeFromKey( SDLK_LEFT );
and being unable to fill the KeyDown[] array you can do:
io.KeyMap[ImGuiKey_Tab] = ImGuiKey_Tab;
io.KeyMap[ImGuiKey_LeftArrow] = ImGuiKey_LeftArrow;
and fill the KeyDown[] array using ImGuiKey_* indices. The code would only be 2 lines longer to setup the keymap table with a for loop.
from imgui.
Related Issues (20)
- ImGui not using the entire screen surface with Android NDK HOT 2
- Windows + V doesn't paste value using SDL HOT 4
- DragFloat: incorrect work of clamp value, when we set it by ctrl+click HOT 1
- Strange endian behaviour causing ImU32 colors to be flipped HOT 5
- How to know why glad failed to load. HOT 1
- Can't hide "Hide tab bar" button when window is in dock HOT 7
- implot breaks on IMGUI_DEFINE_MATH_OPERATORS HOT 4
- Dealing with the glfw window HOT 4
- Issue with ImGui_ImplMetal_Shutdown - Crashes inside ImGui_ImplMetal_DestroyFontsTexture HOT 2
- no payload received for std::string HOT 7
- OpenGL backend + OpenCascades: black screen is shown. HOT 4
- Dynamic Error Modals - spawning them with runtime errors - handling their return values HOT 7
- Mouse position issue HOT 5
- Weird behaviour when setting ImGuiStyle::Alpha before ImGui::Begin when docked HOT 2
- Slight lag on opening comboboxes HOT 8
- Lag when changing mouse cursor (was: lag hovering over text inputs) HOT 4
- Drag drop does not work with Child HOT 6
- When ImGuiChildFlags_AlwaysUseWindowPadding is enabled, the left and right padding widths of the Child are different, but the Parent window is the same HOT 5
- No scrolling region or selectable items inside Child HOT 3
- Can't write in any field. (1.90.5-docking with SDL3) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from imgui.