本文整理匯總了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));
}