ActivateKeyboardLayout是一個為激活鍵盤布局提供服務的計算機函式。
基本介紹
- 中文名:ActivateKeyboardLayout
- 函式功能:激活鍵盤布局
- 函式原型:HKL ActivateKeyboardLayout
- hkl:將被激活的鍵盤布局的句柄
函式功能,函式原型,參數,返回值,Parameters,Return Value,Remarks,
函式功能
激活鍵盤布局。該函式Windows NT和Windows 95中的實現有很大不同。本參考頁中首先給出了完整的Windows NT的實現,下來又給出了Windows 95版本的實現,以便大家更好地了解二者的區別。在Windows NT中ActivateKeyboadLayout函式激活一種不同的鍵盤布局,同時在整個系統中而不僅僅是調用該函式的進程中將該鍵盤布局設為活動的。
函式原型
HKL ActivateKeyboardLayout( HKL hkl,UINT Flags);
參數
hkl:將被激活的鍵盤布局的句柄。在Windows NT/2000/XP下,該布局必須先調用LoadKeyboadLayout函式裝入,該參數必須是鍵盤布局的句柄,或是如下的值中的一種:
HKL_NEXT(&H1):在系統保持的,己裝入的布局的循環鍊表中,選擇下一布局。
HKL_PREV(&H0):在系統保持的,已裝入的布局的循環鍊表中,選擇前一布局。
Flags:定義鍵盤布局如何被激活。該參數可取如下的一些值:
KLF_REORDER(&H8):若該位被設定,則已裝入的鍵盤布局的循環鏈路表將被重新排序。若該位沒有設定,則循環鏈路表的順序不變。例如,若用戶激活了英語鍵盤布局,同時依序裝入了法語、德語、西班牙語鍵盤布局,然後通過設定KLF_REORDER位激活德語鍵盤布局,則會產生如下順序:德語、英語、法語、西牙語鍵盤布局。若激活德語鍵盤布局時未設定KLF_REORDER(&H8)位,則產生如下的鍵盤布局的鍵盤布局序列:德語、西班牙語、英語、法語。若裝入的鍵盤布局少於三種,則該標誌域的值不起作用。
KLF_SETFORPROCESS(&H100):在Windows NT 5.0以上版本中使用。該參數用於整個進程中激活指定的鍵盤布,並向當前進程的所有執行緒傳送WM_INPUTLANGCHANGE訊息。
KLF_UNLOADPREVLOUS(&H4):卸載先前活動的鍵盤布局。此處無法使用此參數,可用UnloadKeyboardLayout 函式替代。
返回值
備註:在任一時刻可以裝入多種鍵盤布局,但一次僅能激活一種布局。裝入多種鍵盤布局使得可以快速地在多種布局之間切換。Windows 95 ACtivateKeyboadLayout函式為當前執行緒設定輸入語言。該函式接受一個鍵盤布局句柄,該句柄標識鍵盤的一個局部的和物理布局。
速查:Windows NT:3.1及以上版本;Windows:95及以上版本;Windows CE:不支持;頭檔案:winuser.h;庫檔案:user32.lib。
[English Version By MSDN]
Parameters
hkl [in] HKLInput locale identifier to be activated.
The input locale identifier must have been loaded by a previous call to the LoadKeyboardLayout function. This parameter must be either the handle to a keyboard layout or one of the following values.
HKL_NEXT(&H1)
Selects the next locale identifier in the circular list of loaded locale identifiers maintained by the system.
HKL_PREV(&H0)
Selects the previous locale identifier in the circular list of loaded locale identifiers maintained by the system.
Flags [in] UINTSpecifies how the input locale identifier is to be activated. This parameter can be one of the following values.
KLF_REORDER(0x00000008)
If this bit is set, the system's circular list of loaded locale identifiers is reordered by moving the locale identifier to the head of the list. If this bit is not set, the list is rotated without a change of order.
For example, if a user had an English locale identifier active, as well as having French, German, and Spanish locale identifiers loaded (in that order), then activating the German locale identifier with the KLF_REORDER bit set would produce the following order: German, English, French, Spanish. Activating the German locale identifier without the KLF_REORDER bit set would produce the following order: German, Spanish, English, French.
If less than three locale identifiers are loaded, the value of this flag is irrelevant.
KLF_RESET(0x40000000)
If set but KLF_SHIFTLOCK is not set, the Caps Lock state is turned off by pressing the Caps Lock key again. If set and KLF_SHIFTLOCK is also set, the Caps Lock state is turned off by pressing either SHIFT key.
These two methods are mutually exclusive, and the setting persists as part of the User's profile in the registry.
KLF_SETFORPROCESS(0x00000100)
Activates the specified locale identifier for the entire process and sends the WM_INPUTLANGCHANGE message to the current thread's Focus or Active window.
KLF_SHIFTLOCK(0x00010000)
This is used with KLF_RESET. See KLF_RESET for an explanation.
KLF_UNLOADPREVIOUS(不支持)
This flag is unsupported. Use the UnloadKeyboardLayout function instead.
Return Value
HKL
The return value is of type HKL. If the function succeeds, the return value is the previous input locale identifier. Otherwise, it is zero.
To get extended error information, use the GetLastError function.
Remarks
This function only affects the layout for the current process or thread.
This function is not restricted to keyboard layouts. The hkl parameter is actually an input locale identifier. This is a broader concept than a keyboard layout, since it can also encompass a speech-to-text converter, an Input Method Editor (IME), or any other form of input. Several input locale identifiers can be loaded at any one time, but only one is active at a time. Loading multiple input locale identifiers makes it possible to rapidly switch between them.
When multiple IMEs are allowed for each locale, passing an input locale identifier in which the high word (the device handle) is zero activates the first IME in the list belonging to the locale.
The KLF_RESET and KLF_SHIFTLOCK flags alter the method by which the Caps Lock state is turned off. By default, the Caps Lock state is turned off by hitting the Caps Lock key again. If only KLF_RESET is set, the default state is reestablished. If KLF_RESET and KLF_SHIFTLOCK are set, the Caps Lock state is turned off by pressing either Caps Lock key. This feature is used to conform to local keyboard behavior standards as well as for personal preferences.