Quantcast
Channel: Active questions tagged utf-8 - Stack Overflow
Viewing all articles
Browse latest Browse all 1204

Keyboard input to UTF-32 problem. i want it to be U+1D41A but instead it outputs U+D41A

$
0
0

im trying to make a keyboard injection converter thing, that takes an input and outputs it into a certain unicode. This is my first time jumping into unicodes so i don't really know anything about this.

And the problem im having is that i want it to output

U+1D41A 

but instead it outputs

U+D41A

i also tried using a lookup table but it still does the same thing.

Here is my code.

#include <windows.h>#include <iostream>#include <cstdint>HHOOK hHook;char32_t to_math_bold(wchar_t c){    if (c >= L'A'&& c <= L'Z') {        return static_cast<char32_t>(c + 0x1D4D0 - L'A');    }     else if (c >= L'a'&& c <= L'z') {        return static_cast<char32_t>(c + 0x1D41A - L'a');    }     else if (c >= L'0'&& c <= L'9') {        return static_cast<char32_t>(c + 0x1D7E0 - L'0');    }    return static_cast<char32_t>(c);}LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam){    if (nCode == HC_ACTION && (wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN))    {        KBDLLHOOKSTRUCT *p = (KBDLLHOOKSTRUCT *)lParam;        DWORD vkCode = p->vkCode;        WCHAR buffer[4] = {0}; // Increased size for possible multi-byte characters        BYTE keyState[256];        GetKeyboardState(keyState);        int result = ToUnicode(vkCode, p->scanCode, keyState, buffer, sizeof(buffer) / sizeof(WCHAR), 0);        if (result > 0)        {            wchar_t typedChar = buffer[0];            std::wcout << L"Typed: " << typedChar << L" (U+" << std::hex << static_cast<unsigned int>(typedChar) << L")\n";            char32_t boldChar = to_math_bold(typedChar);            if (boldChar != typedChar)            {                std::wcout << L"Converted to Math Bold: " << static_cast<wchar_t>(boldChar) << L" (U+" << std::hex << boldChar << L")\n";                INPUT input;                input.type = INPUT_KEYBOARD;                input.ki.wVk = 0;                     // No virtual key code needed for Unicode                input.ki.wScan = boldChar;            // Math bold character                input.ki.dwFlags = KEYEVENTF_UNICODE; // Send Unicode character                input.ki.time = 0;                input.ki.dwExtraInfo = 0;                SendInput(1, &input, sizeof(INPUT));                return 1;            }        }        else        {            std::wcout << L"ToUnicode failed with error code: " << GetLastError() << L"\n";        }    }    return CallNextHookEx(hHook, nCode, wParam, lParam);}void SetHook(){    hHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardProc, NULL, 0);}void Unhook(){    UnhookWindowsHookEx(hHook);}int main(){    SetHook();    MSG msg;    while (GetMessage(&msg, NULL, 0, 0))    {        TranslateMessage(&msg);        DispatchMessage(&msg);    }    Unhook();    return 0;}

Viewing all articles
Browse latest Browse all 1204

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>