Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Passer By

Pages: [1]
1
Window / KeyEvent with IME
« on: October 19, 2017, 04:52:02 pm »
If you tried to read sf::Event::KeyEvent::code for sf::Event::EventType::KeyPressed on Windows with IME (input method editor), you get sf::Keyboard::Key::Unknown.

As far as I know, this is useless information, and if its possible, I'd think it should instead be the physical key on the keyboard that is being pressed. That said, I have no idea how all the OS handles IME, so maybe its impossible?

At least reading messages directly works on Windows
#include<Windows.h>
#include<iostream>

LRESULT CALLBACK echoer(int nCode, WPARAM wParam, LPARAM lParam)
{
    switch (wParam)
    {
    case WM_KEYDOWN:
        [[fallthrough]];
    case WM_SYSKEYDOWN:
        unsigned char c = ((PKBDLLHOOKSTRUCT)lParam)->vkCode;
        std::cerr << c << '\n';  // correctly reads even with IME
        break;
    }
    return CallNextHookEx(nullptr, nCode, wParam, lParam);
}

int main()
{
    auto hook = SetWindowsHookEx(WH_KEYBOARD_LL, echoer, nullptr, 0);

    MSG msg;
    while (!GetMessage(&msg, nullptr, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    UnhookWindowsHookEx(hook);
}
 

Pages: [1]
anything