Keyboard Maliit

The library allows you to control the Maliit keyboard.

Dependency libraries

  • maliit-glib

Features

  • Keyboard open/close, input type selection.
  • Check is open keyboard / get keyboard height.
  • Editor sessions: the keyboard types into one editor at a time; showing it for another editor ends the previous session.
  • Push editor state (surrounding text, cursor, selection, input flags) to the input method.
  • Receive committed text, preedit updates, raw key events and hide requests in the editor; listen state (height/visibility).
  • Reset / copy-paste state / rotate keyboard.

Example

// Listen state (height/visibility)
val stateId = Keyboard.listenState { id, event ->
    println(event)
}

// The editor the keyboard types into; called on the GLib thread
val editor = object : KeyboardEditor {
    override fun onCommit(event: TextEvent) = println(event.text)
    override fun onPreedit(event: TextEvent) = println(event.text)
    override fun onKey(event: KeyEvent) = println(event)
    override fun onHide() = println("hidden by the user")
}

// Give the keyboard to the editor and show it with the Email layout
val session = Keyboard.show(
    editor,
    EditorState(surroundingText = "hello", cursorPosition = 5, contentType = KeyboardType.Email),
)
println("isOpen=${Keyboard.isOpen()}, height=${Keyboard.height()}")

// Push the editor state after the focused field's text changed
session.update(EditorState(surroundingText = "hello!", cursorPosition = 6, contentType = KeyboardType.Email))

// Reset the input method after a programmatic change, report copy/paste availability
session.reset()
session.setCopyPasteState(copyAvailable = true, pasteAvailable = false)

// Re-activate after returning to foreground: also shows the keyboard again for the editor
Keyboard.activate()

// Rotate on orientation change
Keyboard.rotate(90)

// End the session and hide the keyboard; does nothing once another editor has the keyboard
session.hide()

// Cleanup
Keyboard.unlistenState(stateId)
Keyboard.unlistenStateAll()