Skip to content

win32: Add keycode_to_key method for getting logical keys from physical#4454

Draft
Aceeri wants to merge 2 commits intorust-windowing:masterfrom
Aceeri:keycode_to_key_windows
Draft

win32: Add keycode_to_key method for getting logical keys from physical#4454
Aceeri wants to merge 2 commits intorust-windowing:masterfrom
Aceeri:keycode_to_key_windows

Conversation

@Aceeri
Copy link
Copy Markdown
Contributor

@Aceeri Aceeri commented Dec 30, 2025

#2678

Looking for thoughts on this, maybe it makes more sense to have a KeyboardLayout struct that you can query, but the main usecase I (and other game devs) have for this is giving correct mappings in games.

  • Tested on all platforms changed
  • Added an entry to the changelog module if knowledge of this change could be valuable to users
  • Updated documentation to reflect any user-facing changes, including notes of platform-specific behavior
  • Created or updated an example program if it would help users understand this functionality

@Aceeri Aceeri changed the title Add keycode_to_key method for getting logical keys from physical win32: Add keycode_to_key method for getting logical keys from physical Dec 30, 2025
@kchibisov
Copy link
Copy Markdown
Member

The problem is that on platforms like linux we'd need to have a running event loop. I'm also not sure if the function is MT safe, so implementing via global state like that won't generally work, and the function should be a method on a theoretical Keymap struct.

@Aceeri
Copy link
Copy Markdown
Contributor Author

Aceeri commented Dec 30, 2025

The problem is that on platforms like linux we'd need to have a running event loop. I'm also not sure if the function is MT safe, so implementing via global state like that won't generally work, and the function should be a method on a theoretical Keymap struct.

Gotcha, makes sense. Is the LayoutCache still usable if we were able to move this into the event loop + copy mappings over to a separate Keymap struct (stored on the Window?)? I'm not super familiar with how the main thread safeness works here tbh.

Also do you know if that applies to the appkit/macos version too (#4455)? Just trying to figure out which parts to try to salvage if I try to get this into the event loop.

@kchibisov
Copy link
Copy Markdown
Member

Can not speak for windows here, for linux caching is useless.

@Aceeri
Copy link
Copy Markdown
Contributor Author

Aceeri commented Dec 30, 2025

Can not speak for windows here, for linux caching is useless.

As in you can't cache across frames at all? I'll take a bit of a look into the linux code, I haven't really touched it before so I'm pretty blind.

@kchibisov
Copy link
Copy Markdown
Member

In a sense that there's no point to cache anything, you have access to the entire keymap and thus you get things from it. It could have cache internally...

@NeuralModder
Copy link
Copy Markdown

Looking for thoughts on this, maybe it makes more sense to have a KeyboardLayout struct that you can query, but the main usecase I (and other game devs) have for this is giving correct mappings in games.

Interesting that you would say this. I'm also looking to use this in a game, but according to my co-contributors the displayed key labels changing when the keyboard layout changes would be "disorienting", so we want to store the keyboard layout information (inside of RON) instead of just querying the currently active layout. So a KeyboardLayout struct seems like it'd make more sense for that, though we'd still probably have to distill it into something serializable and with only the information we need.

@madsmtm madsmtm added the DS - win32 Affects the Win32/Windows backend label Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DS - win32 Affects the Win32/Windows backend

Development

Successfully merging this pull request may close these issues.

4 participants