本模塊面向輸入法應(yīng)用(包括系統(tǒng)輸入法應(yīng)用、三方輸入法應(yīng)用),為輸入法應(yīng)用提供能力,功能包括:創(chuàng)建軟鍵盤窗口、插入/刪除字符、選中文本、物理鍵盤按鍵事件監(jiān)聽等。
本模塊首批接口從API version 8開始支持。后續(xù)版本的新增接口,采用上角標(biāo)單獨(dú)標(biāo)記接口的起始版本。
功能鍵常量值、編輯框常量值及光標(biāo)常量值。
系統(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 | “下一個(gè)”功能鍵。 |
ENTER_KEY_TYPE_DONE | number | 6 | “回車”功能鍵。 |
ENTER_KEY_TYPE_PREVIOUS | number | 7 | “前一個(gè)”功能鍵。 |
PATTERN_NULL | number | -1 | 無特殊性編輯框。 |
PATTERN_TEXT | number | 0 | 文本編輯框。 |
PATTERN_NUMBER | number | 2 | 數(shù)字編輯框。 |
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 | 編輯框?yàn)閱涡小?/p> |
DISPLAY_MODE_PART | number | 0 | 編輯框顯示為半屏。 |
DISPLAY_MODE_FULL | number | 1 | 編輯框顯示為全屏。 |
CURSOR_UP9+ | number | 1 | 光標(biāo)上移。 |
CURSOR_DOWN9+ | number | 2 | 光標(biāo)下移。 |
CURSOR_LEFT9+ | number | 3 | 光標(biāo)左移。 |
CURSOR_RIGHT9+ | number | 4 | 光標(biāo)右移。 |
WINDOW_TYPE_INPUT_METHOD_FLOAT9+ | number | 2105 | 輸入法應(yīng)用窗口風(fēng)格標(biāo)識。 |
getInputMethodAbility(): InputMethodAbility
獲取服務(wù)端實(shí)例。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
返回值:
類型 | 說明 |
---|---|
服務(wù)端實(shí)例。 |
示例:
- let InputMethodAbility = inputMethodEngine.getInputMethodAbility();
getKeyboardDelegate(): KeyboardDelegate
獲取客戶端監(jiān)聽實(shí)例。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
返回值:
類型 | 說明 |
---|---|
客戶端監(jiān)聽實(shí)例。 |
示例:
- let KeyboardDelegate = inputMethodEngine.getKeyboardDelegate();
getInputMethodEngine(): InputMethodEngine
獲取服務(wù)端實(shí)例。
從API version 8開始支持,API version 9開始廢棄, 建議使用getInputMethodAbility()替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
返回值:
類型 | 說明 |
---|---|
服務(wù)端實(shí)例。 |
示例:
- let InputMethodEngine = inputMethodEngine.getInputMethodEngine();
createKeyboardDelegate(): KeyboardDelegate
獲取客戶端監(jiān)聽實(shí)例。
從API version 8開始支持,API version 9開始廢棄, 建議使用getKeyboardDelegate()替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
返回值:
類型 | 說明 |
---|---|
客戶端監(jiān)聽實(shí)例。 |
示例:
- let keyboardDelegate = inputMethodEngine.createKeyboardDelegate();
下列API示例中都需使用getInputMethodEngine回調(diào)獲取到InputMethodEngine實(shí)例,再通過此實(shí)例調(diào)用對應(yīng)方法。
on(type: 'inputStart', callback: (kbController: KeyboardController, textInputClient: TextInputClient) => void): void
訂閱輸入法綁定成功事件。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 設(shè)置監(jiān)聽類型。 - type為‘inputStart’時(shí)表示訂閱輸入法綁定。 |
callback | (kbController: KeyboardController, textInputClient: TextInputClient) => void | 是 | 回調(diào)函數(shù),返回訂閱輸入法的KeyboardController和TextInputClient實(shí)例。 |
示例:
- 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
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 設(shè)置監(jiān)聽類型。 - type為‘inputStart’時(shí)表示訂閱輸入法綁定。 |
callback | (kbController: KeyboardController, textInputClient: TextInputClient) => void | 否 | 回調(diào)函數(shù),返回取消訂閱的KeyboardController和TextInputClient實(shí)例。 |
示例:
- inputMethodEngine.getInputMethodEngine().off('inputStart', (kbController, textInputClient) => {
- console.log('delete inputStart notification.');
- });
on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void
訂閱輸入法事件。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 設(shè)置監(jiān)聽類型。 - type為'keyboardShow',表示訂閱輸入法顯示。 - type為'keyboardHide',表示訂閱輸入法隱藏。 |
callback | () => void | 是 | 回調(diào)函數(shù)。 |
示例:
- inputMethodEngine.getInputMethodEngine().on('keyboardShow', () => {
- console.log('inputMethodEngine keyboardShow.');
- });
- inputMethodEngine.getInputMethodEngine().on('keyboardHide', () => {
- console.log('inputMethodEngine keyboardHide.');
- });
off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void
取消訂閱輸入法事件。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 設(shè)置監(jiān)聽類型。 - type為'keyboardShow',表示訂閱輸入法顯示。 - type為'keyboardHide',表示訂閱輸入法隱藏。 |
callback | () => void | 否 | 回調(diào)函數(shù)。 |
示例:
- inputMethodEngine.getInputMethodEngine().off('keyboardShow');
- inputMethodEngine.getInputMethodEngine().off('keyboardHide');
下列API示例中都需使用getInputMethodAbility回調(diào)獲取到InputMethodAbility實(shí)例,再通過此實(shí)例調(diào)用對應(yīng)方法。
on(type: 'inputStart', callback: (kbController: KeyboardController, inputClient: InputClient) => void): void
訂閱輸入法綁定成功事件。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 設(shè)置監(jiān)聽類型。 - type為‘inputStart’時(shí)表示訂閱輸入法綁定。 |
callback | (kbController: KeyboardController, inputClient: InputClient) => void | 是 | 回調(diào)函數(shù),返回輸入法操作相關(guān)實(shí)例。 |
示例:
- inputMethodEngine.getInputMethodAbility().on('inputStart', (kbController, client) => {
- let keyboardController = kbController;
- let inputClient = client;
- });
off(type: 'inputStart', callback?: (kbController: KeyboardController, inputClient: InputClient) => void): void
取消訂閱輸入法綁定成功事件。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 設(shè)置監(jiān)聽類型。 - type為‘inputStart’時(shí)表示訂閱輸入法綁定。 |
callback | (kbController: KeyboardController, inputClient: InputClient) => void | 否 | 回調(diào)函數(shù),返回輸入法操作相關(guān)實(shí)例。 |
示例:
- inputMethodEngine.getInputMethodAbility().off('inputStart');
on(type: 'inputStop', callback: () => void): void
訂閱停止輸入法應(yīng)用事件。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 設(shè)置監(jiān)聽類型。 - type為‘inputStop’時(shí)表示訂閱停止輸入法應(yīng)用事件。 |
callback | () => void | 是 | 回調(diào)函數(shù)。 |
示例:
- inputMethodEngine.getInputMethodAbility().on('inputStop', () => {
- console.log('inputMethodAbility inputStop');
- });
off(type: 'inputStop', callback: () => void): void
取消訂閱停止輸入法應(yīng)用事件。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 設(shè)置監(jiān)聽類型。 - type為‘inputStop’時(shí)表示訂閱停止輸入法應(yīng)用事件。 |
callback | () => void | 是 | 回調(diào)函數(shù)。 |
示例:
- inputMethodEngine.getInputMethodAbility().off('inputStop', () => {
- console.log('inputMethodAbility delete inputStop notification.');
- });
on(type: 'setCallingWindow', callback: (wid: number) => void): void
訂閱設(shè)置調(diào)用窗口事件。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 設(shè)置監(jiān)聽類型。 - type為‘setCallingWindow’時(shí)表示訂閱設(shè)置調(diào)用窗口事件。 |
callback | (wid: number) => void | 是 | 回調(diào)函數(shù),返回調(diào)用方window id。 |
示例:
- inputMethodEngine.getInputMethodAbility().on('setCallingWindow', (wid) => {
- console.log('inputMethodAbility setCallingWindow');
- });
off(type: 'setCallingWindow', callback: (wid:number) => void): void
取消訂閱設(shè)置調(diào)用窗口事件。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 設(shè)置監(jiān)聽類型。 - type為‘setCallingWindow’時(shí)表示訂閱設(shè)置調(diào)用窗口事件。 |
callback | (wid:number) => void | 是 | 回調(diào)函數(shù),返回調(diào)用方window id。 |
示例:
- inputMethodEngine.getInputMethodAbility().off('setCallingWindow', () => {
- console.log('inputMethodAbility delete setCallingWindow notification.');
- });
on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void
訂閱輸入法事件。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 設(shè)置監(jiān)聽類型。 - type為'keyboardShow',表示訂閱顯示鍵盤事件。 - type為'keyboardHide',表示訂閱隱藏鍵盤事件。 |
callback | () => void | 是 | 回調(diào)函數(shù)。 |
示例:
- inputMethodEngine.getInputMethodAbility().on('keyboardShow', () => {
- console.log('InputMethodAbility keyboardShow.');
- });
- inputMethodEngine.getInputMethodAbility().on('keyboardHide', () => {
- console.log('InputMethodAbility keyboardHide.');
- });
off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void
取消訂閱輸入法事件。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 設(shè)置監(jiān)聽類型。 - type為'keyboardShow',表示取消訂閱顯示鍵盤事件。 - type為'keyboardHide',表示取消訂閱隱藏鍵盤事件。 |
callback | () => void | 否 | 回調(diào)函數(shù)。 |
示例:
- 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
訂閱設(shè)置輸入法子類型事件。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 設(shè)置監(jiān)聽類型。 - type為'setSubtype',表示訂閱輸入法子類型的設(shè)置事件。 |
callback | (inputMethodSubtype: InputMethodSubtype) => void | 是 | 回調(diào)函數(shù),返回設(shè)置的輸入法子類型。 |
示例:
- inputMethodEngine.getInputMethodAbility().on('setSubtype', (inputMethodSubtype) => {
- console.log('InputMethodAbility setSubtype.');
- });
off(type: 'setSubtype', callback?: (inputMethodSubtype: InputMethodSubtype) => void): void
取消訂閱輸入法子類型事件。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 設(shè)置監(jiān)聽類型。 - type為'setSubtype',表示取消訂閱輸入法子類型的設(shè)置事件。 |
callback | (inputMethodSubtype: InputMethodSubtype) => void | 否 | 回調(diào)函數(shù),返回設(shè)置的輸入法子類型。 |
示例:
- inputMethodEngine.getInputMethodAbility().off('setSubtype', () => {
- console.log('InputMethodAbility delete setSubtype notification.');
- });
下列API示例中都需使用getKeyboardDelegate回調(diào)獲取到KeyboardDelegate實(shí)例,再通過此實(shí)例調(diào)用對應(yīng)方法。
on(type: 'keyDown'|'keyUp', callback: (event: KeyEvent) => boolean): void
訂閱硬鍵盤(即物理鍵盤)事件。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 設(shè)置監(jiān)聽類型。 - type為'keyDown',表示訂閱硬鍵盤按下事件。 - type為'keyUp',表示訂閱硬鍵盤抬起事件。 |
callback | (event: KeyEvent) => boolean | 是 | 回調(diào)函數(shù),返回按鍵信息。 |
示例:
- 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異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 設(shè)置監(jiān)聽類型。 - type為'keyDown',表示取消訂閱硬鍵盤按下事件。 - type為'keyUp',表示取消訂閱硬鍵盤抬起事件。 |
callback | (event: KeyEvent) => boolean | 否 | 回調(diào)函數(shù),返回按鍵信息。 |
示例:
- 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
訂閱光標(biāo)變化事件。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 光標(biāo)變化事件。 - type為’cursorContextChange‘時(shí),表示訂閱光標(biāo)變化事件。 |
callback | (x: number, y: number, height: number) => void | 是 | 回調(diào)函數(shù),返回光標(biāo)信息。 - x為光標(biāo)上端的的x坐標(biāo)值。 - y為光標(biāo)上端的y坐標(biāo)值。 - height為光標(biāo)的高度值。 |
示例:
- 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
取消訂閱光標(biāo)變化事件。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 光標(biāo)變化事件。 - type為’cursorContextChange‘時(shí),表示光標(biāo)變化。 |
callback | (x: number, y:number, height:number) => void | 否 | 回調(diào)函數(shù),返回光標(biāo)信息。 - x為光標(biāo)上端的的x坐標(biāo)值。 - y為光標(biāo)上端的y坐標(biāo)值。 - height為光標(biāo)的高度值。 |
示例:
- 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異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 文本選擇變化事件。 - type為’selectionChange‘時(shí),表示選擇文本變化。 |
callback | (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void | 是 | 回調(diào)函數(shù),返回文本選擇信息。 - oldBegin為變化之前被選中文本的起始下標(biāo)。 - oldEnd為變化之前被選中文本的終止下標(biāo)。 - newBegin為變化之后被選中文本的起始下標(biāo)。 - newEnd為變化之后被選中文本的終止下標(biāo)。 |
示例:
- 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異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 文本選擇變化事件。 - type為’selectionChange‘時(shí),表示選擇文本變化。 |
callback | (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void | 否 | 回調(diào)函數(shù),返回文本選擇信息。 - oldBegin為變化之前被選中文本的起始下標(biāo)。 - oldEnd為變化之前被選中文本的終止下標(biāo)。 - newBegin為變化之后被選中文本的起始下標(biāo)。 - newEnd為變化之后被選中文本的終止下標(biāo)。 |
示例:
- inputMethodEngine.getKeyboardDelegate().off('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => {
- console.log('delete selectionChange notification.');
- });
on(type: 'textChange', callback: (text: string) => void): void
訂閱文本變化事件。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 文本變化事件。 - type為’textChange‘時(shí),表示訂閱文本變化事件。 |
callback | (text: string) => void | 是 | 回調(diào)函數(shù),返回訂閱的文本內(nèi)容。 |
示例:
- inputMethodEngine.getKeyboardDelegate().on('textChange', (text) => {
- console.log('inputMethodEngine textChange. text:' + text);
- });
off(type: 'textChange', callback?: (text: string) => void): void
取消訂閱文本變化事件。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
type | string | 是 | 文本變化事件。 - type為’textChange‘時(shí),表示取消訂閱文本變化事件。 |
callback | (text: string) => void | 否 | 回調(diào)函數(shù),返回取消訂閱的文本內(nèi)容。 |
示例:
- inputMethodEngine.getKeyboardDelegate().off('textChange', (text) => {
- console.log('delete textChange notification. text:' + text);
- });
下列API示例中都需使用on('inputStart')回調(diào)獲取到KeyboardController實(shí)例,再通過此實(shí)例調(diào)用對應(yīng)方法。
hide(callback: AsyncCallback<void>): void
隱藏輸入法。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。當(dāng)輸入法隱藏成功,err為undefined,否則為錯(cuò)誤對象。 |
錯(cuò)誤碼:
以下錯(cuò)誤碼的詳細(xì)介紹請參見輸入法框架錯(cuò)誤碼。
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
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異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對象。 |
錯(cuò)誤碼:
以下錯(cuò)誤碼的詳細(xì)介紹請參見輸入法框架錯(cuò)誤碼。
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
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異步回調(diào)。
從API version 8開始支持,API version 9開始廢棄, 建議使用hide替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。當(dāng)輸入法隱藏成功,err為undefined,否則為錯(cuò)誤對象。 |
示例:
- 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異步回調(diào)。
從API version 8開始支持,API version 9開始廢棄, 建議使用hide替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對象。 |
示例:
- keyboardController.hideKeyboard().then(() => {
- console.info('Succeeded in hiding keyboard.');
- }).catch((err) => {
- console.info('Failed to hide Keyboard: ' + JSON.stringify(err));
- });
下列API示例中都需使用on('inputStart')回調(diào)獲取到InputClient實(shí)例,再通過此實(shí)例調(diào)用對應(yīng)方法。
sendKeyFunction(action:number, callback: AsyncCallback<boolean>): void
發(fā)送功能鍵。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
action | number | 是 | 功能鍵鍵值。 當(dāng)值為0時(shí),表示無效按鍵; 當(dāng)值為1時(shí),表示確認(rèn)鍵(即回車鍵)。 |
callback | AsyncCallback<boolean> | 是 | 回調(diào)函數(shù)。當(dāng)功能鍵發(fā)送成功,err為undefined,data為true;否則為錯(cuò)誤對象。 |
錯(cuò)誤碼:
以下錯(cuò)誤碼的詳細(xì)介紹請參見輸入法框架錯(cuò)誤碼。
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
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異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
action | number | 是 | 功能鍵鍵值。 當(dāng)值為0時(shí),表示無效按鍵; 當(dāng)值為1時(shí),表示確認(rèn)鍵(即回車鍵)。 |
返回值:
類型 | 說明 |
---|---|
Promise<boolean> | Promise對象。返回true表示功能鍵發(fā)送成功;返回false表示功能鍵發(fā)送失敗。 |
錯(cuò)誤碼:
以下錯(cuò)誤碼的詳細(xì)介紹請參見輸入法框架錯(cuò)誤碼。
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
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
獲取光標(biāo)前固定長度的文本。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
length | number | 是 | 文本長度。 |
callback | AsyncCallback<string> | 是 | 回調(diào)函數(shù)。當(dāng)光標(biāo)前固定長度的文本獲取成功,err為undefined,data為獲取到的文本;否則為錯(cuò)誤對象。 |
錯(cuò)誤碼:
以下錯(cuò)誤碼的詳細(xì)介紹請參見輸入法框架錯(cuò)誤碼。
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
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>
獲取光標(biāo)前固定長度的文本。使用promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
length | number | 是 | 文本長度。 |
返回值:
類型 | 說明 |
---|---|
Promise<string> | Promise對象,返回光標(biāo)前固定長度的文本。 |
錯(cuò)誤碼:
以下錯(cuò)誤碼的詳細(xì)介紹請參見輸入法框架錯(cuò)誤碼。
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
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
獲取光標(biāo)后固定長度的文本。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
length | number | 是 | 文本長度。 |
callback | AsyncCallback<string> | 是 | 回調(diào)函數(shù)。當(dāng)光標(biāo)后固定長度的文本獲取成功,err為undefined,data為獲取到的文本;否則為錯(cuò)誤對象。 |
錯(cuò)誤碼:
以下錯(cuò)誤碼的詳細(xì)介紹請參見輸入法框架錯(cuò)誤碼。
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
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>
獲取光標(biāo)后固定長度的文本。使用promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
length | number | 是 | 文本長度。 |
返回值:
類型 | 說明 |
---|---|
Promise<string> | Promise對象,返回光標(biāo)后固定長度的文本。 |
錯(cuò)誤碼:
以下錯(cuò)誤碼的詳細(xì)介紹請參見輸入法框架錯(cuò)誤碼。
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
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
刪除光標(biāo)前固定長度的文本。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
length | number | 是 | 文本長度。 |
callback | AsyncCallback<boolean> | 是 | 回調(diào)函數(shù)。當(dāng)光標(biāo)前固定長度的文本刪除成功,err為undefined,data為true;否則為錯(cuò)誤對象。 |
錯(cuò)誤碼:
以下錯(cuò)誤碼的詳細(xì)介紹請參見輸入法框架錯(cuò)誤碼。
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
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>
刪除光標(biāo)前固定長度的文本。使用promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
length | number | 是 | 文本長度。 |
返回值:
類型 | 說明 |
---|---|
Promise<boolean> | Promise對象。返回true表示刪除光標(biāo)前固定長度的文本成功;返回false表示刪除光標(biāo)前固定長度的文本失敗。 |
錯(cuò)誤碼:
以下錯(cuò)誤碼的詳細(xì)介紹請參見輸入法框架錯(cuò)誤碼。
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
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
刪除光標(biāo)后固定長度的文本。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
length | number | 是 | 文本長度。 |
callback | AsyncCallback<boolean> | 是 | 回調(diào)函數(shù)。當(dāng)光標(biāo)后固定長度的文本刪除成功,err為undefined,data為true;否則為錯(cuò)誤對象。 |
錯(cuò)誤碼:
以下錯(cuò)誤碼的詳細(xì)介紹請參見輸入法框架錯(cuò)誤碼。
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
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>
刪除光標(biāo)后固定長度的文本。使用promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
length | number | 是 | 文本長度。 |
返回值:
類型 | 說明 |
---|---|
Promise<boolean> | Promise對象。返回true表示刪除光標(biāo)后固定長度的文本成功;返回false表示刪除光標(biāo)后固定長度的文本失敗。 |
錯(cuò)誤碼:
以下錯(cuò)誤碼的詳細(xì)介紹請參見輸入法框架錯(cuò)誤碼。
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
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異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
text | string | 是 | 文本。 |
callback | AsyncCallback<boolean> | 是 | 回調(diào)函數(shù)。當(dāng)文本插入成功,err為undefined,data為true;否則為錯(cuò)誤對象。 |
錯(cuò)誤碼:
以下錯(cuò)誤碼的詳細(xì)介紹請參見輸入法框架錯(cuò)誤碼。
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
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異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
text | string | 是 | 文本。 |
返回值:
類型 | 說明 |
---|---|
Promise<boolean> | Promise對象。返回true表示插入文本成功;返回false表示插入文本失敗。 |
錯(cuò)誤碼:
以下錯(cuò)誤碼的詳細(xì)介紹請參見輸入法框架錯(cuò)誤碼。
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
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
獲取編輯框?qū)傩灾?。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
callback | AsyncCallback<EditorAttribute> | 是 | 回調(diào)函數(shù)。當(dāng)編輯框?qū)傩灾但@取成功,err為undefined,data為編輯框?qū)傩灾?;否則為錯(cuò)誤對象。 |
錯(cuò)誤碼:
以下錯(cuò)誤碼的詳細(xì)介紹請參見輸入法框架錯(cuò)誤碼。
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
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>
獲取編輯框?qū)傩灾怠J褂胮romise異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
返回值:
類型 | 說明 |
---|---|
Promise<EditorAttribute> | Promise對象,返回編輯框?qū)傩灾怠?/p> |
錯(cuò)誤碼:
以下錯(cuò)誤碼的詳細(xì)介紹請參見輸入法框架錯(cuò)誤碼。
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
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
移動光標(biāo)。使用callback異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
direction | number | 是 | 光標(biāo)移動方向。 |
callback | AsyncCallback<void> | 是 | 回調(diào)函數(shù)。當(dāng)光標(biāo)移動成功,err為undefined,否則為錯(cuò)誤對象。 |
錯(cuò)誤碼:
以下錯(cuò)誤碼的詳細(xì)介紹請參見輸入法框架錯(cuò)誤碼。
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
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>
移動光標(biāo)。使用promise異步回調(diào)。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
direction | number | 是 | 光標(biāo)移動方向。 |
返回值:
類型 | 說明 |
---|---|
Promise<void> | 無返回結(jié)果的Promise對象。 |
錯(cuò)誤碼:
以下錯(cuò)誤碼的詳細(xì)介紹請參見輸入法框架錯(cuò)誤碼。
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
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));
- }
編輯框?qū)傩灾怠?/p>
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
名稱 | 類型 | 可讀 | 可寫 | 說明 |
---|---|---|---|---|
enterKeyType | number | 是 | 否 | 編輯框的功能屬性。 |
inputPattern | number | 是 | 否 | 編輯框的文本屬性。 |
按鍵屬性值。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
名稱 | 類型 | 可讀 | 可寫 | 說明 |
---|---|---|---|---|
keyCode | number | 是 | 否 | 按鍵的鍵值。鍵碼值說明參考 KeyCode。 |
keyAction | number | 是 | 否 | 按鍵的狀態(tài)。 當(dāng)值為2時(shí),表示按下事件; 當(dāng)值為3時(shí),表示抬起事件。 |
從API version 8開始支持,API version 9開始廢棄, 建議使用InputClient替代。
下列API示例中都需使用on('inputStart')回調(diào)獲取到TextInputClient實(shí)例,再通過此實(shí)例調(diào)用對應(yīng)方法。
getForward(length:number, callback: AsyncCallback<string>): void
獲取光標(biāo)前固定長度的文本。使用callback異步回調(diào)。
從API version 8開始支持,API version 9開始廢棄, 建議使用getForward替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
length | number | 是 | 文本長度。 |
callback | AsyncCallback<string> | 是 | 回調(diào)函數(shù)。當(dāng)光標(biāo)前固定長度的文本獲取成功,err為undefined,data為獲取到的文本;否則為錯(cuò)誤對象。 |
示例:
- 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>
獲取光標(biāo)前固定長度的文本。使用promise異步回調(diào)。
從API version 8開始支持,API version 9開始廢棄, 建議使用getForward替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
length | number | 是 | 文本長度。 |
返回值:
類型 | 說明 |
---|---|
Promise<string> | Promise對象,返回光標(biāo)前固定長度的文本。 |
示例:
- 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
獲取光標(biāo)后固定長度的文本。使用callback異步回調(diào)。
從API version 8開始支持,API version 9開始廢棄, 建議使用getBackward替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
length | number | 是 | 文本長度。 |
callback | AsyncCallback<string> | 是 | 回調(diào)函數(shù)。當(dāng)光標(biāo)后固定長度的文本獲取成功,err為undefined,data為獲取到的文本;否則為錯(cuò)誤對象。 |
示例:
- 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>
獲取光標(biāo)后固定長度的文本。使用promise異步回調(diào)。
從API version 8開始支持,API version 9開始廢棄, 建議使用getBackward替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
length | number | 是 | 文本長度。 |
返回值:
類型 | 說明 |
---|---|
Promise<string> | Promise對象,返回光標(biāo)后固定長度的文本。 |
示例:
- 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
刪除光標(biāo)前固定長度的文本。使用callback異步回調(diào)。
從API version 8開始支持,API version 9開始廢棄, 建議使用deleteForward替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
length | number | 是 | 文本長度。 |
callback | AsyncCallback<boolean> | 是 | 回調(diào)函數(shù)。當(dāng)光標(biāo)前固定長度的文本刪除成功,err為undefined,data為true;否則為錯(cuò)誤對象。 |
示例:
- 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>
刪除光標(biāo)前固定長度的文本。使用promise異步回調(diào)。
從API version 8開始支持,API version 9開始廢棄, 建議使用deleteForward替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
length | number | 是 | 文本長度。 |
返回值:
類型 | 說明 |
---|---|
Promise<boolean> | Promise對象。返回true表示刪除光標(biāo)前固定長度的文本成功;返回false表示刪除光標(biāo)前固定長度的文本失敗。 |
示例:
- 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
刪除光標(biāo)后固定長度的文本。使用callback異步回調(diào)。
從API version 8開始支持,API version 9開始廢棄, 建議使用deleteBackward替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
length | number | 是 | 文本長度。 |
callback | AsyncCallback<boolean> | 是 | 回調(diào)函數(shù)。當(dāng)光標(biāo)后固定長度的文本刪除成功,err為undefined,data為true;否則為錯(cuò)誤對象。 |
示例:
- 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>
刪除光標(biāo)后固定長度的文本。使用callback異步回調(diào)。
從API version 8開始支持,API version 9開始廢棄, 建議使用deleteBackward替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
length | number | 是 | 文本長度。 |
返回值:
類型 | 說明 |
---|---|
Promise<boolean> | Promise對象。返回true表示刪除光標(biāo)后固定長度的文本成功;返回false表示刪除光標(biāo)后固定長度的文本失敗。 |
示例:
- 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異步回調(diào)。
從API version 8開始支持,API version 9開始廢棄, 建議使用sendKeyFunction替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
action | number | 是 | 功能鍵鍵值。 當(dāng)值為0時(shí),表示無效按鍵; 當(dāng)值為1時(shí),表示確認(rèn)鍵(即回車鍵)。 |
callback | AsyncCallback<boolean> | 是 | 回調(diào)函數(shù)。當(dāng)功能鍵發(fā)送成功,err為undefined,data為true;否則為錯(cuò)誤對象。 |
示例:
- 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異步回調(diào)。
從API version 8開始支持,API version 9開始廢棄, 建議使用sendKeyFunction替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
action | number | 是 | 功能鍵鍵值。 當(dāng)值為0時(shí),表示無效按鍵; 當(dāng)值為1時(shí),表示確認(rèn)鍵(即回車鍵)。 |
返回值:
類型 | 說明 |
---|---|
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異步回調(diào)。
從API version 8開始支持,API version 9開始廢棄, 建議使用insertText替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
text | string | 是 | 文本。 |
callback | AsyncCallback<boolean> | 是 | 回調(diào)函數(shù)。當(dāng)文本插入成功,err為undefined,data為true;否則為錯(cuò)誤對象。 |
示例:
- 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異步回調(diào)。
從API version 8開始支持,API version 9開始廢棄, 建議使用insertText替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
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
獲取編輯框?qū)傩灾?。使用callback異步回調(diào)。
從API version 8開始支持,API version 9開始廢棄, 建議使用getEditorAttribute替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
callback | AsyncCallback<EditorAttribute> | 是 | 回調(diào)函數(shù)。當(dāng)編輯框的屬性值獲取成功,err為undefined,data為編輯框?qū)傩灾?;否則為錯(cuò)誤對象。 |
示例:
- 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>
獲取編輯框?qū)傩灾?。使用promise異步回調(diào)。
從API version 8開始支持,API version 9開始廢棄, 建議使用getEditorAttribute替代。
系統(tǒng)能力: SystemCapability.MiscServices.InputMethodFramework
返回值:
類型 | 說明 |
---|---|
Promise<EditorAttribute> | Promise對象,返回編輯框?qū)傩灾怠?/p> |
示例:
- 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));
- });
更多建議: