The korean layout has alphabet mode and hangul mode.
I only need hangul mode in the korean layout. To suppress alphabet mode I wrote this code but I could not find the way to get current IME mode. Which Windows API can I use to implement checkKoreanInputMode() function?
#include <Windows.h>
#include <iostream>
#include <thread>
bool checkKoreanInputMode() {
// check current IME layout and mode
}
void setKoreanInputMode() {
keybd_event(VK_HANGUL, 0, 0, 0);
keybd_event(VK_HANGUL, 0, KEYEVENTF_KEYUP, 0);
}
int main() {
while (true) {
if (!checkKoreanInputMode()) {
std::cout << "Switching to Korean input mode." << std::endl;
setKoreanInputMode();
}
std::this_thread::sleep_for(std::chrono::seconds(1));
}
return 0;
}
I tried to use ImmGetConversionStatus(), but ImmGetContext() returns always NULL even if I changed IME.
bool checkKoreanInputMode() {
// Get the current IME context
HIMC hIMC = ImmGetContext(GetForegroundWindow());
if (hIMC == NULL){
return false;
}
// Get the current IME mode
DWORD dwConversion = 0, dwSentence = 0;
bool isKoreanInputMode = false;
if (ImmGetConversionStatus(hIMC, &dwConversion, &dwSentence)) {
// Check if the current mode is Korean IME with English input mode
isKoreanInputMode = (dwConversion & IME_CMODE_NATIVE) && !(dwConversion & IME_CMODE_ALPHANUMERIC);
}
// Release the IME context
ImmReleaseContext(GetForegroundWindow(), hIMC);
return isKoreanInputMode;
}
What am I doing wrong?



WM_IME_NOTIFYandImmGetConversionStatus.WM_IME_NOTIFY. Can you show me how to use it?ImmGetDefaultIMEWndandWM_IME_CONTROL.