本模塊面向輸入法應用(包括系統(tǒng)輸入法應用、三方輸入法應用),為輸入法應用提供能力,功能包括:創(chuàng)建軟鍵盤窗口、插入/刪除字符、選中文本、物理鍵盤按鍵事件監(jiān)聽等。
本模塊首批接口從API version 8開始支持。后續(xù)版本的新增接口,采用上角標單獨標記接口的起始版本。
功能鍵常量值、編輯框常量值及光標常量值。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
名稱 | 類型 | 值 | 說明 |
---|---|---|---|
ENTER_KEY_TYPE_UNSPECIFIED | number | 0 | 無功能鍵。 |
ENTER_KEY_TYPE_GO | number | 2 | “前往”功能鍵。 |
ENTER_KEY_TYPE_SEARCH | number | 3 | “搜索”功能鍵。 |
ENTER_KEY_TYPE_SEND | number | 4 | “發(fā)送”功能鍵。 |
ENTER_KEY_TYPE_NEXT | number | 5 | “下一個”功能鍵。 |
ENTER_KEY_TYPE_DONE | number | 6 | “回車”功能鍵。 |
ENTER_KEY_TYPE_PREVIOUS | number | 7 | “前一個”功能鍵。 |
PATTERN_NULL | number | -1 | 無特殊性編輯框。 |
PATTERN_TEXT | number | 0 | 文本編輯框。 |
PATTERN_NUMBER | number | 2 | 數字編輯框。 |
PATTERN_PHONE | number | 3 | 電話號碼編輯框。 |
PATTERN_DATETIME | number | 4 | 日期編輯框。 |
PATTERN_EMAIL | number | 5 | 郵件編輯框。 |
PATTERN_URI | number | 6 | 超鏈接編輯框。 |
PATTERN_PASSWORD | number | 7 | 密碼編輯框。 |
OPTION_ASCII | number | 20 | 允許輸入ASCII值。 |
OPTION_NONE | number | 0 | 不指定編輯框輸入屬性。 |
OPTION_AUTO_CAP_CHARACTERS | number | 2 | 允許輸入字符。 |
OPTION_AUTO_CAP_SENTENCES | number | 8 | 允許輸入句子。 |
OPTION_AUTO_WORDS | number | 4 | 允許輸入單詞。 |
OPTION_MULTI_LINE | number | 1 | 允許輸入多行。 |
OPTION_NO_FULLSCREEN | number | 10 | 半屏樣式。 |
FLAG_SELECTING | number | 2 | 編輯框處于選擇狀態(tài)。 |
FLAG_SINGLE_LINE | number | 1 | 編輯框為單行。 |
DISPLAY_MODE_PART | number | 0 | 編輯框顯示為半屏。 |
DISPLAY_MODE_FULL | number | 1 | 編輯框顯示為全屏。 |
CURSOR_UP9+ | number | 1 | 光標上移。 |
CURSOR_DOWN9+ | number | 2 | 光標下移。 |
CURSOR_LEFT9+ | number | 3 | 光標左移。 |
CURSOR_RIGHT9+ | number | 4 | 光標右移。 |
WINDOW_TYPE_INPUT_METHOD_FLOAT9+ | number | 2105 | 輸入法應用窗口風格標識。 |
getInputMethodAbility(): InputMethodAbility
獲取服務端實例。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
返回值:
類型 | 說明 |
---|---|
服務端實例。 |
示例:
- let InputMethodAbility = inputMethodEngine.getInputMethodAbility();
getKeyboardDelegate(): KeyboardDelegate
獲取客戶端監(jiān)聽實例。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
返回值:
類型 | 說明 |
---|---|
客戶端監(jiān)聽實例。 |
示例:
- let KeyboardDelegate = inputMethodEngine.getKeyboardDelegate();
getInputMethodEngine(): InputMethodEngine
獲取服務端實例。
從API version 8開始支持,API version 9開始廢棄, 建議使用getInputMethodAbility()替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
返回值:
類型 | 說明 |
---|---|
服務端實例。 |
示例:
- let InputMethodEngine = inputMethodEngine.getInputMethodEngine();
createKeyboardDelegate(): KeyboardDelegate
獲取客戶端監(jiān)聽實例。
從API version 8開始支持,API version 9開始廢棄, 建議使用getKeyboardDelegate()替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
返回值:
類型 | 說明 |
---|---|
客戶端監(jiān)聽實例。 |
示例:
- let keyboardDelegate = inputMethodEngine.createKeyboardDelegate();
on(type: 'inputStart', callback: (kbController: KeyboardController, textInputClient: TextInputClient) => void): void
訂閱輸入法綁定成功事件。使用callback異步回調。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 設置監(jiān)聽類型。 - type為‘inputStart’時表示訂閱輸入法綁定。 |
callback | (kbController: KeyboardController, textInputClient: TextInputClient) => void | 是 | 回調函數,返回訂閱輸入法的KeyboardController和TextInputClient實例。 |
示例:
- inputMethodEngine.getInputMethodEngine().on('inputStart', (kbController, textClient) => {
- let keyboardController = kbController;
- let textInputClient = textClient;
- });
off(type: 'inputStart', callback?: (kbController: KeyboardController, textInputClient: TextInputClient) => void): void
取消訂閱輸入法綁定成功事件。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 設置監(jiān)聽類型。 - type為‘inputStart’時表示訂閱輸入法綁定。 |
callback | (kbController: KeyboardController, textInputClient: TextInputClient) => void | 否 | 回調函數,返回取消訂閱的KeyboardController和TextInputClient實例。 |
示例:
- inputMethodEngine.getInputMethodEngine().off('inputStart', (kbController, textInputClient) => {
- console.log('delete inputStart notification.');
- });
on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void
訂閱輸入法事件。使用callback異步回調。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 設置監(jiān)聽類型。 - type為'keyboardShow',表示訂閱輸入法顯示。 - type為'keyboardHide',表示訂閱輸入法隱藏。 |
callback | () => void | 是 | 回調函數。 |
示例:
- inputMethodEngine.getInputMethodEngine().on('keyboardShow', () => {
- console.log('inputMethodEngine keyboardShow.');
- });
- inputMethodEngine.getInputMethodEngine().on('keyboardHide', () => {
- console.log('inputMethodEngine keyboardHide.');
- });
off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void
取消訂閱輸入法事件。使用callback異步回調。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 設置監(jiān)聽類型。 - type為'keyboardShow',表示訂閱輸入法顯示。 - type為'keyboardHide',表示訂閱輸入法隱藏。 |
callback | () => void | 否 | 回調函數。 |
示例:
- inputMethodEngine.getInputMethodEngine().off('keyboardShow');
- inputMethodEngine.getInputMethodEngine().off('keyboardHide');
on(type: 'inputStart', callback: (kbController: KeyboardController, inputClient: InputClient) => void): void
訂閱輸入法綁定成功事件。使用callback異步回調。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 設置監(jiān)聽類型。 - type為‘inputStart’時表示訂閱輸入法綁定。 |
callback | (kbController: KeyboardController, inputClient: InputClient) => void | 是 | 回調函數,返回輸入法操作相關實例。 |
示例:
- inputMethodEngine.getInputMethodAbility().on('inputStart', (kbController, client) => {
- let keyboardController = kbController;
- let inputClient = client;
- });
off(type: 'inputStart', callback?: (kbController: KeyboardController, inputClient: InputClient) => void): void
取消訂閱輸入法綁定成功事件。使用callback異步回調。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 設置監(jiān)聽類型。 - type為‘inputStart’時表示訂閱輸入法綁定。 |
callback | (kbController: KeyboardController, inputClient: InputClient) => void | 否 | 回調函數,返回輸入法操作相關實例。 |
示例:
- inputMethodEngine.getInputMethodAbility().off('inputStart');
on(type: 'inputStop', callback: () => void): void
訂閱停止輸入法應用事件。使用callback異步回調。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 設置監(jiān)聽類型。 - type為‘inputStop’時表示訂閱停止輸入法應用事件。 |
callback | () => void | 是 | 回調函數。 |
示例:
- inputMethodEngine.getInputMethodAbility().on('inputStop', () => {
- console.log('inputMethodAbility inputStop');
- });
off(type: 'inputStop', callback: () => void): void
取消訂閱停止輸入法應用事件。使用callback異步回調。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 設置監(jiān)聽類型。 - type為‘inputStop’時表示訂閱停止輸入法應用事件。 |
callback | () => void | 是 | 回調函數。 |
示例:
- inputMethodEngine.getInputMethodAbility().off('inputStop', () => {
- console.log('inputMethodAbility delete inputStop notification.');
- });
on(type: 'setCallingWindow', callback: (wid: number) => void): void
訂閱設置調用窗口事件。使用callback異步回調。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 設置監(jiān)聽類型。 - type為‘setCallingWindow’時表示訂閱設置調用窗口事件。 |
callback | (wid: number) => void | 是 | 回調函數,返回調用方window id。 |
示例:
- inputMethodEngine.getInputMethodAbility().on('setCallingWindow', (wid) => {
- console.log('inputMethodAbility setCallingWindow');
- });
off(type: 'setCallingWindow', callback: (wid:number) => void): void
取消訂閱設置調用窗口事件。使用callback異步回調。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 設置監(jiān)聽類型。 - type為‘setCallingWindow’時表示訂閱設置調用窗口事件。 |
callback | (wid:number) => void | 是 | 回調函數,返回調用方window id。 |
示例:
- inputMethodEngine.getInputMethodAbility().off('setCallingWindow', () => {
- console.log('inputMethodAbility delete setCallingWindow notification.');
- });
on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void
訂閱輸入法事件。使用callback異步回調。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 設置監(jiān)聽類型。 - type為'keyboardShow',表示訂閱顯示鍵盤事件。 - type為'keyboardHide',表示訂閱隱藏鍵盤事件。 |
callback | () => void | 是 | 回調函數。 |
示例:
- inputMethodEngine.getInputMethodAbility().on('keyboardShow', () => {
- console.log('InputMethodAbility keyboardShow.');
- });
- inputMethodEngine.getInputMethodAbility().on('keyboardHide', () => {
- console.log('InputMethodAbility keyboardHide.');
- });
off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void
取消訂閱輸入法事件。使用callback異步回調。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 設置監(jiān)聽類型。 - type為'keyboardShow',表示取消訂閱顯示鍵盤事件。 - type為'keyboardHide',表示取消訂閱隱藏鍵盤事件。 |
callback | () => void | 否 | 回調函數。 |
示例:
- inputMethodEngine.getInputMethodAbility().off('keyboardShow', () => {
- console.log('InputMethodAbility delete keyboardShow notification.');
- });
- inputMethodEngine.getInputMethodAbility().off('keyboardHide', () => {
- console.log('InputMethodAbility delete keyboardHide notification.');
- });
on(type: 'setSubtype', callback: (inputMethodSubtype: InputMethodSubtype) => void): void
訂閱設置輸入法子類型事件。使用callback異步回調。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 設置監(jiān)聽類型。 - type為'setSubtype',表示訂閱輸入法子類型的設置事件。 |
callback | (inputMethodSubtype: InputMethodSubtype) => void | 是 | 回調函數,返回設置的輸入法子類型。 |
示例:
- inputMethodEngine.getInputMethodAbility().on('setSubtype', (inputMethodSubtype) => {
- console.log('InputMethodAbility setSubtype.');
- });
off(type: 'setSubtype', callback?: (inputMethodSubtype: InputMethodSubtype) => void): void
取消訂閱輸入法子類型事件。使用callback異步回調。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 設置監(jiān)聽類型。 - type為'setSubtype',表示取消訂閱輸入法子類型的設置事件。 |
callback | (inputMethodSubtype: InputMethodSubtype) => void | 否 | 回調函數,返回設置的輸入法子類型。 |
示例:
- inputMethodEngine.getInputMethodAbility().off('setSubtype', () => {
- console.log('InputMethodAbility delete setSubtype notification.');
- });
on(type: 'keyDown'|'keyUp', callback: (event: KeyEvent) => boolean): void
訂閱硬鍵盤(即物理鍵盤)事件。使用callback異步回調。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 設置監(jiān)聽類型。 - type為'keyDown',表示訂閱硬鍵盤按下事件。 - type為'keyUp',表示訂閱硬鍵盤抬起事件。 |
callback | (event: KeyEvent) => boolean | 是 | 回調函數,返回按鍵信息。 |
示例:
- inputMethodEngine.getKeyboardDelegate().on('keyUp', (keyEvent) => {
- console.info('inputMethodEngine keyCode.(keyUp):' + JSON.stringify(keyEvent.keyCode));
- console.info('inputMethodEngine keyAction.(keyUp):' + JSON.stringify(keyEvent.keyAction));
- return true;
- });
- inputMethodEngine.getKeyboardDelegate().on('keyDown', (keyEvent) => {
- console.info('inputMethodEngine keyCode.(keyDown):' + JSON.stringify(keyEvent.keyCode));
- console.info('inputMethodEngine keyAction.(keyDown):' + JSON.stringify(keyEvent.keyAction));
- return true;
- });
off(type: 'keyDown'|'keyUp', callback?: (event: KeyEvent) => boolean): void
取消訂閱硬鍵盤(即物理鍵盤)事件。使用callback異步回調。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 設置監(jiān)聽類型。 - type為'keyDown',表示取消訂閱硬鍵盤按下事件。 - type為'keyUp',表示取消訂閱硬鍵盤抬起事件。 |
callback | (event: KeyEvent) => boolean | 否 | 回調函數,返回按鍵信息。 |
示例:
- inputMethodEngine.getKeyboardDelegate().off('keyUp', (keyEvent) => {
- console.log('delete keyUp notification.');
- return true;
- });
- inputMethodEngine.getKeyboardDelegate().off('keyDown', (keyEvent) => {
- console.log('delete keyDown notification.');
- return true;
- });
on(type: 'cursorContextChange', callback: (x: number, y:number, height:number) => void): void
訂閱光標變化事件。使用callback異步回調。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 光標變化事件。 - type為’cursorContextChange‘時,表示訂閱光標變化事件。 |
callback | (x: number, y: number, height: number) => void | 是 | 回調函數,返回光標信息。 - x為光標上端的的x坐標值。 - y為光標上端的y坐標值。 - height為光標的高度值。 |
示例:
- inputMethodEngine.getKeyboardDelegate().on('cursorContextChange', (x, y, height) => {
- console.log('inputMethodEngine cursorContextChange x:' + x);
- console.log('inputMethodEngine cursorContextChange y:' + y);
- console.log('inputMethodEngine cursorContextChange height:' + height);
- });
off(type: 'cursorContextChange', callback?: (x: number, y: number, height: number) => void): void
取消訂閱光標變化事件。使用callback異步回調。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 光標變化事件。 - type為’cursorContextChange‘時,表示光標變化。 |
callback | (x: number, y:number, height:number) => void | 否 | 回調函數,返回光標信息。 - x為光標上端的的x坐標值。 - y為光標上端的y坐標值。 - height為光標的高度值。 |
示例:
- inputMethodEngine.getKeyboardDelegate().off('cursorContextChange', (x, y, height) => {
- console.log('delete cursorContextChange notification.');
- });
on(type: 'selectionChange', callback: (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void): void
訂閱文本選擇變化事件。使用callback異步回調。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 文本選擇變化事件。 - type為’selectionChange‘時,表示選擇文本變化。 |
callback | (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void | 是 | 回調函數,返回文本選擇信息。 - oldBegin為變化之前被選中文本的起始下標。 - oldEnd為變化之前被選中文本的終止下標。 - newBegin為變化之后被選中文本的起始下標。 - newEnd為變化之后被選中文本的終止下標。 |
示例:
- inputMethodEngine.getKeyboardDelegate().on('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => {
- console.log('inputMethodEngine beforeEach selectionChange oldBegin:' + oldBegin);
- console.log('inputMethodEngine beforeEach selectionChange oldEnd:' + oldEnd);
- console.log('inputMethodEngine beforeEach selectionChange newBegin:' + newBegin);
- console.log('inputMethodEngine beforeEach selectionChange newEnd:' + newEnd);
- });
off(type: 'selectionChange', callback?: (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void): void
取消訂閱文本選擇變化事件。使用callback異步回調。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 文本選擇變化事件。 - type為’selectionChange‘時,表示選擇文本變化。 |
callback | (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void | 否 | 回調函數,返回文本選擇信息。 - oldBegin為變化之前被選中文本的起始下標。 - oldEnd為變化之前被選中文本的終止下標。 - newBegin為變化之后被選中文本的起始下標。 - newEnd為變化之后被選中文本的終止下標。 |
示例:
- inputMethodEngine.getKeyboardDelegate().off('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => {
- console.log('delete selectionChange notification.');
- });
on(type: 'textChange', callback: (text: string) => void): void
訂閱文本變化事件。使用callback異步回調。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 文本變化事件。 - type為’textChange‘時,表示訂閱文本變化事件。 |
callback | (text: string) => void | 是 | 回調函數,返回訂閱的文本內容。 |
示例:
- inputMethodEngine.getKeyboardDelegate().on('textChange', (text) => {
- console.log('inputMethodEngine textChange. text:' + text);
- });
off(type: 'textChange', callback?: (text: string) => void): void
取消訂閱文本變化事件。使用callback異步回調。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 文本變化事件。 - type為’textChange‘時,表示取消訂閱文本變化事件。 |
callback | (text: string) => void | 否 | 回調函數,返回取消訂閱的文本內容。 |
示例:
- inputMethodEngine.getKeyboardDelegate().off('textChange', (text) => {
- console.log('delete textChange notification. text:' + text);
- });
hide(callback: AsyncCallback<void>): void
隱藏輸入法。使用callback異步回調。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
callback | AsyncCallback<void> | 是 | 回調函數。當輸入法隱藏成功,err為undefined,否則為錯誤對象。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見輸入法框架錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
12800003 | input method client error. |
示例:
- keyboardController.hide((err) => {
- if (err !== undefined) {
- console.error('Failed to hide keyboard: ' + JSON.stringify(err));
- return;
- }
- console.log('Succeeded in hiding keyboard.');
- });
hide(): Promise<void>
隱藏輸入法。使用promise異步回調。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結果的Promise對象。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見輸入法框架錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
12800003 | input method client error. |
示例:
- keyboardController.hide().then(() => {
- console.info('Succeeded in hiding keyboard.');
- }).catch((err) => {
- console.info('Failed to hide keyboard: ' + JSON.stringify(err));
- });
hideKeyboard(callback: AsyncCallback<void>): void
隱藏輸入法。使用callback異步回調。
從API version 8開始支持,API version 9開始廢棄, 建議使用hide替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
callback | AsyncCallback<void> | 是 | 回調函數。當輸入法隱藏成功,err為undefined,否則為錯誤對象。 |
示例:
- keyboardController.hideKeyboard((err) => {
- if (err !== undefined) {
- console.error('Failed to hide Keyboard: ' + JSON.stringify(err));
- return;
- }
- console.log('Succeeded in hiding keyboard.');
- });
hideKeyboard(): Promise<void>
隱藏輸入法。使用promise異步回調。
從API version 8開始支持,API version 9開始廢棄, 建議使用hide替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結果的Promise對象。 |
示例:
- keyboardController.hideKeyboard().then(() => {
- console.info('Succeeded in hiding keyboard.');
- }).catch((err) => {
- console.info('Failed to hide Keyboard: ' + JSON.stringify(err));
- });
sendKeyFunction(action:number, callback: AsyncCallback<boolean>): void
發(fā)送功能鍵。使用callback異步回調。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
action | number | 是 | 功能鍵鍵值。 當值為0時,表示無效按鍵; 當值為1時,表示確認鍵(即回車鍵)。 |
callback | AsyncCallback<boolean> | 是 | 回調函數。當功能鍵發(fā)送成功,err為undefined,data為true;否則為錯誤對象。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見輸入法框架錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
12800003 | input method client error. |
示例:
- let action = 1;
- try {
- inputClient.sendKeyFunction(action, (err, result) => {
- if (err !== undefined) {
- console.error('Failed to sendKeyFunction: ' + JSON.stringify(err));
- return;
- }
- if (result) {
- console.info('Succeeded in sending key function. ');
- } else {
- console.error('Failed to sendKeyFunction. ');
- }
- });
- } catch (err) {
- console.error('sendKeyFunction err: ' + JSON.stringify(err));
- }
sendKeyFunction(action: number): Promise<boolean>
發(fā)送功能鍵。使用promise異步回調。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
action | number | 是 | 功能鍵鍵值。 當值為0時,表示無效按鍵; 當值為1時,表示確認鍵(即回車鍵)。 |
返回值:
類型 | 說明 |
---|---|
Promise<boolean> | Promise對象。返回true表示功能鍵發(fā)送成功;返回false表示功能鍵發(fā)送失敗。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見輸入法框架錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
12800003 | input method client error. |
示例:
- let action = 1;
- try {
- inputClient.sendKeyFunction(action).then((result) => {
- if (result) {
- console.info('Succeeded in sending key function. ');
- } else {
- console.error('Failed to sendKeyFunction. ');
- }
- }).catch((err) => {
- console.error('Failed to sendKeyFunction:' + JSON.stringify(err));
- });
- } catch (err) {
- console.error('Failed to sendKeyFunction: ' + JSON.stringify(err));
- }
getForward(length:number, callback: AsyncCallback<string>): void
獲取光標前固定長度的文本。使用callback異步回調。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
length | number | 是 | 文本長度。 |
callback | AsyncCallback<string> | 是 | 回調函數。當光標前固定長度的文本獲取成功,err為undefined,data為獲取到的文本;否則為錯誤對象。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見輸入法框架錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
12800003 | input method client error. |
12800006 | Input method controller error. |
示例:
- let length = 1;
- try {
- inputClient.getForward(length, (err, text) => {
- if (err !== undefined) {
- console.error('Failed to getForward: ' + JSON.stringify(err));
- return;
- }
- console.log('Succeeded in getting forward, text: ' + text);
- });
- } catch (err) {
- console.error('Failed to getForward: ' + JSON.stringify(err));
- }
getForward(length:number): Promise<string>
獲取光標前固定長度的文本。使用promise異步回調。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
length | number | 是 | 文本長度。 |
返回值:
類型 | 說明 |
---|---|
Promise<string> | Promise對象,返回光標前固定長度的文本。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見輸入法框架錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
12800003 | input method client error. |
12800006 | Input method controller error. |
示例:
- let length = 1;
- try {
- inputClient.getForward(length).then((text) => {
- console.info('Succeeded in getting forward, text: ' + text);
- }).catch((err) => {
- console.error('Failed to getForward: ' + JSON.stringify(err));
- });
- } catch (err) {
- console.error('Failed to getForward: ' + JSON.stringify(err));
- }
getBackward(length:number, callback: AsyncCallback<string>): void
獲取光標后固定長度的文本。使用callback異步回調。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
length | number | 是 | 文本長度。 |
callback | AsyncCallback<string> | 是 | 回調函數。當光標后固定長度的文本獲取成功,err為undefined,data為獲取到的文本;否則為錯誤對象。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見輸入法框架錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
12800003 | input method client error. |
12800006 | Input method controller error. |
示例:
- let length = 1;
- try {
- inputClient.getBackward(length, (err, text) => {
- if (err !== undefined) {
- console.error('Failed to getForward: ' + JSON.stringify(err));
- return;
- }
- console.log('Succeeded in getting backward, text: ' + text);
- });
- } catch (err) {
- console.error('Failed to getForward: ' + JSON.stringify(err));
- }
getBackward(length:number): Promise<string>
獲取光標后固定長度的文本。使用promise異步回調。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
length | number | 是 | 文本長度。 |
返回值:
類型 | 說明 |
---|---|
Promise<string> | Promise對象,返回光標后固定長度的文本。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見輸入法框架錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
12800003 | input method client error. |
12800006 | Input method controller error. |
示例:
- let length = 1;
- try {
- inputClient.getBackward(length).then((text) => {
- console.info('Succeeded in getting backward, text: ' + text);
- }).catch((err) => {
- console.error('Failed to getForward: ' + JSON.stringify(err));
- });
- } catch (err) {
- console.error('Failed to getForward: ' + JSON.stringify(err));
- }
deleteForward(length:number, callback: AsyncCallback<boolean>): void
刪除光標前固定長度的文本。使用callback異步回調。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
length | number | 是 | 文本長度。 |
callback | AsyncCallback<boolean> | 是 | 回調函數。當光標前固定長度的文本刪除成功,err為undefined,data為true;否則為錯誤對象。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見輸入法框架錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
12800002 | Input method engine error. |
12800003 | input method client error. |
示例:
- let length = 1;
- try {
- inputClient.deleteForward(length, (err, result) => {
- if (err !== undefined) {
- console.error('Failed to delete forward: ' + JSON.stringify(err));
- return;
- }
- if (result) {
- console.info('Succeeded in deleting forward. ');
- } else {
- console.error('Failed to delete forward: ' + JSON.stringify(err));
- }
- });
- } catch (err) {
- console.error('Failed to delete forward: ' + JSON.stringify(err));
- }
deleteForward(length:number): Promise<boolean>
刪除光標前固定長度的文本。使用promise異步回調。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
length | number | 是 | 文本長度。 |
返回值:
類型 | 說明 |
---|---|
Promise<boolean> | Promise對象。返回true表示刪除光標前固定長度的文本成功;返回false表示刪除光標前固定長度的文本失敗。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見輸入法框架錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
12800002 | Input method engine error. |
12800003 | input method client error. |
示例:
- let length = 1;
- try {
- inputClient.deleteForward(length).then((result) => {
- if (result) {
- console.info('Succeeded in deleting forward. ');
- } else {
- console.error('Failed to delete Forward. ');
- }
- }).catch((err) => {
- console.error('Failed to delete Forward: ' + JSON.stringify(err));
- });
- } catch (err) {
- console.error('Failed to delete Forward: ' + JSON.stringify(err));
- }
deleteBackward(length:number, callback: AsyncCallback<boolean>): void
刪除光標后固定長度的文本。使用callback異步回調。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
length | number | 是 | 文本長度。 |
callback | AsyncCallback<boolean> | 是 | 回調函數。當光標后固定長度的文本刪除成功,err為undefined,data為true;否則為錯誤對象。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見輸入法框架錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
12800002 | Input method engine error. |
12800003 | input method client error. |
示例:
- let length = 1;
- try {
- inputClient.deleteBackward(length, (err, result) => {
- if (err !== undefined) {
- console.error('Failed to delete Backward: ' + JSON.stringify(err));
- return;
- }
- if (result) {
- console.info('Succeeded in deleting backward. ');
- } else {
- console.error('Failed to delete Backward: ' + JSON.stringify(err));
- }
- });
- } catch (err) {
- console.error('deleteBackward err: ' + JSON.stringify(err));
- }
deleteBackward(length:number): Promise<boolean>
刪除光標后固定長度的文本。使用promise異步回調。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
length | number | 是 | 文本長度。 |
返回值:
類型 | 說明 |
---|---|
Promise<boolean> | Promise對象。返回true表示刪除光標后固定長度的文本成功;返回false表示刪除光標后固定長度的文本失敗。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見輸入法框架錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
12800002 | Input method engine error. |
12800003 | input method client error. |
示例:
- let length = 1;
- inputClient.deleteBackward(length).then((result) => {
- if (result) {
- console.info('Succeeded in deleting backward. ');
- } else {
- console.error('Failed to deleteBackward. ');
- }
- }).catch((err) => {
- console.error('Failed to deleteBackward: ' + JSON.stringify(err));
- });
insertText(text:string, callback: AsyncCallback<boolean>): void
插入文本。使用callback異步回調。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
text | string | 是 | 文本。 |
callback | AsyncCallback<boolean> | 是 | 回調函數。當文本插入成功,err為undefined,data為true;否則為錯誤對象。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見輸入法框架錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
12800002 | Input method engine error. |
12800003 | input method client error. |
示例:
- inputClient.insertText('test', (err, result) => {
- if (err !== undefined) {
- console.error('Failed to insertText: ' + JSON.stringify(err));
- return;
- }
- if (result) {
- console.info('Succeeded in inserting text. ');
- } else {
- console.error('Failed to insertText. ');
- }
- });
insertText(text:string): Promise<boolean>
插入文本。使用promise異步回調。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
text | string | 是 | 文本。 |
返回值:
類型 | 說明 |
---|---|
Promise<boolean> | Promise對象。返回true表示插入文本成功;返回false表示插入文本失敗。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見輸入法框架錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
12800002 | Input method engine error. |
12800003 | input method client error. |
示例:
- try {
- inputClient.insertText('test').then((result) => {
- if (result) {
- console.info('Succeeded in inserting text. ');
- } else {
- console.error('Failed to insertText. ');
- }
- }).catch((err) => {
- console.error('Failed to insertText: ' + JSON.stringify(err));
- });
- } catch (err) {
- console.error('Failed to insertText: ' + JSON.stringify(err));
- }
getEditorAttribute(callback: AsyncCallback<EditorAttribute>): void
獲取編輯框屬性值。使用callback異步回調。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
callback | AsyncCallback<EditorAttribute> | 是 | 回調函數。當編輯框屬性值獲取成功,err為undefined,data為編輯框屬性值;否則為錯誤對象。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見輸入法框架錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
12800003 | input method client error. |
示例:
- inputClient.getEditorAttribute((err, editorAttribute) => {
- if (err !== undefined) {
- console.error('Failed to getEditorAttribute: ' + JSON.stringify(err));
- return;
- }
- console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern));
- console.log('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType));
- });
getEditorAttribute(): Promise<EditorAttribute>
獲取編輯框屬性值。使用promise異步回調。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
返回值:
類型 | 說明 |
---|---|
Promise<EditorAttribute> | Promise對象,返回編輯框屬性值。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見輸入法框架錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
12800003 | input method client error. |
示例:
- inputClient.getEditorAttribute().then((editorAttribute) => {
- console.info('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern));
- console.info('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType));
- }).catch((err) => {
- console.error('Failed to getEditorAttribute: ' + JSON.stringify(err));
- });
moveCursor(direction: number, callback: AsyncCallback<void>): void
移動光標。使用callback異步回調。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
direction | number | 是 | 光標移動方向。 |
callback | AsyncCallback<void> | 是 | 回調函數。當光標移動成功,err為undefined,否則為錯誤對象。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見輸入法框架錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
12800003 | input method client error. |
示例:
- try {
- inputClient.moveCursor(inputMethodEngine.CURSOR_UP, (err) => {
- if (err !== undefined) {
- console.error('Failed to moveCursor: ' + JSON.stringify(err));
- return;
- }
- console.info('Succeeded in moving cursor.');
- });
- } catch (err) {
- console.error('Failed to moveCursor: ' + JSON.stringify(err));
- }
moveCursor(direction: number): Promise<void>
移動光標。使用promise異步回調。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
direction | number | 是 | 光標移動方向。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結果的Promise對象。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見輸入法框架錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
12800003 | input method client error. |
示例:
- try {
- inputClient.moveCursor(inputMethodEngine.CURSOR_UP).then(() => {
- console.log('Succeeded in moving cursor.');
- }).catch((err) => {
- console.error('Failed to moveCursor: ' + JSON.stringify(err));
- });
- } catch (err) {
- console.log('Failed to moveCursor: ' + JSON.stringify(err));
- }
編輯框屬性值。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
名稱 | 類型 | 可讀 | 可寫 | 說明 |
---|---|---|---|---|
enterKeyType | number | 是 | 否 | 編輯框的功能屬性。 |
inputPattern | number | 是 | 否 | 編輯框的文本屬性。 |
按鍵屬性值。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
名稱 | 類型 | 可讀 | 可寫 | 說明 |
---|---|---|---|---|
keyCode | number | 是 | 否 | 按鍵的鍵值。鍵碼值說明參考 KeyCode。 |
keyAction | number | 是 | 否 | 按鍵的狀態(tài)。 當值為2時,表示按下事件; 當值為3時,表示抬起事件。 |
從API version 8開始支持,API version 9開始廢棄, 建議使用InputClient替代。
下列API示例中都需使用on('inputStart')回調獲取到TextInputClient實例,再通過此實例調用對應方法。
getForward(length:number, callback: AsyncCallback<string>): void
獲取光標前固定長度的文本。使用callback異步回調。
從API version 8開始支持,API version 9開始廢棄, 建議使用getForward替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
length | number | 是 | 文本長度。 |
callback | AsyncCallback<string> | 是 | 回調函數。當光標前固定長度的文本獲取成功,err為undefined,data為獲取到的文本;否則為錯誤對象。 |
示例:
- let length = 1;
- textInputClient.getForward(length, (err, text) => {
- if (err !== undefined) {
- console.error('Failed to getForward: ' + JSON.stringify(err));
- return;
- }
- console.log('Succeeded in getting forward, text: ' + text);
- });
getForward(length:number): Promise<string>
獲取光標前固定長度的文本。使用promise異步回調。
從API version 8開始支持,API version 9開始廢棄, 建議使用getForward替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
length | number | 是 | 文本長度。 |
返回值:
類型 | 說明 |
---|---|
Promise<string> | Promise對象,返回光標前固定長度的文本。 |
示例:
- let length = 1;
- textInputClient.getForward(length).then((text) => {
- console.info('Succeeded in getting forward, text: ' + text);
- }).catch((err) => {
- console.error('Failed to getForward: ' + JSON.stringify(err));
- });
getBackward(length:number, callback: AsyncCallback<string>): void
獲取光標后固定長度的文本。使用callback異步回調。
從API version 8開始支持,API version 9開始廢棄, 建議使用getBackward替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
length | number | 是 | 文本長度。 |
callback | AsyncCallback<string> | 是 | 回調函數。當光標后固定長度的文本獲取成功,err為undefined,data為獲取到的文本;否則為錯誤對象。 |
示例:
- let length = 1;
- textInputClient.getBackward(length, (err, text) => {
- if (err !== undefined) {
- console.error('Failed to getBackward: ' + JSON.stringify(err));
- return;
- }
- console.log('Succeeded in getting borward, text: ' + text);
- });
getBackward(length:number): Promise<string>
獲取光標后固定長度的文本。使用promise異步回調。
從API version 8開始支持,API version 9開始廢棄, 建議使用getBackward替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
length | number | 是 | 文本長度。 |
返回值:
類型 | 說明 |
---|---|
Promise<string> | Promise對象,返回光標后固定長度的文本。 |
示例:
- let length = 1;
- textInputClient.getBackward(length).then((text) => {
- console.info('Succeeded in getting backward: ' + JSON.stringify(text));
- }).catch((err) => {
- console.error('Failed to getBackward: ' + JSON.stringify(err));
- });
deleteForward(length:number, callback: AsyncCallback<boolean>): void
刪除光標前固定長度的文本。使用callback異步回調。
從API version 8開始支持,API version 9開始廢棄, 建議使用deleteForward替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
length | number | 是 | 文本長度。 |
callback | AsyncCallback<boolean> | 是 | 回調函數。當光標前固定長度的文本刪除成功,err為undefined,data為true;否則為錯誤對象。 |
示例:
- let length = 1;
- textInputClient.deleteForward(length, (err, result) => {
- if (err !== undefined) {
- console.error('Failed to deleteForward: ' + JSON.stringify(err));
- return;
- }
- if (result) {
- console.info('Succeeded in deleting forward. ');
- } else {
- console.error('Failed to deleteForward. ');
- }
- });
deleteForward(length:number): Promise<boolean>
刪除光標前固定長度的文本。使用promise異步回調。
從API version 8開始支持,API version 9開始廢棄, 建議使用deleteForward替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
length | number | 是 | 文本長度。 |
返回值:
類型 | 說明 |
---|---|
Promise<boolean> | Promise對象。返回true表示刪除光標前固定長度的文本成功;返回false表示刪除光標前固定長度的文本失敗。 |
示例:
- let length = 1;
- textInputClient.deleteForward(length).then((result) => {
- if (result) {
- console.info('Succeeded in deleting forward. ');
- } else {
- console.error('Failed to delete forward. ');
- }
- }).catch((err) => {
- console.error('Failed to delete forward: ' + JSON.stringify(err));
- });
deleteBackward(length:number, callback: AsyncCallback<boolean>): void
刪除光標后固定長度的文本。使用callback異步回調。
從API version 8開始支持,API version 9開始廢棄, 建議使用deleteBackward替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
length | number | 是 | 文本長度。 |
callback | AsyncCallback<boolean> | 是 | 回調函數。當光標后固定長度的文本刪除成功,err為undefined,data為true;否則為錯誤對象。 |
示例:
- let length = 1;
- textInputClient.deleteBackward(length, (err, result) => {
- if (err !== undefined) {
- console.error('Failed to delete backward: ' + JSON.stringify(err));
- return;
- }
- if (result) {
- console.info('Succeeded in deleting backward. ');
- } else {
- console.error('Failed to deleteBackward. ');
- }
- });
deleteBackward(length:number): Promise<boolean>
刪除光標后固定長度的文本。使用callback異步回調。
從API version 8開始支持,API version 9開始廢棄, 建議使用deleteBackward替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
length | number | 是 | 文本長度。 |
返回值:
類型 | 說明 |
---|---|
Promise<boolean> | Promise對象。返回true表示刪除光標后固定長度的文本成功;返回false表示刪除光標后固定長度的文本失敗。 |
示例:
- let length = 1;
- textInputClient.deleteBackward(length).then((result) => {
- if (result) {
- console.info('Succeeded in deleting backward. ');
- } else {
- console.error('Failed to deleteBackward. ');
- }
- }).catch((err) => {
- console.error('Failed to deleteBackward: ' + JSON.stringify(err));
- });
sendKeyFunction(action: number, callback: AsyncCallback<boolean>): void
發(fā)送功能鍵。使用callback異步回調。
從API version 8開始支持,API version 9開始廢棄, 建議使用sendKeyFunction替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
action | number | 是 | 功能鍵鍵值。 當值為0時,表示無效按鍵; 當值為1時,表示確認鍵(即回車鍵)。 |
callback | AsyncCallback<boolean> | 是 | 回調函數。當功能鍵發(fā)送成功,err為undefined,data為true;否則為錯誤對象。 |
示例:
- let action = 1;
- textInputClient.sendKeyFunction(action, (err, result) => {
- if (err !== undefined) {
- console.error('Failed to sendKeyFunction: ' + JSON.stringify(err));
- return;
- }
- if (result) {
- console.info('Succeeded in sending key function. ');
- } else {
- console.error('Failed to sendKeyFunction. ');
- }
- });
sendKeyFunction(action: number): Promise<boolean>
發(fā)送功能鍵。使用promise異步回調。
從API version 8開始支持,API version 9開始廢棄, 建議使用sendKeyFunction替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
action | number | 是 | 功能鍵鍵值。 當值為0時,表示無效按鍵; 當值為1時,表示確認鍵(即回車鍵)。 |
返回值:
類型 | 說明 |
---|---|
Promise<boolean> | Promise對象。返回true表示發(fā)送功能鍵成功;返回false表示發(fā)送功能鍵失敗。 |
示例:
- let action = 1;
- textInputClient.sendKeyFunction(action).then((result) => {
- if (result) {
- console.info('Succeeded in sending key function. ');
- } else {
- console.error('Failed to sendKeyFunction. ');
- }
- }).catch((err) => {
- console.error('Failed to sendKeyFunction:' + JSON.stringify(err));
- });
insertText(text:string, callback: AsyncCallback<boolean>): void
插入文本。使用callback異步回調。
從API version 8開始支持,API version 9開始廢棄, 建議使用insertText替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
text | string | 是 | 文本。 |
callback | AsyncCallback<boolean> | 是 | 回調函數。當文本插入成功,err為undefined,data為true;否則為錯誤對象。 |
示例:
- textInputClient.insertText('test', (err, result) => {
- if (err !== undefined) {
- console.error('Failed to insertText: ' + JSON.stringify(err));
- return;
- }
- if (result) {
- console.info('Succeeded in inserting text. ');
- } else {
- console.error('Failed to insertText. ');
- }
- });
insertText(text:string): Promise<boolean>
插入文本。使用promise異步回調。
從API version 8開始支持,API version 9開始廢棄, 建議使用insertText替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
text | string | 是 | 文本。 |
返回值:
類型 | 說明 |
---|---|
Promise<boolean> | Promise對象。返回true表示插入文本成功;返回false表示插入文本失敗。 |
示例:
- textInputClient.insertText('test').then((result) => {
- if (result) {
- console.info('Succeeded in inserting text. ');
- } else {
- console.error('Failed to insertText. ');
- }
- }).catch((err) => {
- console.error('Failed to insertText: ' + JSON.stringify(err));
- });
getEditorAttribute(callback: AsyncCallback<EditorAttribute>): void
獲取編輯框屬性值。使用callback異步回調。
從API version 8開始支持,API version 9開始廢棄, 建議使用getEditorAttribute替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
callback | AsyncCallback<EditorAttribute> | 是 | 回調函數。當編輯框的屬性值獲取成功,err為undefined,data為編輯框屬性值;否則為錯誤對象。 |
示例:
- textInputClient.getEditorAttribute((err, editorAttribute) => {
- if (err !== undefined) {
- console.error('Failed to getEditorAttribute: ' + JSON.stringify(err));
- return;
- }
- console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern));
- console.log('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType));
- });
getEditorAttribute(): Promise<EditorAttribute>
獲取編輯框屬性值。使用promise異步回調。
從API version 8開始支持,API version 9開始廢棄, 建議使用getEditorAttribute替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
返回值:
類型 | 說明 |
---|---|
Promise<EditorAttribute> | Promise對象,返回編輯框屬性值。 |
示例:
- textInputClient.getEditorAttribute().then((editorAttribute) => {
- console.info('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern));
- console.info('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType));
- }).catch((err) => {
- console.error('Failed to getEditorAttribute: ' + JSON.stringify(err));
- });
更多建議: