C++中文输入法支持

发布于:2024-12-06 ⋅ 阅读:(28) ⋅ 点赞:(0)
glfw win
#include "ImeInput.h"
ImeInput imeInput;
HWND     hWnd = (HWND)getWnd(this);
imeInput.CreateImeWindow(hWnd);
imeInput.EnableIME(hWnd);
imeInput.SetInputLanguage();
ImeComposition compos;
std::wstring   textInput;

while (!glfwWindowShouldClose(m_window)) {
	if (imeInput.GetResult(hWnd, GCS_RESULTSTR, &compos) && textInput != compos.ime_string) {
		imeInput.GetComposition(hWnd, GCS_RESULTSTR, &compos);  // 中文输入,防止重复输入
		imeInput.CleanupComposition(hWnd);
		textInput = compos.ime_string;
		std::wcout << "output:" << textInput << std::endl;
	}
	glfwWaitEvents();
	glfwSwapBuffers(m_window);
}
imeInput.CancelIME(hWnd);
imeInput.DestroyImeWindow(hWnd);
glfwDestroyWindow(m_window);
glfwTerminate();
SDL 
SDL_Init(SDL_INIT_VIDEO);
SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1"); // 支持输入法

void onEvent(const SDL_Event& event) {
    switch (event.type) {
    case SDL_QUIT:
    case SDL_WINDOWEVENT:
    case SDL_KEYDOWN:
    case SDL_KEYUP:
        break;
    case SDL_TEXTEDITING:
        break;
    case SDL_TEXTINPUT:
		std::cout << "output: " << event.text << "\n";
    case SDL_MOUSEMOTION:
    case SDL_MOUSEBUTTONDOWN:
    case SDL_MOUSEBUTTONUP:
    case SDL_MOUSEWHEEL:
	        break;
    case SDL_DROPFILE:
        // event.drop.file  拖拽
    default:
    }
}
参考 

LuaUI2/LuaUI2/ImeInput.h at daba4835c848261943fd9ce6d2df0bac0140bd95 · ifzz/LuaUI2 · GitHub


创作不易,小小的支持一下吧!


网站公告

今日签到

点亮在社区的每一天
去签到