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

ImGuiKey Enum Missing Additional Keys for ABNT2 Keyboard Layout #8468

Open
leonardovac opened this issue Mar 7, 2025 · 7 comments
Open

ImGuiKey Enum Missing Additional Keys for ABNT2 Keyboard Layout #8468

leonardovac opened this issue Mar 7, 2025 · 7 comments

Comments

@leonardovac
Copy link

Version/Branch of Dear ImGui:

Commit 377a387, Branch: master

Back-ends:

imgui_impl_win32.cpp

Compiler, OS:

Windows 11 + MSVC 2022

Full config/build information:

No response

Details:

Our problem:

As mentioned in previous issues (#7136, #7201, #7306), the ImGuiKey enum is missing some keys present in non-US keyboard layouts. This issue is being opened primarily to add more data to the case, as well as reference the Dear ImGui keyboard layout mapping.

OS: Windows
Backend: Win32
Physical KB Layout: ABNT2
Input Layout: PT (Brazil ABNT2)

Physical Markings Virtual Key Code ImGuiKey 1.91.8
ç 0xBA = VK_OEM_1 ImGuiKey_Semicolon
; : 0xBF = VK_OEM_2 ImGuiKey_Slash
' " 0xC0 = VK_OEM_3 ImGuiKey_GraveAccent
/?° 0xC1 None
. 0xC2 None
´ ` 0xDB = VK_OEM_4 ImGuiKey_LeftBracket
]}º 0xDC = VK_OEM_5 ImGuiKey_Backslash
[{ª 0xDD = VK_OEM_6 ImGuiKey_RightBracket
~^ 0xDE = VK_OEM_7 ImGuiKey_Apostrophe
\| 0xE2 = VK_OEM_102 None

The following VK Codes: 0xC1, 0xC2, and 0xE2 aren't present in the ImGuiKey enum or ImGui_ImplWin32_KeyEventToImGuiKey. The first two codes don't appear on either the DE or FR keyboard layouts.

Keyboard example:

Image

My POV:

I believe filling the gaps is more important than "fixing" the divergent keys, which can be quite challenging.

case VK_OEM_102: return ImGuiKey_OEM102;
case 0xC1: return ImGuiKey_ReservedC1;
case 0xC2: return ImGuiKey_ReservedC2;
ImGuiKey_OEM102,                // "<>" or "\|" on RT 102-key keyboard.
ImGuiKey_ReservedC1,            // "/?" on 107-key ABNT2 keyboard.
ImGuiKey_ReservedC2,            // "." (Numpad) on 107-key ABNT2 keyboard.

Extra

There's a typo at line 8770 of imgui.cpp:
Current: // Those names a provided for debugging purpose and are not meant to be saved persistently not compared.
Intended?: // These names are provided for debugging purposes and are not meant to be saved persistently or compared.

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

Use ImGui::ShowDemoWindow() or:

ImGui::TextUnformatted("(WinAPI) Key: ");
for (std::uint16_t virtualKey = 1; virtualKey < 255; virtualKey++)
{
	if (GetAsyncKeyState(virtualKey) & 0x8000)
	{
		char buffer[256];
		GetKeyNameTextA(static_cast<LONG>(MapVirtualKeyW(virtualKey, MAPVK_VK_TO_VSC)) << 16 | 1 << 25, buffer, sizeof(buffer));
		ImGui::SameLine();
		ImGui::Text("[0x%X] %s", virtualKey, buffer);
	}
}

ImGui::TextUnformatted("(ImGui)  Key: ");
for (std::uint16_t imguiKey = ImGuiKey_NamedKey_BEGIN; imguiKey < ImGuiKey_NamedKey_END; imguiKey++)
{
	if (ImGui::IsKeyDown(static_cast<ImGuiKey>(imguiKey)))
	{
		ImGui::SameLine();
		ImGui::Text("[%d] %s", imguiKey, ImGui::GetKeyName(static_cast<ImGuiKey>(imguiKey)));
	}
}

With an ABNT2 keyboard.

@ocornut
Copy link
Owner

ocornut commented Mar 10, 2025

Thanks for your report.

I would absolutely need the Scancode for those keys to use this information.

const int scancode = (int)LOBYTE(HIWORD(lParam));

As specified in #7201 (comment)

@ocornut
Copy link
Owner

ocornut commented Mar 10, 2025

Could you also run with SDL3 and GLFW backend and print both scancode and keycodes for the 3 keys?
Thank you.

ocornut added a commit that referenced this issue Mar 10, 2025
…anslated keycodes when dealing with OEM keys + Added ImGuiKey_Oem102. (#7136, #7201, #7206, #7306, #7670, #7672, #8468)
@ocornut
Copy link
Owner

ocornut commented Mar 10, 2025

I have pushed a9e5382 which sensibly rework a few things.

  • A Oem102 key was added. It's emitted based on scancode 86 rather than VK_OEM_102.
  • Other surrounding keys are relying on scancodes rather than keycodes for Win32, SDL2, SDL3 backends.
  • As a result some of those keys are now "untranslated" aka referring to US layout.
  • There's no perfect solution to the larger problem discussed in other issues, so trying to come up with a reasonable one.

I would need more details from you on the ABNT keys.
Please log exact scancode and keycodes values for Win32, SDL2 and SDL3 backends.

More references:
https://docs.google.com/spreadsheets/d/1TwAHusBpxf_avmk03FUSrni17RP8qXmbJeDzs5fs0nY/edit?pli=1&gid=0#gid=0
https://kbdlayout.info/KBDBR/virtualkeys?arrangement=ABNT

ocornut added a commit that referenced this issue Mar 10, 2025
…7670, #7672, #8468)

+ more consistently use Ctrl+XXX instead of Ctrl-XXX.
@leonardovac
Copy link
Author

Results:

Win32

OS: Windows
Physical KB Layout: ABNT2
Input Layout: PT (Brazil ABNT2)

Physical Markings Scancode Keycode ImGuiKey 1.91.9 WIP (a9e5382)
ç 39 0xBA = VK_OEM_1 ImGuiKey_Semicolon
; : 53 0xBF = VK_OEM_2 ImGuiKey_Slash
' " 41 0xC0 = VK_OEM_3 ImGuiKey_GraveAccent
/?° 115 0xC1 None
. 126 0xC2 None
´ ` 26 0xDB = VK_OEM_4 ImGuiKey_LeftBracket
]}º 43 0xDC = VK_OEM_5 ImGuiKey_Backslash
[{ª 27 0xDD = VK_OEM_6 ImGuiKey_RightBracket
~^ 40 0xDE = VK_OEM_7 ImGuiKey_Apostrophe
\| 86 0xE2 = VK_OEM_102 ImGuiKey_Oem102
[00811] Key: Scancode = 39, VK = 00BA = 'Semicolon'
[01559] Key: Scancode = 53, VK = 00BF = 'Slash'
[01973] Key: Scancode = 41, VK = 00C0 = 'GraveAccent'
[02197] Key: Scancode = 115, VK = 00C1 = *UNHANDLED*
[02359] Key: Scancode = 126, VK = 00C2 = *UNHANDLED*
[02519] Key: Scancode = 26, VK = 00DB = 'LeftBracket'
[02700] Key: Scancode = 43, VK = 00DC = 'Backslash'
[02751] Key: Scancode = 27, VK = 00DD = 'RightBracket'
[02824] Key: Scancode = 40, VK = 00DE = 'Apostrophe'
[02902] Key: Scancode = 86, VK = 00E2 = 'Oem102'
SDL2 / SDL3

OS: Windows
Physical KB Layout: ABNT2
Input Layout: PT (Brazil ABNT2)

Physical Markings Scancode Keycode ImGuiKey 1.91.9 WIP (a9e5382)
ç 51 = SDL_SCANCODE_SEMICOLON 231 = ?¹ ImGuiKey_Semicolon
; : 56 = SDL_SCANCODE_SLASH 59 = SDLK_SEMICOLON ImGuiKey_Semicolon
' " 53 = SDL_SCANCODE_GRAVE 39 = SDLK_APOSTROPHE ImGuiKey_GraveAccent
/?° 135 = SDL_SCANCODE_INTERNATIONAL1 47 = SDLK_SLASH None
. 133 = SDL_SCANCODE_KP_COMMA 1073741957 = SDLK_KP_COMMA None
´ ` 47 = SDL_SCANCODE_LEFTBRACKET 180 = ?¹ ImGuiKey_LeftBracket
]}º 49 = SDL_SCANCODE_BACKSLASH 93 = SDLK_RIGHTBRACKET ImGuiKey_Backslash
[{ª 48 = SDL_SCANCODE_RIGHTBRACKET 91 = SDLK_LEFTBRACKET ImGuiKey_RightBracket
~^ 52 = SDL_SCANCODE_APOSTROPHE 126 = SDLK_TILDE ImGuiKey_Apostrophe
\| 100 = SDL_SCANCODE_NONUSBACKSLASH 92 = SDLK_BACKSLASH ImGuiKey_Oem102

¹ Keycodes macros goes up to 177 and then jump to 1073741881, skipping ´ ` (180) and ç (231).

Scan and Keycodes have the same value in SDL2/SDL3.
Keycode seems accurate.

[00760] Key: Scancode=51, Keycode=231 (000000E7) = 'Semicolon'
[00846] Key: Scancode=56, Keycode=59 (0000003B) = 'Semicolon'
[00910] Key: Scancode=53, Keycode=39 (00000027) = 'GraveAccent'
[00984] Key: Scancode=135, Keycode=47 (0000002F) *UNHANDLED*
[01053] Key: Scancode=133, Keycode=1073741957 (40000085) *UNHANDLED*
[01129] Key: Scancode=47, Keycode=180 (000000B4) = 'LeftBracket'
[01190] Key: Scancode=49, Keycode=93 (0000005D) = 'Backslash'
[01260] Key: Scancode=48, Keycode=91 (0000005B) = 'RightBracket'
[01311] Key: Scancode=52, Keycode=126 (0000007E) = 'Apostrophe'
[01364] Key: Scancode=100, Keycode=92 (0000005C) = 'Oem102'
GLFW

OS: Windows
Physical KB Layout: ABNT2
Input Layout: PT (Brazil ABNT2)

Physical Markings Scancode Keycode ImGuiKey 1.91.9 WIP (a9e5382)
ç 39 59 = GLFW_KEY_SEMICOLON ImGuiKey_Semicolon
; : 53 59 = GLFW_KEY_SEMICOLON ImGuiKey_Semicolon
' " 41 39 = GLFW_KEY_APOSTROPHE ImGuiKey_Apostrophe
/?° 115 -1 = ? None
. 126 -1 = ? None
´ ` 26 91 = GLFW_KEY_LEFT_BRACKET ImGuiKey_LeftBracket
]}º 43 93 = GLFW_KEY_RIGHT_BRACKET ImGuiKey_RightBracket
[{ª 27 91 = GLFW_KEY_LEFT_BRACKET ImGuiKey_LeftBracket
~^ 40 39 = GLFW_KEY_APOSTROPHE ImGuiKey_Apostrophe
\| 86 92 = GLFW_KEY_BACKSLASH ImGuiKey_Backlash

Scancodes with the same values as in Win32.

[00984] Key Scancode:39 Keycode:59 = 'Semicolon'
[01176] Key Scancode:53 Keycode:59 = 'Semicolon'
[01225] Key Scancode:41 Keycode:39 = 'Apostrophe'
[01305] Key Scancode:115 Keycode:-1 = *UNHANDLED
[01399] Key Scancode:126 Keycode:-1 = *UNHANDLED
[01486] Key Scancode:26 Keycode:91 = 'LeftBracket'
[01584] Key Scancode:43 Keycode:93 = 'RightBracket'
[01632] Key Scancode:27 Keycode:91 = 'LeftBracket'
[01675] Key Scancode:40 Keycode:39 = 'Apostrophe'
[01723] Key Scancode:86 Keycode:92 = 'Backslash'

ocornut added a commit that referenced this issue Mar 11, 2025
@ocornut
Copy link
Owner

ocornut commented Mar 11, 2025

Thanks a lot for the details.
I pushed 557c77e with support for Win32 and GLFW backend, but I don't know if it is possible to do the same for SDL backends.

What do you think?
I wouldn't mind closing this if you are happy enough about the result :)

@leonardovac
Copy link
Author

We may consider renaming ImGuiKey_AbntC1 and ImGuiKey_AbntC2 to something more user-friendly, as 0xC1/0xC2 only makes sense in a Windows context.
Maybe: ImGuiKey_AbntSlash and ImGuiKey_AbntNumpadPeriod

These are the results after 557c77e:

Windows

Table

OS: Windows
Physical KB Layout: ABNT2
Input Layout: PT (Brazil ABNT2)

Physical Markings Scancode Keycode ImGuiKey 1.91.9 WIP (557c77e)
ç 39 0xBA = VK_OEM_1 ImGuiKey_Semicolon
; : 53 0xBF = VK_OEM_2 ImGuiKey_Slash
' " 41 0xC0 = VK_OEM_3 ImGuiKey_GraveAccent
/?° 115 0xC1 ImGuiKey_AbntC1
. 126 0xC2 ImGuiKey_AbntC2
´ ` 26 0xDB = VK_OEM_4 ImGuiKey_LeftBracket
]}º 43 0xDC = VK_OEM_5 ImGuiKey_Backslash
[{ª 27 0xDD = VK_OEM_6 ImGuiKey_RightBracket
~^ 40 0xDE = VK_OEM_7 ImGuiKey_Apostrophe
\| 86 0xE2 = VK_OEM_102 ImGuiKey_Oem102
  • "All keys mapped." – Every key on the keyboard is properly registered, with none left unhandled.
  • "No duplicate key mappings." – Each key has its own unique enum, with no duplicates.
  • "Enums match physical markings." – The assigned enums align with the physical key labels

Veredict: ✅ PASS

SDL2 / SDL3

Table

OS: Windows
Physical KB Layout: ABNT2
Input Layout: PT (Brazil ABNT2)

Physical Markings Scancode Keycode ImGuiKey 1.91.9 WIP (557c77e)
ç 51 = SDL_SCANCODE_SEMICOLON 231 = ?¹ ImGuiKey_Semicolon
; : 56 = SDL_SCANCODE_SLASH 59 = SDLK_SEMICOLON ImGuiKey_Semicolon
' " 53 = SDL_SCANCODE_GRAVE 39 = SDLK_APOSTROPHE ImGuiKey_GraveAccent
/?° 135 = SDL_SCANCODE_INTERNATIONAL1 47 = SDLK_SLASH None
. 133 = SDL_SCANCODE_KP_COMMA 1073741957 = SDLK_KP_COMMA None
´ ` 47 = SDL_SCANCODE_LEFTBRACKET 180 = ?¹ ImGuiKey_LeftBracket
]}º 49 = SDL_SCANCODE_BACKSLASH 93 = SDLK_RIGHTBRACKET ImGuiKey_Backslash
[{ª 48 = SDL_SCANCODE_RIGHTBRACKET 91 = SDLK_LEFTBRACKET ImGuiKey_RightBracket
~^ 52 = SDL_SCANCODE_APOSTROPHE 126 = SDLK_TILDE ImGuiKey_Apostrophe
\| 100 = SDL_SCANCODE_NONUSBACKSLASH 92 = SDLK_BACKSLASH ImGuiKey_Oem102
  • "All keys mapped." – Every key on the keyboard is properly registered, with none left unhandled.
  • "No duplicate key mappings." – Each key has its own unique enum, with no duplicates.
  • "Enums match physical markings." – The assigned enums align with the physical key labels

Veredict: ❌ FAIL

GLFW

Table

OS: Windows
Physical KB Layout: ABNT2
Input Layout: PT (Brazil ABNT2)

Physical Markings Scancode Keycode ImGuiKey 1.91.9 WIP (557c77e)
ç 39 59 = GLFW_KEY_SEMICOLON ImGuiKey_Semicolon
; : 53 59 = GLFW_KEY_SEMICOLON ImGuiKey_Semicolon
' " 41 39 = GLFW_KEY_APOSTROPHE ImGuiKey_Apostrophe
/?° 115 -1 = ? ImGuiKey_AbntC1
. 126 -1 = ? ImGuiKey_AbntC2
´ ` 26 91 = GLFW_KEY_LEFT_BRACKET ImGuiKey_LeftBracket
]}º 43 93 = GLFW_KEY_RIGHT_BRACKET ImGuiKey_RightBracket
[{ª 27 91 = GLFW_KEY_LEFT_BRACKET ImGuiKey_LeftBracket
~^ 40 39 = GLFW_KEY_APOSTROPHE ImGuiKey_Apostrophe
\| 86 92 = GLFW_KEY_BACKSLASH ImGuiKey_Backlash
  • "All keys mapped." – Every key on the keyboard is properly registered, with none left unhandled.
  • "No duplicate key mappings." – Each key has its own unique enum, with no duplicates.
  • "Enums match physical markings." – The assigned enums align with the physical key labels

Veredict: ❌ FAIL

Local Changes

Messed around to see what I would get, here are the results:

Windows

Not changed.

SDL2/ SDL3

Using Keycode for the majority of them, just for example:

Table 1

OS: Windows
Physical KB Layout: ABNT2
Input Layout: PT (Brazil ABNT2)

Physical Markings Scancode Keycode ImGuiKey 1.91.9 WIP leonardovac/imgui/ 81cd7e2
ç 51 = SDL_SCANCODE_SEMICOLON 231 = ?¹ ImGuiKey_ReservedAbntCeCedilha
; : 56 = SDL_SCANCODE_SLASH 59 = SDLK_SEMICOLON ImGuiKey_Semicolon
' " 53 = SDL_SCANCODE_GRAVE 39 = SDLK_APOSTROPHE ImGuiKey_Apostrophe
/?° 135 = SDL_SCANCODE_INTERNATIONAL1 47 = SDLK_SLASH ImGuiKey_Slash
. 133 = SDL_SCANCODE_KP_COMMA 1073741957 = SDLK_KP_COMMA ImGuiKey_AbntNumpadPeriod (C2)
´ ` 47 = SDL_SCANCODE_LEFTBRACKET 180 = ?¹ ImGuiKey_GraveAccent
]}º 49 = SDL_SCANCODE_BACKSLASH 93 = SDLK_RIGHTBRACKET ImGuiKey_RightBracket
[{ª 48 = SDL_SCANCODE_RIGHTBRACKET 91 = SDLK_LEFTBRACKET ImGuiKey_LeftBracket
~^ 52 = SDL_SCANCODE_APOSTROPHE 126 = SDLK_TILDE ImGuiKey_ReservedAbntTilde
\| 100 = SDL_SCANCODE_NONUSBACKSLASH 92 = SDLK_BACKSLASH ImGuiKey_Oem102
Table 2

OS: Windows
Physical KB Layout: ABNT2
Input Layout: US

Physical Markings Expected Markings Scancode Keycode ImGuiKey 1.91.9 WIP leonardovac/imgui/ 81cd7e2
ç ; 51 = SDL_SCANCODE_SEMICOLON 59 = SDLK_SEMICOLON ImGuiKey_Semicolon
; : / 56 = SDL_SCANCODE_SLASH 47 = SDLK_SLASH ImGuiKey_Slash
' " ` 53 = SDL_SCANCODE_GRAVE 96 = SDLK_GRAVE ImGuiKey_GraveAccent
/?° 135 = SDL_SCANCODE_INTERNATIONAL1 0 None
. 133 = SDL_SCANCODE_KP_COMMA 1073741957 = SDLK_KP_COMMA ImGuiKey_AbntC2
´ ` [ 47 = SDL_SCANCODE_LEFTBRACKET 91 = SDLK_LEFTBRACKET ImGuiKey_LeftBracket
]}º \ 49 = SDL_SCANCODE_BACKSLASH 92 = SDLK_BACKSLASH ImGuiKey_BackSlash
[{ª ] 48 = SDL_SCANCODE_RIGHTBRACKET 93 = SDLK_RIGHTBRACKET ImGuiKey_RightBracket
~^ ' 52 = SDL_SCANCODE_APOSTROPHE 39 = SDLK_APOSTROPHE ImGuiKey_Apostrophe
\| 100 = SDL_SCANCODE_NONUSBACKSLASH 92 = SDLK_BACKSLASH ImGuiKey_Oem102
Debug Log
[40266] Key: Scancode=51, Keycode=59 (0000003B) = 'Semicolon'
[40304] Key: Scancode=56, Keycode=47 (0000002F) = 'Slash'
[40354] Key: Scancode=53, Keycode=96 (00000060) = 'GraveAccent'
[40418] Key: Scancode=135, Keycode=0 (00000000) *UNHANDLED*
[40484] Key: Scancode=133, Keycode=1073741957 (40000085) = 'AbntC2'
[40553] Key: Scancode=47, Keycode=91 (0000005B) = 'LeftBracket'
[40627] Key: Scancode=49, Keycode=92 (0000005C) = 'Backslash'
[40692] Key: Scancode=48, Keycode=93 (0000005D) = 'RightBracket'
[40742] Key: Scancode=52, Keycode=39 (00000027) = 'Apostrophe'
[40811] Key: Scancode=100, Keycode=92 (0000005C) = 'Oem102'
  • "All keys mapped." – Every key on the keyboard is properly registered, with none left unhandled.
  • "No duplicate key mappings." – Each key has its own unique enum, with no duplicates.
  • "Enums match physical markings." – The assigned enums align with the physical key labels

Veredict: ✅ PASS

GLFW

Backend doesn’t differentiate between some keys...

Veredict: ❌ FAIL

Sorry, something went wrong.

ocornut added a commit that referenced this issue Mar 13, 2025
…2: added support. (#8468)"

This reverts commit 557c77e.
@ocornut
Copy link
Owner

ocornut commented Mar 13, 2025

I'm temporarily reverting the previous commit. The topic seem a little too complicated for me to handle now.
Thanks for your detailed report, that's really helpful. Tho for those tests I think you would need to perform similar tests on other keyboards and/or other layouts too. It's hard to guaranteed that e.g. SDL_SCANCODE_KP_COMMA necessary is AbntNumpadPeriod.

(Your commit link: https://www.github.com/leonardovac/imgui/commit/81cd7e2bd81912e241f4220cff54550e7db79d60)

Q: why/how do you need to use those keys within the context of Dear ImGui ?

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