✅ How do I replace each character with a character that corresponds to the standard English layout?
There is a string with the characters "ЙЦУКЕН". It corresponds to the "QWERTY" string of the standard English layout. Is it possible to replace each character with the corresponding character of the standard English layout without creating my own dictionaries?
11 Replies
you need to map the characters somehow
what is it specifically you are trying to do?
Let's imagine a simple console application. It takes each string from string[] args. And replaces each character (e.g., "Й") with the English layout character ("Q") corresponding to the key.
I start the application and pass the string
"myapp -йцукен"
The application gives me the result "qwerty".
the simplest solution is a dictionary
it could be possible to do something with keycodes and system layouts but I don't know the specific possibility
Yeah, but that's exactly what I want to avoid. I hope there are more universal options
How are the characters related to each other?
position on the keyboard
the physical keypress that produces them
so from the actual key input events (from polling input) you could maybe do this based on the keycode rather than the character, but you would still need mappings of the keycode to the chars you want
In theory, Windows has a dictionary. I'd like to refer to it
For example, go through all connected keyboard layouts. And just then output all the variants
This might be a win32 function or possibly registry
I know there's utilities that let you "remap" keys, you could look at how those work but only read those mappings
I found this from winforms that seems to provide the installed input languages, but I don't think it provides the key mappings:
https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.inputlanguage.installedinputlanguages?view=windowsdesktop-8.0
InputLanguage.InstalledInputLanguages Property (System.Windows.Forms)
Gets a list of all installed input languages.
there is also this from user32 (accessible with dllimport):
https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getkeyboardlayout
GetKeyboardLayout function (winuser.h) - Win32 apps
Retrieves the active input locale identifier (formerly called the keyboard layout).