Skip to content

SIL.Windows.Forms.Keyboarding

Damien Daspit edited this page Dec 9, 2015 · 3 revisions

SIL.Windows.Forms.Keyboarding provides an implementation of the SIL.Keyboarding.IKeyboardController interface (defined in SIL.Core) that can be used to support keyboard switching in Windows Forms applications. Currently, this library supports system and Keyman keyboards on Windows, and X keyboard extension (XKB) and Intelligent Input Bus (IBus) keyboards on Linux.

Keyboard Controller

The KeyboardController class provides a Windows Forms implementation of the SIL.Keyboarding.IKeyboardController interface. An application interacts with the class through a static API for initialization/shutdown and control registration. All other interactions, such as getting or activating keyboards, occur using the Controller static property on the SIL.Keyboarding.Keyboard class.

The keyboard controller is initialized using the Initialize method. An application can pass a list of keyboard adaptors to this method call if it wishes. If it does not, a default set of keyboard adaptors will be initialized depending on the platform. This method should be called during application startup. The keyboard controller should be shutdown properly before the application exits by calling the Shutdown method.

Any Windows Forms controls that need to handle keyboard input need to be registered with the controller by calling RegisterControl. On Windows, if the applications needs to be notified when a user switches the keyboard, then the application can pass an object to this method that implements the SIL.Windows.Forms.Keyboarding.Windows.IWindowsLanguageProfileSink interface. On Linux, if the application needs to perform specific behavior with IBus pre-edit handling, then the application can pass an object to this method that implements the SIL.Windows.Forms.Keyboarding.Linux.IIbusEventHandler interface. If the control is a TextBox, then the application does not need to pass an IBus event handler. The application should call UnregisterControl for all registered controls prior to disposing them.

Keyboard Adaptors

Typically, a keyboard adaptor is needed for each type of keyboard available on a platform. Keyboard adaptors implement the IKeyboardRetrievingAdaptor interface. All keyboard adaptors are responsible for encapsulating the following behavior: keyboard activation, retrieving a list of available keyboard definitions, and instantiating unavailable keyboard definitions. In the SIL.Windows.Forms.Keyboarding assembly, all keyboard definitions inherit from the KeyboardDescription class. Keyboard adaptors interact with the keyboard controller using the singleton instance that can be retrieved from the Instance property on the KeyboardController class.