当前位置: 首页>>代码示例>>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;未经允许,请勿转载。