0

I need to print my language character from virtual key codes. How to implement?

SetConsoleCP(1251); 
SetConsoleOutputCP(1251);

setlocale(LC_ALL, "Russian");

int a = 0x44;
TCHAR aa = (TCHAR)a;

cout << char(aa) << endl;

i tryed. But in console printed english character 'D' a i need russian character. Only from Virtual-Key Codes (https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes)

Andreas Wenzel
  • 22,760
  • 4
  • 24
  • 39
  • Locale has nothing to do with it. The mapping between virtual keys and characters is determined by the keyboard layout. You are probably looking for [`MapVirtualKey`](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-mapvirtualkeyw) (uses the keyboard layout active on the calling thread) or [`MapVirtualKeyEx`](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-mapvirtualkeyexw) (takes keyboard layout as a parameter). – Igor Tandetnik Jun 28 '20 at 17:36
  • Игорь, дружище. как это реализовать? Igor, my friend, how to implment thar? – Allium Unus Jun 28 '20 at 17:44
  • [Take a look here](https://stackoverflow.com/a/59041425/3439404). `[Win32Functions.KeyboardScan]::VKCodeToUnicodeHKL(0x44, 0xf0330419)` could help if you use real HKL instead my `0xf0330419` ([Russian Mnemonic](https://learn.microsoft.com/en-gb/globalization/keyboards/kbdrum.html)). – JosefZ Jun 29 '20 at 11:01

0 Answers0