AHK Toggle/Get Current Input method

Source: Internet
Author: User
Tags integer

Using the AHK code to switch the input method, and get the current input method, this is just an example, you can play it into a more useful program, such as the specified window using the specified input method, you can set a separate shortcut key for each input method, and so on. However, there is a BUG, when the input method switch to Microsoft IME, and then get the current input method state, error. Do not know is not my input method of the problem.

The input method information that is installed in the system is in the registry hkey_users/. Default/keyboard Layout/preload. Inside only the keyboard layout name of the input method, such as E0040840 left E004 description of the Input Method identification (Smart ABC) right 0804 indicates that the input method is Chinese input. The specific name of its input method is available to the keyboard layout name of the registry Hkey_local_machine/system/currentcontrolset/control/keyboard layouts/IME. The Layout text key value is the name of the input method.


Note: The installed IME may be displayed less than the Input method list of the taskbar, and you can go to Hkey_local_machine/system/currentcontrolset/control/keyboard layouts/ Find all the input methods that have been registered in the system. Call the specified input method: first need to obtain the keyboard layout of the input method, and then call the API function Loadkeyboardlayout to activate the specified input method, the function returns the keyboard layout handle of the specified input method, and finally send the message to the current active window to switch input method, Dllcall (" SendMessage ", uint, handle of the active window, uint, up, uint, 1, uint, Input method keyboard layout handle). This completes the invocation of the specified input method. Switch Input Method: Similar to the call, call the API function Activatekeyboardlayout complete. Of course, you will also need to send a toggle input message. function Activatekeyboardlayout (HKL hkl,uint Flags), where the value of the parameter HKL is 1 to toggle the next input method, and 0 for the previous input method. Get the current input method: Directly call API function Getkeyboardlayout, this function directly returns the name of the current keyboard layout, such as the need for the exact input method name, to the registry to find.

Description of the relevant API function:
Getkeyboardlayout:http://baike.baidu.com/view/1080067.html?wtp=tt
Activatekeyboardlayout:http://baike.baidu.com/view/1080058.htm
Loadkeyboardlayout:http://baike.baidu.com/view/1080078.htm
In addition to these, Microsoft also provides the input method more detailed operation API, such as switch or get half/full width, toggle case, Show/Hide IME status bar and so on.
Interested to view msdn:http://msdn.microsoft.com/en-us/library/aa914560.aspx

The code is as follows:

Gui, Add, GroupBox, X6 y4 w230 H10, Installed Input method (double-click Toggle)
Gui, Add, ListView, R20 X6 y24 w230 h120 vlistime gsetime, serial number | keyboard Layout | name
Gui, Add, Button, X6 y144 w80 h30 gpreime, Previous input method
Gui, Add, Button, x156 y144 w80 h30 gnextime, Next Input method
Gui, ADD, Button, x86 y144 w70 h30 gstateime, current status
; Generated using Smartgui Creator 4.0
Gui, Show, x397 y213 h190 w247, IME Toggle
Gosub,readime
Return
Guiclose:
Exitapp
Readime:
Lv_modifycol (3,300)
Loop,hkey_users,. Default/keyboard layout/preload, 1, 1
{
Regread,layout
Regread,imename,hkey_local_machine,system/currentcontrolset/control/keyboard Layouts/%Layout%,Layout Text
Regread,layout
Listcontent=%a_loopregname% 丨%imename% 丨%layout%
Lv_insert (1, "Vis", A_loopregname,layout,imename)
}
Return
Stateime:
Result:=dllcall ("Getkeyboardlayout", "int", 0,uint)
SetFormat, Integer, Hex
Result + = 0
SetFormat, Integer, D
MsgBox Current keyboard layout is%result%
Return

Setime:
If (a_guievent<> "DoubleClick")
{
Return
}
Gui,submit,nohide
Lv_gettext (layout,a_eventinfo,2)
; ~ MsgBox%layout%

Switchime (Layout)
Return

Switchime (Dwlayout)
{
Dllcall ("SendMessage", uint, winactive ("A"), uint,, uint, 1, uint, Dllcall ("Loadkeyboardlayout", Str, Dwlayout, uint, 1 ))
}

NextIME:
Dllcall ("SendMessage", uint, winactive ("A"), uint,, uint, 1, uint, Dllcall ("Activatekeyboardlayout", uint, 1, UINT, 256 ))
;--Activates the next input method for the current window
Return
Preime:
Dllcall ("SendMessage", uint, winactive ("A"), uint,, uint, 1, uint, Dllcall ("Activatekeyboardlayout", uint, 0, uint, 256 ))
;--Activates the previous input method for the current window
Return

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.