22
22
23
23
// CHANGELOG
24
24
// (minor and older changes stripped away, please see git history for details)
25
+ // 2024-07-02: Update for SDL3 api changes: SDLK_x renames and SDLK_KP_x removals (#7761, #7762).
25
26
// 2024-07-01: Update for SDL3 api changes: SDL_SetTextInputRect() changed to SDL_SetTextInputArea().
26
27
// 2024-06-26: Update for SDL3 api changes: SDL_StartTextInput()/SDL_StopTextInput()/SDL_SetTextInputRect() functions signatures.
27
28
// 2024-06-24: Update for SDL3 api changes: SDL_EVENT_KEY_DOWN/SDL_EVENT_KEY_UP contents.
@@ -146,8 +147,29 @@ static void ImGui_ImplSDL3_SetPlatformImeData(ImGuiViewport* viewport, ImGuiPlat
146
147
}
147
148
}
148
149
149
- static ImGuiKey ImGui_ImplSDL3_KeycodeToImGuiKey ( int keycode)
150
+ static ImGuiKey ImGui_ImplSDL3_KeyEventToImGuiKey (SDL_Keycode keycode, SDL_Scancode scancode )
150
151
{
152
+ // Keypad doesn't have individual key values in SDL3
153
+ switch (scancode)
154
+ {
155
+ case SDL_SCANCODE_KP_0: return ImGuiKey_Keypad0;
156
+ case SDL_SCANCODE_KP_1: return ImGuiKey_Keypad1;
157
+ case SDL_SCANCODE_KP_2: return ImGuiKey_Keypad2;
158
+ case SDL_SCANCODE_KP_3: return ImGuiKey_Keypad3;
159
+ case SDL_SCANCODE_KP_4: return ImGuiKey_Keypad4;
160
+ case SDL_SCANCODE_KP_5: return ImGuiKey_Keypad5;
161
+ case SDL_SCANCODE_KP_6: return ImGuiKey_Keypad6;
162
+ case SDL_SCANCODE_KP_7: return ImGuiKey_Keypad7;
163
+ case SDL_SCANCODE_KP_8: return ImGuiKey_Keypad8;
164
+ case SDL_SCANCODE_KP_9: return ImGuiKey_Keypad9;
165
+ case SDL_SCANCODE_KP_PERIOD: return ImGuiKey_KeypadDecimal;
166
+ case SDL_SCANCODE_KP_DIVIDE: return ImGuiKey_KeypadDivide;
167
+ case SDL_SCANCODE_KP_MULTIPLY: return ImGuiKey_KeypadMultiply;
168
+ case SDL_SCANCODE_KP_MINUS: return ImGuiKey_KeypadSubtract;
169
+ case SDL_SCANCODE_KP_PLUS: return ImGuiKey_KeypadAdd;
170
+ case SDL_SCANCODE_KP_ENTER: return ImGuiKey_KeypadEnter;
171
+ case SDL_SCANCODE_KP_EQUALS: return ImGuiKey_KeypadEqual;
172
+ }
151
173
switch (keycode)
152
174
{
153
175
case SDLK_TAB: return ImGuiKey_Tab;
@@ -181,23 +203,6 @@ static ImGuiKey ImGui_ImplSDL3_KeycodeToImGuiKey(int keycode)
181
203
case SDLK_NUMLOCKCLEAR: return ImGuiKey_NumLock;
182
204
case SDLK_PRINTSCREEN: return ImGuiKey_PrintScreen;
183
205
case SDLK_PAUSE: return ImGuiKey_Pause;
184
- case SDLK_KP_0: return ImGuiKey_Keypad0;
185
- case SDLK_KP_1: return ImGuiKey_Keypad1;
186
- case SDLK_KP_2: return ImGuiKey_Keypad2;
187
- case SDLK_KP_3: return ImGuiKey_Keypad3;
188
- case SDLK_KP_4: return ImGuiKey_Keypad4;
189
- case SDLK_KP_5: return ImGuiKey_Keypad5;
190
- case SDLK_KP_6: return ImGuiKey_Keypad6;
191
- case SDLK_KP_7: return ImGuiKey_Keypad7;
192
- case SDLK_KP_8: return ImGuiKey_Keypad8;
193
- case SDLK_KP_9: return ImGuiKey_Keypad9;
194
- case SDLK_KP_PERIOD: return ImGuiKey_KeypadDecimal;
195
- case SDLK_KP_DIVIDE: return ImGuiKey_KeypadDivide;
196
- case SDLK_KP_MULTIPLY: return ImGuiKey_KeypadMultiply;
197
- case SDLK_KP_MINUS: return ImGuiKey_KeypadSubtract;
198
- case SDLK_KP_PLUS: return ImGuiKey_KeypadAdd;
199
- case SDLK_KP_ENTER: return ImGuiKey_KeypadEnter;
200
- case SDLK_KP_EQUALS: return ImGuiKey_KeypadEqual;
201
206
case SDLK_LCTRL: return ImGuiKey_LeftCtrl;
202
207
case SDLK_LSHIFT: return ImGuiKey_LeftShift;
203
208
case SDLK_LALT: return ImGuiKey_LeftAlt;
@@ -217,32 +222,32 @@ static ImGuiKey ImGui_ImplSDL3_KeycodeToImGuiKey(int keycode)
217
222
case SDLK_7: return ImGuiKey_7;
218
223
case SDLK_8: return ImGuiKey_8;
219
224
case SDLK_9: return ImGuiKey_9;
220
- case SDLK_a : return ImGuiKey_A;
221
- case SDLK_b : return ImGuiKey_B;
222
- case SDLK_c : return ImGuiKey_C;
223
- case SDLK_d : return ImGuiKey_D;
224
- case SDLK_e : return ImGuiKey_E;
225
- case SDLK_f : return ImGuiKey_F;
226
- case SDLK_g : return ImGuiKey_G;
227
- case SDLK_h : return ImGuiKey_H;
228
- case SDLK_i : return ImGuiKey_I;
229
- case SDLK_j : return ImGuiKey_J;
230
- case SDLK_k : return ImGuiKey_K;
231
- case SDLK_l : return ImGuiKey_L;
232
- case SDLK_m : return ImGuiKey_M;
233
- case SDLK_n : return ImGuiKey_N;
234
- case SDLK_o : return ImGuiKey_O;
235
- case SDLK_p : return ImGuiKey_P;
236
- case SDLK_q : return ImGuiKey_Q;
237
- case SDLK_r : return ImGuiKey_R;
238
- case SDLK_s : return ImGuiKey_S;
239
- case SDLK_t : return ImGuiKey_T;
240
- case SDLK_u : return ImGuiKey_U;
241
- case SDLK_v : return ImGuiKey_V;
242
- case SDLK_w : return ImGuiKey_W;
243
- case SDLK_x : return ImGuiKey_X;
244
- case SDLK_y : return ImGuiKey_Y;
245
- case SDLK_z : return ImGuiKey_Z;
225
+ case SDLK_A : return ImGuiKey_A;
226
+ case SDLK_B : return ImGuiKey_B;
227
+ case SDLK_C : return ImGuiKey_C;
228
+ case SDLK_D : return ImGuiKey_D;
229
+ case SDLK_E : return ImGuiKey_E;
230
+ case SDLK_F : return ImGuiKey_F;
231
+ case SDLK_G : return ImGuiKey_G;
232
+ case SDLK_H : return ImGuiKey_H;
233
+ case SDLK_I : return ImGuiKey_I;
234
+ case SDLK_J : return ImGuiKey_J;
235
+ case SDLK_K : return ImGuiKey_K;
236
+ case SDLK_L : return ImGuiKey_L;
237
+ case SDLK_M : return ImGuiKey_M;
238
+ case SDLK_N : return ImGuiKey_N;
239
+ case SDLK_O : return ImGuiKey_O;
240
+ case SDLK_P : return ImGuiKey_P;
241
+ case SDLK_Q : return ImGuiKey_Q;
242
+ case SDLK_R : return ImGuiKey_R;
243
+ case SDLK_S : return ImGuiKey_S;
244
+ case SDLK_T : return ImGuiKey_T;
245
+ case SDLK_U : return ImGuiKey_U;
246
+ case SDLK_V : return ImGuiKey_V;
247
+ case SDLK_W : return ImGuiKey_W;
248
+ case SDLK_X : return ImGuiKey_X;
249
+ case SDLK_Y : return ImGuiKey_Y;
250
+ case SDLK_Z : return ImGuiKey_Z;
246
251
case SDLK_F1: return ImGuiKey_F1;
247
252
case SDLK_F2: return ImGuiKey_F2;
248
253
case SDLK_F3: return ImGuiKey_F3;
@@ -338,8 +343,9 @@ bool ImGui_ImplSDL3_ProcessEvent(const SDL_Event* event)
338
343
case SDL_EVENT_KEY_DOWN:
339
344
case SDL_EVENT_KEY_UP:
340
345
{
346
+ // IMGUI_DEBUG_LOG("SDL_EVENT_KEY_%d: key=%d, scancode=%d, mod=%X\n", (event->type == SDL_EVENT_KEY_DOWN) ? "DOWN" : "UP", event->key.key, event->key.scancode, event->key.mod);
341
347
ImGui_ImplSDL3_UpdateKeyModifiers ((SDL_Keymod)event->key .mod );
342
- ImGuiKey key = ImGui_ImplSDL3_KeycodeToImGuiKey (event->key .key );
348
+ ImGuiKey key = ImGui_ImplSDL3_KeyEventToImGuiKey (event->key .key , event-> key . scancode );
343
349
io.AddKeyEvent (key, (event->type == SDL_EVENT_KEY_DOWN));
344
350
io.SetKeyEventNativeData (key, event->key .key , event->key .scancode , event->key .scancode ); // To support legacy indexing (<1.87 user code). Legacy backend uses SDLK_*** as indices to IsKeyXXX() functions.
345
351
return true ;
0 commit comments