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);
}
Some when you use IME, your physical keys on your keyboard that SFML has an entry in the sf::Keyboard::Key enum don't work anymore?
Oe is it random virtual key presses that SFML can't possibly map out, that you want to trigger?
The physical keys stop working, not the virtual keys.
A concrete example:
sf::Window window;
// ...
for(sf::Event event; window.PollEvent(event); )
{
if(event.type == sf::Event::KeyPressed)
std::cerr << event.key.code; // prints -1 for Unkown with IME, works without IME
if(event.type == sf::Event::KeyReleased)
std::cerr << event.key.code; // always works, prints physical key released
}
I'm asking if sf::Event::KeyPressed can possibly play nice with IME