Skip to content

Commit 7a10423

Browse files
committed
Fix keyboard handling
1 parent e01a445 commit 7a10423

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/interface.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -752,16 +752,26 @@ void ui_do_frame()
752752
// also use keydown events for ctrl characters, esc, and a few other
753753
// characters that the emulator will need
754754
if (io.WantCaptureKeyboard == false) {
755-
// send keys that are down (which we need for control keys backspace
756-
// etc. The underlying code will figure out what it needs to keep
755+
// get the text input keys from IMGUI and send whatever has been typed as normal
756+
// keys. special handling of ctrl keys, etc is done next
757+
if (io.KeyCtrl == false && io.KeyAlt == false && io.KeySuper == false) {
758+
for (auto n = 0; n < io.InputQueueCharacters.Size; n++)
759+
{
760+
unsigned int c = (unsigned int)io.InputQueueCharacters[n];
761+
keyboard_handle_event(c, false, io.KeyCtrl, io.KeyAlt, io.KeySuper);
762+
}
763+
}
764+
765+
// now handle non-printable characters
757766
for (auto i = 0; i < 512; i++) {
758767
int key = SDL_GetKeyFromScancode((SDL_Scancode)i);
759-
if (ImGui::IsKeyPressed(i)) {
760-
if ((key & SDLK_SCANCODE_MASK) || key < 256) {
761-
keyboard_handle_event(key, io.KeyShift, io.KeyCtrl, io.KeyAlt, io.KeySuper);
762-
}
763-
}
768+
if (io.KeyCtrl == true || (key <= SDLK_a || key > SDLK_z)) {
769+
if (ImGui::IsKeyPressed(i)) {
770+
keyboard_handle_event(key, io.KeyShift, io.KeyCtrl, io.KeyAlt, io.KeySuper);
771+
}
772+
}
764773
}
774+
765775
}
766776

767777
if (Show_main_menu) {

0 commit comments

Comments
 (0)