MCPcopy Create free account
hub / github.com/OGSR/OGSR-Engine / DikToChar

Method DikToChar

ogsr_engine/xr_3da/Xr_input.cpp:472–538  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

470}
471
472u16 CInput::DikToChar(const int dik, const bool utf) const
473{
474 switch (dik)
475 {
476 // Эти клавиши через ToAscii не обработать, поэтому пропишем явно
477 case DIK_NUMPAD0: return '0';
478 case DIK_NUMPAD1: return '1';
479 case DIK_NUMPAD2: return '2';
480 case DIK_NUMPAD3: return '3';
481 case DIK_NUMPAD4: return '4';
482 case DIK_NUMPAD5: return '5';
483 case DIK_NUMPAD6: return '6';
484 case DIK_NUMPAD7: return '7';
485 case DIK_NUMPAD8: return '8';
486 case DIK_NUMPAD9: return '9';
487 case DIK_NUMPADSLASH: return '/';
488 case DIK_NUMPADPERIOD: return '.';
489 //
490 default:
491 u8 State[256]{};
492 if (this->is_exclusive_mode)
493 { // GetKeyboardState в данном случае не используем, потому что оно очень глючно работает в эксклюзивном режиме
494 if (this->iGetAsyncKeyState(DIK_LSHIFT) || this->iGetAsyncKeyState(DIK_RSHIFT))
495 State[VK_SHIFT] = 0x80; //Для получения правильных символов при зажатом shift
496 }
497 else
498 {
499 if (!GetKeyboardState(State))
500 return 0;
501 }
502
503 u16 output{};
504 if (utf)
505 {
506 WCHAR symbol{};
507 if (this->is_exclusive_mode)
508 {
509 auto layout = GetKeyboardLayout(GetWindowThreadProcessId(gGameWindow, nullptr));
510 if (ToUnicodeEx(MapVirtualKeyEx(dik, MAPVK_VSC_TO_VK, layout), dik, State, &symbol, 1, 0, layout) != 1)
511 return 0;
512 }
513 else
514 {
515 if (ToUnicode(MapVirtualKey(dik, MAPVK_VSC_TO_VK), dik, State, &symbol, 1, 0) != 1)
516 return 0;
517 }
518 WideCharToMultiByte(CP_UTF8, 0, &symbol, 1, reinterpret_cast<char*>(&output), sizeof output, nullptr, nullptr);
519 return output;
520 }
521 else
522 {
523 if (this->is_exclusive_mode)
524 {
525 auto layout = GetKeyboardLayout(GetWindowThreadProcessId(gGameWindow, nullptr));
526 if (ToAsciiEx(MapVirtualKeyEx(dik, MAPVK_VSC_TO_VK, layout), dik, State, &output, 0, layout) == 1)
527 return output;
528 }
529 else

Callers 2

KeyPressedMethod · 0.80
on_key_pressMethod · 0.80

Calls 1

iGetAsyncKeyStateMethod · 0.95

Tested by

no test coverage detected