IMKServerInput is an informal protocol that defines methods for receiving text events. This is intentionally not a formal protocol because there are three ways to receive events. An input method chooses one of the following approaches and implements the appropriate methods:


  • Key binding. In this approach the system tries to map each key-down event to an action method that the input method has implemented. If successful (action method found), the system calls didCommandBySelector:client:. If unsuccessful (action method not found), the system calls inputText:client:. For this approach you need to implement inputText(_:client:) and didCommand(by:client:).

  • Text data only. In this approach, you opt to receive all key events without the key binding, and then unpack the relevant text data. Key events are broken down into the Unicodes, the key code that generated them, and modifier flags. This data is then sent to the inputText(_:key:modifiers:client:) method, which you need to implement.

  • Handle all events. In this approach, you receive events directly from the Text Services Manager as NSEvent objects. You must implement handle(_:client:) method.


Supporting Key Binding

func inputText(String!, client: Any!) -> Bool

Handles key down events that do not map to an action method.

func didCommand(by: Selector!, client: Any!) -> Bool

Processes a command generated by user action such as typing certain keys or pressing the mouse button.

Unpacking Text Data

func inputText(String!, key: Int, modifiers: Int, client: Any!) -> Bool

Receives Unicode, the key code that generated it, and any modifier flags.

Receiving Events Directly from the Text Services Manager

func handle(NSEvent!, client: Any!) -> Bool

Handles key down and mouse events.

Committing a Composition

func commitComposition(Any!)

Informs the controller that the composition should be committed.

Getting Input Strings and Candidates

func composedString(Any!) -> Any!

Return the current composed string.

func originalString(Any!) -> NSAttributedString!

Return the string that consists of the precomposed Unicode characters.

func candidates(Any!) -> [Any]!

Returns an array of candidates.


Info Dictionary Keys

Constants for keys used to look up information in the info dictionary.