当前位置: 首页 > 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.gsyq.cn/news/32883.html

相关文章:

  • 2025 年 10 月盐城公司变更,盐城地址挂靠,盐城商标注册公司最新推荐,聚焦资质、案例、售后的五家公司深度解读
  • 第一天学习
  • K3s + Sysbox:让容器拥有“虚拟机的灵魂”
  • 题解:AT_abc200_e [ABC200E] Patisserie ABC 2
  • CF1996G Penacony
  • 远程命令执行漏洞、SSRF、XXE、tomcat弱口令漏洞
  • Ollama API 交互
  • 项目冷场?用禅道协作白板激活团队的创新思维!
  • 2025年桥洞力学板市场趋势与选购指南:江苏同芯木业江苏行业领先
  • 吴恩达深度学习课程二: 改善深层神经网络 第一周:深度学习的实践(一)
  • Ollama 运行模型
  • 2025 年矿井轴流通风机,矿井抽出式轴流对旋通风机,矿井压入式对旋轴流通风机,FKD 系列矿井压入式对旋轴流通风机厂家最新推荐,实力品牌深度解析采购无忧之选
  • 2025 年矿用隔爆型压入式轴流通风机,FKZ 系列矿井轴流通风机,FKCDZ 系列矿井抽出式轴流对旋通风机厂家最新推荐,聚焦资质、案例、售后的五家机构深度解读
  • 第一次编程作业完结撒花!!!
  • 2025年沈阳/北京/东三省制造业企业商业秘密保护权威推荐榜单:高新技术企业与上市公司数据安全解决方案精选
  • 2025沈阳/北京/东三省制造业企业商业秘密保护厂家推荐大宸商业,专业合规护航企业发展
  • LangGraph MCP - 使用LangGraph构建多智能体工作流(六)
  • 告别卡顿与等待,Rancher Vai 让集群操作“秒响应”
  • 2025 年铝型材框架、铝型材围栏、6063 铝型材、重型铝型材厂家最新推荐 —— 产能、专利、环保三维数据透视
  • 2025 年碳化硅金刚线切割机,石墨金刚线切割机,陶瓷金刚线切割机厂家最新推荐,产能、专利、适配性三维数据透视
  • 2025 年 10 月油石、保温材料、玉石、石英金刚线切割机厂家最新推荐,产能、专利、环保三维数据透视
  • 2025 年 10 月瓦楞纸、蜂窝铝、硬质合金金刚线切割机厂家最新推荐,实力品牌深度解析采购无忧之选!
  • 共产主义没能解决”霸凌“的状况
  • 测试计划与方案怎么写?这份让开发和PM都信服的模板请收好!
  • 5 MHz 到 10 GHz 一只搞定:H3-MABA-011118 国产替代实测笔记
  • Perplexity AI研究助手10个提示词
  • Linux 下使用 tar 与 pigz 进行多核压缩
  • 2025年pvc线槽厂家权威推荐榜单:线槽盖板/不锈钢线槽/塑料线槽板源头厂家精选
  • 2025年无锡排水管道非开挖修复公司权威推荐榜单:污水管道维修改造/商场污水管道修复/排水管道修复源头公司精选
  • Jenkins 集成jmeter、rf