Click to Rate and Give Feedback
MSDN
MSDN Library
User Interface
User Input
Keyboard Input
Functions
 ActivateKeyboardLayout Function
ActivateKeyboardLayout Function

The ActivateKeyboardLayout function sets the input locale identifier (formerly called the keyboard layout handle) for the calling thread or the current process. The input locale identifier specifies a locale as well as the physical layout of the keyboard.

Syntax

HKL ActivateKeyboardLayout(      
    HKL hkl,     UINT Flags );

Parameters

hkl
[in] Input locale identifier to be activated.

Windows 95/98/Me: This parameter can be obtained using LoadKeyboardLayout or GetKeyboardLayoutList, or it can be one of the values in the table that follows.

Windows NT/2000/XP: 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
Selects the next locale identifier in the circular list of loaded locale identifiers maintained by the system.
HKL_PREV
Selects the previous locale identifier in the circular list of loaded locale identifiers maintained by the system.
Flags
[in] Specifies how the input locale identifier is to be activated. This parameter can be one of the following values.
KLF_REORDER
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
Windows 2000/XP: 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
Windows 2000/XP: 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
Windows 2000/XP: 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

Windows NT 3.51 and earlier: The return value is of type BOOL. If the function succeeds, it is nonzero. If the function fails, it is zero.

Windows 95/98, Windows NT 4.0 and later: 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.

Windows 95/98/Me: An application can create a valid input locale identifier by setting the high word to zero and the low word to a locale identifier. Using such an input locale identifier changes the input language without affecting the physical layout.

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.

Windows 2000/XP: 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.

Function Information

Minimum DLL Versionuser32.dll
HeaderDeclared in Winuser.h, include Windows.h
Import libraryUser32.lib
Minimum operating systems Windows 95, Windows NT 3.1

See Also

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
vb.net syntax      dmex   |   Edit   |   Show History
<DllImport("user32.dll", CharSet:=CharSet.Auto, ExactSpelling:=True)> _
Public Shared Function ActivateKeyboardLayout(ByVal hkl As IntPtr, ByVal uFlags As Integer) As IntPtr
End Function
Flag as ContentBug
C# syntax      dmex   |   Edit   |   Show History
[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
public static extern IntPtr ActivateKeyboardLayout(IntPtr hkl, int uFlags);
Tags What's this?: c# (x) syntax (x) Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker