中文输入法的热键(100分)

  • 主题发起人 主题发起人 delphi1
  • 开始时间 开始时间
D

delphi1

Unregistered / Unconfirmed
GUEST, unregistred user!
如何得到系统安装的每个中文输入法所设置的激活热键?<br>或者得到所有输入法中设置的热键?
 
我觉得应该在注册表中,或者某个ini文件中能找到.
 
在windows/inf/ime.inf中.
 
哈,这个问题找我。<br>要知道WINDOWS的大部分秘密均在注册表中,一开注册表,万事大吉。<br>请查看/HKEY_CURRENT_USER/Control Panel/Input Method/Hot Keys<br>路径下,你会发现诸如:00000011、00000012等子键,每一子键代<br>表一种输入的热键,该子键有如下键值:<br>&nbsp; &nbsp; Key Modifiers &nbsp; : &nbsp;用于指定功能转换键,如Alt、Shift或左Alt等<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : &nbsp;如alt,可能为 01 c0 00 00<br>&nbsp; &nbsp; Target IME &nbsp; &nbsp;: &nbsp;用于指定具体的输入法,如 &nbsp;04 08 24 0e<br>&nbsp; &nbsp; Virtual Key &nbsp;: &nbsp;用于指定字母键名,如3,则为 &nbsp;33 00 00 00<br>&nbsp; &nbsp; 上面例子中指定了输入法04 08 24 0e的热键为alt+3。<br>&nbsp; &nbsp; 而对于Taget IME的值,你可将其16进制值直接翻译成字符串,如<br>上例中的04 08 24 0e,变成e0240804,然后,你可据此进入另一个路径:<br>/HKEY_LOCAL_MACHINE/System/CurrentControlSet/Control/Keyboard layouts<br>在此路径下你会找到一个子键e0240804,找到并打开它,你可看到如下的<br>键值:<br>&nbsp; &nbsp; IME file<br>&nbsp; &nbsp; layout file<br>&nbsp; &nbsp; layout text &nbsp;: &nbsp;该输入法的显示名称,如“王码五笔型”<br>&nbsp; &nbsp; 至此一切都明白了吗,你设置“王码五笔型”的热键为ALT+3。<br>&nbsp; &nbsp; 这里你唯一难清楚的是Key Modifiers的值的获取方法,我也没时间<br>试,最多你在系统中设置不同的方式以检测其不同的取值,不会很多,组合<br>键有:Ctrl、Alt、Shift及左键、右键五个。<br>&nbsp; &nbsp; 祝你好运!我的答案你可满意?
 
啊!中午起了一个头,现在已经答得这么全了,白忙乎了半天<br>嘻嘻,还留了一点.^_^<br>关于Key Modifiers的值, 本人稍作分析,发现它作为一个32为二进制串,意义如下:<br>00000 &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp; 000000 0000000000000000<br>&nbsp; &nbsp; &nbsp; &nbsp;^ &nbsp; &nbsp; &nbsp; &nbsp;^ &nbsp; &nbsp; &nbsp; ^ &nbsp; &nbsp; &nbsp; ^ &nbsp; &nbsp; &nbsp;^<br>&nbsp; &nbsp; &nbsp; shift &nbsp; ctrl &nbsp; &nbsp; alt &nbsp; &nbsp; 左 &nbsp; &nbsp; 右<br>1:有,0:无. <br>祝你好运!我的有头有尾你可满意?
 
通过API可以知道已安装的所有输入法名称和Handle,真的没有API能够得到输入法的热键吗?<br><br>yanghaijun的办法可行,只是本人比较懒,希望越简单越好。
 
我只看见过这个函数,它好像是windows的系统级API,说明里头写的是仅供Control Panel<br>用,不知道我们能不能用起来?API的帮助里头都找不到.我是从MSDN里头找到的.<br>Delphi的Source里头也没有定义(这倒不成其为原因).用用试试看......<br><br><br>BOOL WINAPI ImmGetHotKey(DWORD dwHotKeyID, LPUINT lpuModifiers, <br>&nbsp; &nbsp; LPUINT lpuVKey, LPHKL lphKL)<br>Gets the value of the IME hot key. This function is called by control panel. <br>Returns TRUE if successful, FALSE otherwise. <br><br>dwHotKeyID <br>Hot key identifier. <br><br>lpuModifiers <br>Value that specifies the keys that must be <br>combined with lpuVKey to trigger the hot key. <br>Can be a combination of these values: <br><br>Value <br>Meaning <br>MOD_ALT &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ALT key <br>MOD_CONTROL &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CTRL key <br>MOD_SHIFT &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SHIFT key <br>MOD_LEFT &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Use key on left side of keyboard <br>MOD_RIGHT &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Use key on right side of keyboard <br>MOD_ON_KEYUP &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Trigger hot key when hot key is released <br>MOD_IGNORE_ALL_MODIFIER &nbsp; &nbsp; &nbsp; Ignore modifier keys <br><br>lpuVKey <br>Virtual key code of this hot key. <br><br>lphKL <br>Handle of the keyboard layout for the IME. If return value of this parameter is of NULL, <br>this hot key can switch to the IME with this keyboard layout.
 
