跳到正文
元书输入法使用文档

文档首页键盘皮肤

事件通知

本页目录

当键盘元素需要根据某些状态动态变化时,就可以使用「事件通知」功能。

比如:

  • 模仿系统键盘回车键在某些场景下是蓝色,某些是正常系统键颜色。
  • 跟踪并显示当前 RIME 某个 option 的值,比如 ascii_mode 的值,以完成 RIME 的中英文输入切换。

通知的设置需要绑定在按键样式上,具体来说,就是在按键样式的 notification 配置中进行设置。

按键也包含工具栏上的按键。

示例:

qButton:
backgroundStyle: alphabeticBackgroundStyle
foregroundStyle:
- qButtonForegroundStyle
- qButtonUpForegroundStyle
...
notification:
- keyboardActionNotification

目前通知有以下几种类型:

  • RIME 类型通知:监听 RIME 引擎通知事件。
  • 键盘动作类型通知:监听键盘发出的某一种 KeyboardAction。
  • 回车键类型通知:监听系统回车键的类型。
  • RIME 预编辑文本通知类型:监听 RIME 预编辑文本的变化。

通知类型

RIME 类型通知

RIME 类型通知用于监听 RIME 输入法的通知事件。

notificationType: rime

RIME 类型通知也有自己的分类,通过 rimeNotificationType 设置:

  • optionChanged: 监听 RIME option 变更
  • schemaChanged: 监听 rime 输入方案变更

RIME Option 变更通知

RIME Option 变更通知用于监听 RIME 输入法的 option 变更事件。

notificationType: rime
rimeNotificationType: optionChanged
rimeOptionName: ascii_mode
rimeOptionValue: true

当通知中的内容与 rimeOptionName 和 rimeOptionValue 设置的内容匹配时,触发样式变化。当 rimeOptionName 匹配,而 rimeOptionValue 设的值与当前的值不匹配时,按键会恢复为原始样式。

RIME schema 变更通知

RIME schema 变更通知用于监听 RIME 引擎的输入方案变更事件。

notificationType: rime
rimeNotificationType: schemaChanged
# rimeSchemaID 与 rimeSchemaName 二选一设置,建议使用 rimeSchemaID,中文在不同编码下判断可能会有问题
rimeSchemaID: 方案ID
rimeSchemaName: 方案名称

键盘动作类型通知

键盘动作类型通知用于监听键盘发出的某一种 KeyboardAction。

notificationType: keyboardAction
notificationKeyboardAction: { character: 'a' }

回车键类型通知

回车键类型通知用于监听系统回车键的类型。

notificationType: returnKeyType
returnKeyType: [1, 4, 7]

RIME 预编辑文本通知类型

RIME 预编辑文本通知类型用于监听 RIME 预编辑文本的变化。

notificationType: preeditChanged
backgroundStyle: blueSystemButtonBackgroundStyle
foregroundStyle: enterButtonWhiteForegroundStyle
action: enter

注意:这里设置的样式为 rime preedit 存在时的样式,当 preedit 为空时,按键会恢复为原始样式。

根据通知调整按键样式及动作

在通知设置中,可以通过 backgroundStyle,foregroundStyle,action, swipeUpAction, swipeDownAction 参数改变按键的样式及触发动作。

blueReturnKeyTypeNotification:
notificationType: returnKeyType
returnKeyType: [1, 4, 7]
backgroundStyle: blueSystemButtonBackgroundStyle
foregroundStyle: enterButtonWhiteForegroundStyle
action: enter

锁定通知结果

可以使用参数 lockedNotificationMatchState 来锁定匹配后的状态。

注意:锁定状态后,当通知结果不匹配后,按键也不会发生。

示例:

changeFlypyRimeSchemaNotification:
  notificationType: keyboardAction
  notificationKeyboardAction: { switchRimeSchema: 'aaa' }
  lockedNotificationMatchState: true
  foregroundStyle:
    # - rightArrowButtonForegroundStyle
    - rightArrowButtonSwitchChineseForegroundStyle
  action: { switchRimeSchema: 'bbb' }
指南目录

输入关键词,例如「皮肤」或「输入方案」。