當前位置: 首頁>>代碼示例>>Java>>正文


Java InputConnection.sendKeyEvent方法代碼示例

本文整理匯總了Java中android.view.inputmethod.InputConnection.sendKeyEvent方法的典型用法代碼示例。如果您正苦於以下問題:Java InputConnection.sendKeyEvent方法的具體用法?Java InputConnection.sendKeyEvent怎麽用?Java InputConnection.sendKeyEvent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.view.inputmethod.InputConnection的用法示例。


在下文中一共展示了InputConnection.sendKeyEvent方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onKey

import android.view.inputmethod.InputConnection; //導入方法依賴的package包/類
@Override
  public void onKey(int primaryCode, int[] keyCodes) {
      InputConnection ic = getCurrentInputConnection() ;
      playclick(primaryCode);
      switch (primaryCode) {
          case Keyboard.KEYCODE_DELETE:
              ic.deleteSurroundingText(1, 0);
              break;
          case Keyboard.KEYCODE_SHIFT:
              caps = !caps;
              keyboard.setShifted(caps);
              kv.invalidateAllKeys();
              break;
          case Keyboard.KEYCODE_DONE:
              ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER));
              break;
          default:
              char code = (char) primaryCode;
              if(Character.isLetter(code) && caps) {
                  code = Character.toUpperCase(code);
              }

              ic.commitText(String.valueOf(code), 1);
break;
      }
  }
 
開發者ID:zhaofengli,項目名稱:airboard,代碼行數:27,代碼來源:AirBoard.java

示例2: onKey

import android.view.inputmethod.InputConnection; //導入方法依賴的package包/類
@Override
public void onKey(int primaryCode, int[] ints) {
    Log.d(TAG, "onKey " + primaryCode);
    InputConnection ic = getCurrentInputConnection();
    playClick(primaryCode);

    switch (primaryCode) {
        case Keyboard.KEYCODE_DELETE:
            ic.deleteSurroundingText(1, 0);
            break;
        case Keyboard.KEYCODE_SHIFT:
            handleShift();
            break;
        case Keyboard.KEYCODE_DONE:
            ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER));
            break;
        case Keyboard.KEYCODE_ALT:
            handleSymbolsSwitch();
            break;
        case Keyboard.KEYCODE_MODE_CHANGE:
            handleLanguageSwitch();
            break;
        default:
            char code = (char) primaryCode;
            if (Character.isLetter(code) && isCapsOn) {
                code = Character.toUpperCase(code);
            }

            ic.commitText(String.valueOf(code), 1);
            break;
    }
}
 
開發者ID:Medeuz,項目名稱:CustomAndroidKeyboard,代碼行數:33,代碼來源:SimpleIME.java

示例3: onKey

import android.view.inputmethod.InputConnection; //導入方法依賴的package包/類
@Override
public void onKey(int primaryCode, int[] keyCodes) {
    InputConnection ic = getCurrentInputConnection();
    playClick(primaryCode);

    switch (primaryCode) {
        case Keyboard.KEYCODE_DELETE:
            ic.deleteSurroundingText(1, 0);
            break;
        case Keyboard.KEYCODE_SHIFT:
            shift = !shift;
            if (kv.getKeyboard() == qwertyKeyboard) {
                kv.getKeyboard().setShifted(shift);
            } else {
                if (shift) {
                    kv.setKeyboard(symShiftKeyboard);
                } else {
                    kv.setKeyboard(symbolsKeyboard);
                }
            }
            kv.invalidateAllKeys();
            break;
        case Keyboard.KEYCODE_MODE_CHANGE:
            if (kv.getKeyboard() == symbolsKeyboard || kv.getKeyboard() == symShiftKeyboard) {
                kv.setKeyboard(qwertyKeyboard);
            } else {
                kv.setKeyboard(symbolsKeyboard);
                symbolsKeyboard.setShifted(false);
            }
            break;
        case Keyboard.KEYCODE_DONE:
            if (prefs.getBoolean("pref_signature_enable", false)) {
                ic.commitText(prefs.getString("pref_signature_text", ""), 0);
            }
            ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER));
            break;
        default:
            char code = (char)primaryCode;
            if (Character.isLetter(code) && shift) {
                code = Character.toUpperCase(code);
            }
            if (shift) {
                shift = false;
                kv.getKeyboard().setShifted(false);
                kv.invalidateAllKeys();
            }
            ic.commitText(String.valueOf(code), 1);
    }

    if (prefs.getBoolean("pref_swap_enable", false)) {
        shuffleKeyboard(kv.getKeyboard());
    }
}
 
開發者ID:rollforbugs,項目名稱:lokey,代碼行數:54,代碼來源:IME.java

示例4: handleKeypress

import android.view.inputmethod.InputConnection; //導入方法依賴的package包/類
private void handleKeypress(Keypress key, InputConnection ic) {
    final int meta = keypressMetastate(key);
    final long now = System.currentTimeMillis();
    ic.sendKeyEvent(new KeyEvent(now, now, KeyEvent.ACTION_DOWN, key.keycode, 0, meta));
    ic.sendKeyEvent(new KeyEvent(now, now, KeyEvent.ACTION_UP,   key.keycode, 0, meta));
}
 
開發者ID:Adellica,項目名稱:Thumbkeyboard,代碼行數:7,代碼來源:ThumbkeyboardIME.java


注:本文中的android.view.inputmethod.InputConnection.sendKeyEvent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。