yanhaijun:很遗憾我不能给你高分,虽然我们可能还是本家<br>茶叶蛋很好吃,茶叶蛋大概经常吃。<br><br>下面是我使用的部分代码,增加Windows95没有的设置默认输入法,是商业软件中的哦:<br>uses<br>&nbsp; Menus, Imm, ShellApi, About;<br><br>function ImmGetHotKey(dwHotKeyID: DWord; var uModifiers: UINT;<br>&nbsp; var uVKey: UINT; var hKL: HKL): Boolean; stdcall; external 'Imm32.dll' Name 'ImmGetHotKey';<br><br>function HotKeyToStr(uModifiers, uVKey: UINT): string;<br>var<br>&nbsp; Shift: TShiftState;<br>begin<br>&nbsp; Shift := [];<br>&nbsp; if uModifiers and MOD_ALT &lt;&gt; 0 then Shift := Shift + [ssAlt];<br>&nbsp; if uModifiers and MOD_CONTROL &lt;&gt; 0 then Shift := Shift + [ssCtrl];<br>&nbsp; if uModifiers and MOD_SHIFT &lt;&gt; 0 then Shift := Shift + [ssShift];<br>&nbsp; if uModifiers and MOD_LEFT &lt;&gt; 0 then Shift := Shift + [ssLeft];<br>&nbsp; if uModifiers and MOD_RIGHT &lt;&gt; 0 then Shift := Shift + [ssRight];<br>&nbsp; Result := ShortCutToText(ShortCut(uVKey, Shift));<br>end;<br><br>procedure TSetImeForm.FormCreate(Sender: TObject);<br>const<br>&nbsp; nHKL_LIST = 20;<br>var<br>&nbsp; iImeCount, i, j, iImageIndex: Integer;<br>&nbsp; hImeList: array[1..nHKL_LIST] of HKL;<br>&nbsp; szImeFileName: array[0..MAX_PATH] of Char;<br>&nbsp; szImeName: array[0..254] of Char;<br>&nbsp; hLargeIcon, hSmallIcon: HICON;<br>&nbsp; Icon: TIcon;<br>&nbsp; uModifiers, uVKey: UINT;<br>&nbsp; hIme: HKL;<br>&nbsp; sHotKeys: string;<br>begin<br>&nbsp; ListView.Items.Clear;<br>&nbsp; iImeCount := GetKeyboardLayoutList(nHKL_LIST, hImeList);<br>&nbsp; for i := 1 to iImeCount do<br>&nbsp; &nbsp; if ImmEscape(hImeList, 0, IME_ESC_IME_NAME, @szImeName) &gt; 0 then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; iImageIndex := -1;<br>&nbsp; &nbsp; &nbsp; ImmGetIMEFileName(hImeList, szImeFileName, MAX_PATH);<br>&nbsp; &nbsp; &nbsp; if ExtractIconEx(szImeFileName, 0, hLargeIcon, hSmallIcon, 1) &lt;&gt; 0 then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; Icon := TIcon.Create;<br>&nbsp; &nbsp; &nbsp; &nbsp; Icon.Handle := hSmallIcon;<br>&nbsp; &nbsp; &nbsp; &nbsp; iImageIndex := ImageList.AddIcon(Icon);<br>&nbsp; &nbsp; &nbsp; &nbsp; Icon.Free;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; with ListView.Items.Add do<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; Caption := szImeName;<br>&nbsp; &nbsp; &nbsp; &nbsp; ImageIndex := iImageIndex;<br>&nbsp; &nbsp; &nbsp; &nbsp; if Caption = SysIni.ReadString(seUser, idDefaultIme, '五笔型码') then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Selected := True;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end;<br>&nbsp; for i := IME_HOTKEY_DSWITCH_FIRST to IME_HOTKEY_DSWITCH_LAST do<br>&nbsp; &nbsp; if ImmGetHotKey(i, uModifiers, uVKey, hIme) then<br>&nbsp; &nbsp; &nbsp; for j := 1 to iImeCount do<br>&nbsp; &nbsp; &nbsp; &nbsp; if hIme = hImeList[j] then &nbsp;//First Ime is En, and has not name<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ListView.Items[j - 2].SubItems.Add(HotKeyToStr(uModifiers, uVKey));<br>&nbsp; sHotKeys := '';<br>&nbsp; if ImmGetHotKey(IME_CHOTKEY_IME_NONIME_TOGGLE, uModifiers, uVKey, hIme) then<br>&nbsp; &nbsp; sHotKeys := sHotKeys + '打开关闭输入法' + ' &nbsp;' + HotKeyToStr(uModifiers, uVKey) + #13;<br>&nbsp; if ImmGetHotKey(IME_CHOTKEY_SYMBOL_TOGGLE, uModifiers, uVKey, hIme) then<br>&nbsp; &nbsp; sHotKeys := sHotKeys + '切换中英文符号' + ' &nbsp;' + HotKeyToStr(uModifiers, uVKey) + #13;<br>&nbsp; if ImmGetHotKey(IME_CHOTKEY_SHAPE_TOGGLE, uModifiers, uVKey, hIme) then<br>&nbsp; &nbsp; sHotKeys := sHotKeys + '切换全角和半角' + ' &nbsp;' + HotKeyToStr(uModifiers, uVKey) + #13;<br>&nbsp; HotKeyList.Caption := sHotKeys;<br>end;<br><br>
 
后退
顶部