当前位置: 首页 > news >正文

如何在Windows下开发输入法:Mini How to

RIME (中州韻輸入法引擎)是一個跨平臺的輸入法框架。基於這一框架,開發者们在Windows、macOS、Linux、Android等平臺上創造了不同的輸入法前端實現。

Weasel (小狼毫)是它的Windows版,从0.9.30到0.17.4版支持Windows XP SP3, 7, 8/8.1, 10, 11.

我从github下载了最新版。里面有env.vs2022.bat,env.vs2019.bat, Visual Studio Version 17的.sln,Visual Studio 2015的.vcxproj.

AI说:开发IME (Input Method Editor),当前推荐使用TSF而非传统的IMM32实现‌。TSF(Text Services Framework)集成于Windows XP及后续操作系统中,为高级文本输入和自然语言处理提供可扩展的标准化接口‌。‌‌文本服务层‌作为COM组件实现,提供键盘输入、手写识别、语音识别等功能。

呵呵,SilverLight今何在?它是微软2007年推出的跨浏览器插件,主要用于网页端富媒体(视频、交互式应用等)的渲染和开发‌。

Weasel依然用.def文件而不是dllexport. 它是个导出下列符号的.dll:
ImeConversionList, ImeConfigure, ImeDestroy, ImeEscape, ImeInquire, ImeProcessKey, ImeSelect, ImeSetActiveContext, ImeToAsciiEx, NotifyIME, ImeRegisterWord, ImeUnregisterWord,
ImeGetRegisterWordStyle, ImeEnumRegisterWord, ImeSetCompositionString

一个.dll如何成为输入法?修改注册表。要改HKCU\Keyboard Layout\Preload和HKLM\SYSTEM\CurrentControlSet\Control\Keyboard Layouts等处。

$ find -name '*' | xargs grep RegCreate
./WeaselSetup/imesetup.cpp: ret = RegCreateKey(hKey, hkl_str, &hSubKey);
./WeaselSetup/InstallOptionsDlg.h: ret = RegCreateKeyEx(rootKey, subpath, 0, NULL, 0,

const WCHAR KEYBOARD_LAYOUTS_KEY[] =L"SYSTEM\\CurrentControlSet\\Control\\Keyboard Layouts";
const WCHAR PRELOAD_KEY[] = L"Keyboard Layout\\Preload";if (register_ime) {
HKL hKL = ImmInstallIME(ime_path.c_str(), get_weasel_ime_name().c_str());
if (!hKL) {// manually register imeWCHAR hkl_str[16] = {0};HKEY hKey;LSTATUS ret = RegOpenKey(HKEY_LOCAL_MACHINE, KEYBOARD_LAYOUTS_KEY, &hKey);if (ret == ERROR_SUCCESS) {for (DWORD k = 0xE0200000 + (hant ? 0x0404 : 0x0804); k <= 0xE0FF0804;k += 0x10000) {StringCchPrintfW(hkl_str, _countof(hkl_str), L"%08X", k);HKEY hSubKey;ret = RegOpenKey(hKey, hkl_str, &hSubKey);if (ret == ERROR_SUCCESS) {WCHAR imeFile[32] = {0};DWORD len = sizeof(imeFile);DWORD type = 0;ret = RegQueryValueEx(hSubKey, L"Ime File", NULL, &type,(LPBYTE)imeFile, &len);if (ret = ERROR_SUCCESS) {if (_wcsicmp(imeFile, L"weasel.ime") == 0) {hKL = (HKL)k;  // already there
          }}RegCloseKey(hSubKey);} else {// found a spare number to registerret = RegCreateKey(hKey, hkl_str, &hSubKey);if (ret == ERROR_SUCCESS) {const WCHAR ime_file[] = L"weasel.ime";RegSetValueEx(hSubKey, L"Ime File", 0, REG_SZ, (LPBYTE)ime_file,sizeof(ime_file));const WCHAR layout_file[] = L"kbdus.dll";RegSetValueEx(hSubKey, L"Layout File", 0, REG_SZ,(LPBYTE)layout_file, sizeof(layout_file));const std::wstring layout_text = get_weasel_ime_name();RegSetValueEx(hSubKey, L"Layout Text", 0, REG_SZ,(LPBYTE)layout_text.c_str(),layout_text.size() * sizeof(wchar_t));RegCloseKey(hSubKey);hKL = (HKL)k;}break;}}RegCloseKey(hKey);}if (hKL) {HKEY hPreloadKey;ret = RegOpenKey(HKEY_CURRENT_USER, PRELOAD_KEY, &hPreloadKey);if (ret == ERROR_SUCCESS) {for (size_t i = 1; true; ++i) {std::wstring number = std::to_wstring(i);DWORD type = 0;WCHAR value[32];DWORD len = sizeof(value);ret = RegQueryValueEx(hPreloadKey, number.c_str(), 0, &type,(LPBYTE)value, &len);if (ret != ERROR_SUCCESS) {RegSetValueEx(hPreloadKey, number.c_str(), 0, REG_SZ,(const BYTE*)hkl_str,(wcslen(hkl_str) + 1) * sizeof(WCHAR));break;}}RegCloseKey(hPreloadKey);}}
}
if (!hKL) {DWORD dwErr = GetLastError();WCHAR msg[100];CString str;str.LoadStringW(IDS_STR_ERRREGIME);StringCchPrintfW(msg, _countof(msg), str, hKL, dwErr);MSG_NOT_SILENT_ID_CAP(silent, msg, IDS_STR_INSTALL_FAILED,MB_ICONERROR | MB_OK);return 1;
}
return 0;
}
View Code

~/weasel-master/WeaselIME$ wc -l *.cpp *.h
26 dllmain.cpp
155 ime.cpp
267 KeyEvent.cpp
8 stdafx.cpp
566 WeaselIME.cpp
941 immdev.h
16 resource.h
21 stdafx.h
12 targetver.h
69 WeaselIME.h
2081 总计

/* immdev.h - Input Method Manager definitions for IME developers */
/* Copyright (c) Microsoft Corporation. All rights reserved. */

很早很早以前,immdev.h, immdev.lib在DDK (Device Driver Development Kit)里,还带区位等输入法的源码,后来好像挪到SDK里。

有头文件,有dll,但是没.lib. AI说:创建一个文本文件imm32.def,内容如下:
EXPORTS
ImmGetDefaultIMEWnd
ImmInstallIMEA
...
打开适用于您Visual Studio版本的Developer Command Prompt,然后执行命令:lib /def:imm32.def /out:imm32.lib /MACHINE:X64

微软网站说:You can use LIB with the /DEF option to create an import library and an export file. LINK uses the export file to build a program that contains exports (usually a dynamic-link library (DLL)), and it uses the import library to resolve references to those exports in other programs.

嗯,① DLL的导入导出库与静态库不同,后者包含全部代码,前者只是存根。② WeaselIME/weasel.def正是所需啊。

So, 你面对的就是1000行程序,而已。

那些函数的文档,微软网站有:

Input Method Manager (IMM) is a technology used by an application to communicate with an input method editor (IME), which runs as a service. The IME allows computer users to enter complex characters and symbols, such as Japanese kanji characters, by using a standard keyboard.

This section describes the IMM API and explains how to use the functionality to create and manage IME windows. It includes the following sections:

About Input Method Manager
Using Input Method Manager
Input Method Manager Reference


我看过本书,好像叫高级C/C++编译技术 Advanced C and C++ Compiling,写得很好(我没说看懂了)。

Linux下不用导入库,.a是为-static准备的;直接链接到.so

This package, x11proto-dev ,  provides development headers describing the wire protocol for the X11 core and extension protocols, and also provides a number of utility headers, used to abstract OS-specific functions.

http://www.jsqmd.com/news/24669/

相关文章:

  • 2025 年 10 月盐城公司变更,盐城地址挂靠,盐城商标注册公司最新推荐,聚焦资质、案例、售后的五家公司深度解读
  • 第一天学习
  • AI元人文:星火与土壤
  • 5-4-其他查询 - 实践
  • K3s + Sysbox:让容器拥有“虚拟机的灵魂”
  • 题解:AT_abc200_e [ABC200E] Patisserie ABC 2
  • CF1996G Penacony
  • 远程命令执行漏洞、SSRF、XXE、tomcat弱口令漏洞
  • Ollama API 交互
  • 项目冷场?用禅道协作白板激活团队的创新思维!
  • xxx.ped 在生物信息学中是什么?
  • Ollama 基本概念
  • 2025年桥洞力学板市场趋势与选购指南:江苏同芯木业江苏行业领先
  • 2025年桥洞力学板行业发展趋势与前五厂家推荐
  • 2025年10月桥洞力学板品牌综合评测与行业趋势分析
  • 2.HD302-070 socket can调试笔记1
  • 如何使用FlareSolverr来抓取Cloudflare网站 - 狼人:
  • 吴恩达深度学习课程二: 改善深层神经网络 第一周:深度学习的实践(一)
  • 云端微信 - 随时随地在浏览器访问
  • Ollama 运行模型
  • 【往届EI、Scopus已检索|ACM独立出版】第二届经济数据分析与人工智能国际学术会议 (EDAI 2025)
  • win11后台程序cpu高占用问题
  • 线段树的各种姿势
  • 2025 年矿井轴流通风机,矿井抽出式轴流对旋通风机,矿井压入式对旋轴流通风机,FKD 系列矿井压入式对旋轴流通风机厂家最新推荐,实力品牌深度解析采购无忧之选
  • 2025 年矿用隔爆型压入式轴流通风机,FKZ 系列矿井轴流通风机,FKCDZ 系列矿井抽出式轴流对旋通风机厂家最新推荐,聚焦资质、案例、售后的五家机构深度解读
  • 2025 年矿井压入式轴流通风机,矿用隔爆型压入式对旋轴流通风机,煤矿地面用抽出式轴流对旋通风机厂家最新推荐,精准检测与稳定性能深度解析
  • 第一次编程作业完结撒花!!!
  • LangGraph MCP - 使用LangGraph实现多智能体架构(七)
  • DP 复习 - L
  • 完整教程:swin-transformer架构解析和源码解析