本文整理汇总了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;
}
}
示例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;
}
}
示例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());
}
}
示例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));
}