List of usage examples for android.view KeyEvent KeyEvent
private KeyEvent(KeyEvent origEvent, int action)
From source file:com.hichinaschool.flashcards.anki.DeckPicker.java
protected void sendKey(int keycode) { this.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, keycode)); this.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, keycode)); }
From source file:com.anysoftkeyboard.AnySoftKeyboard.java
private void sendEscape() { InputConnection ic = getCurrentInputConnection(); if (ic == null) return;//from w w w .j ava2 s . c o m if (isTerminalEmulation()) { sendKeyChar((char) 27); } else { ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, 111 /* KEYCODE_ESCAPE */)); ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, 111 /* KEYCODE_ESCAPE */)); } }
From source file:org.distantshoresmedia.keyboard.LatinIME.java
private void sendSpecialKey(int code) { if (!isConnectbot()) { commitTyped(getCurrentInputConnection(), true); sendModifiedKeyDownUp(code);/*from w w w . j a va2s . co m*/ return; } // TODO(klausw): properly support xterm sequences for Ctrl/Alt modifiers? // See http://slackware.osuosl.org/slackware-12.0/source/l/ncurses/xterm.terminfo // and the output of "$ infocmp -1L". Support multiple sets, and optional // true numpad keys? if (ESC_SEQUENCES == null) { ESC_SEQUENCES = new HashMap<Integer, String>(); CTRL_SEQUENCES = new HashMap<Integer, Integer>(); // VT escape sequences without leading Escape ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_HOME, "[1~"); ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_END, "[4~"); ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_PAGE_UP, "[5~"); ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_PAGE_DOWN, "[6~"); ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F1, "OP"); ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F2, "OQ"); ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F3, "OR"); ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F4, "OS"); ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F5, "[15~"); ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F6, "[17~"); ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F7, "[18~"); ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F8, "[19~"); ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F9, "[20~"); ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F10, "[21~"); ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F11, "[23~"); ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F12, "[24~"); ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FORWARD_DEL, "[3~"); ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_INSERT, "[2~"); // Special ConnectBot hack: Ctrl-1 to Ctrl-0 for F1-F10. CTRL_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F1, KeyEvent.KEYCODE_1); CTRL_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F2, KeyEvent.KEYCODE_2); CTRL_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F3, KeyEvent.KEYCODE_3); CTRL_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F4, KeyEvent.KEYCODE_4); CTRL_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F5, KeyEvent.KEYCODE_5); CTRL_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F6, KeyEvent.KEYCODE_6); CTRL_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F7, KeyEvent.KEYCODE_7); CTRL_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F8, KeyEvent.KEYCODE_8); CTRL_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F9, KeyEvent.KEYCODE_9); CTRL_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F10, KeyEvent.KEYCODE_0); // Natively supported by ConnectBot // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_UP, "OA"); // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_DOWN, "OB"); // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_LEFT, "OD"); // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_RIGHT, "OC"); // No VT equivalents? // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_CENTER, ""); // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_SYSRQ, ""); // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_BREAK, ""); // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_NUM_LOCK, ""); // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_SCROLL_LOCK, ""); } InputConnection ic = getCurrentInputConnection(); Integer ctrlseq = null; if (mConnectbotTabHack) { ctrlseq = CTRL_SEQUENCES.get(code); } String seq = ESC_SEQUENCES.get(code); if (ctrlseq != null) { if (mModAlt) { // send ESC prefix for "Alt" ic.commitText(Character.toString((char) 27), 1); } ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_CENTER)); ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_CENTER)); ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, ctrlseq)); ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, ctrlseq)); } else if (seq != null) { if (mModAlt) { // send ESC prefix for "Alt" ic.commitText(Character.toString((char) 27), 1); } // send ESC prefix of escape sequence ic.commitText(Character.toString((char) 27), 1); ic.commitText(seq, 1); } else { // send key code, let connectbot handle it sendDownUpKeyEvents(code); } handleModifierKeysUp(false, false); }
From source file:org.pocketworkstation.pckeyboard.LatinIME.java
private void sendSpecialKey(int code) { if (!isConnectbot()) { commitTyped(getCurrentInputConnection(), true); sendModifiedKeyDownUp(code);//from w w w.j av a 2s . c om return; } // TODO(klausw): properly support xterm sequences for Ctrl/Alt modifiers? // See http://slackware.osuosl.org/slackware-12.0/source/l/ncurses/xterm.terminfo // and the output of "$ infocmp -1L". Support multiple sets, and optional // true numpad keys? if (ESC_SEQUENCES == null) { ESC_SEQUENCES = new HashMap<Integer, String>(); CTRL_SEQUENCES = new HashMap<Integer, Integer>(); // VT escape sequences without leading Escape ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_HOME, "[1~"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_END, "[4~"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_PAGE_UP, "[5~"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_PAGE_DOWN, "[6~"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F1, "OP"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F2, "OQ"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F3, "OR"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F4, "OS"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F5, "[15~"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F6, "[17~"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F7, "[18~"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F8, "[19~"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F9, "[20~"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F10, "[21~"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F11, "[23~"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F12, "[24~"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FORWARD_DEL, "[3~"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_INSERT, "[2~"); // Special ConnectBot hack: Ctrl-1 to Ctrl-0 for F1-F10. CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F1, KeyEvent.KEYCODE_1); CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F2, KeyEvent.KEYCODE_2); CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F3, KeyEvent.KEYCODE_3); CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F4, KeyEvent.KEYCODE_4); CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F5, KeyEvent.KEYCODE_5); CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F6, KeyEvent.KEYCODE_6); CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F7, KeyEvent.KEYCODE_7); CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F8, KeyEvent.KEYCODE_8); CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F9, KeyEvent.KEYCODE_9); CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F10, KeyEvent.KEYCODE_0); // Natively supported by ConnectBot // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_UP, "OA"); // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_DOWN, "OB"); // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_LEFT, "OD"); // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_RIGHT, "OC"); // No VT equivalents? // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_CENTER, ""); // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_SYSRQ, ""); // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_BREAK, ""); // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_NUM_LOCK, ""); // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_SCROLL_LOCK, ""); } InputConnection ic = getCurrentInputConnection(); Integer ctrlseq = null; if (mConnectbotTabHack) { ctrlseq = CTRL_SEQUENCES.get(code); } String seq = ESC_SEQUENCES.get(code); if (ctrlseq != null) { if (mModAlt) { // send ESC prefix for "Alt" ic.commitText(Character.toString((char) 27), 1); } ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_CENTER)); ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_CENTER)); ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, ctrlseq)); ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, ctrlseq)); } else if (seq != null) { if (mModAlt) { // send ESC prefix for "Alt" ic.commitText(Character.toString((char) 27), 1); } // send ESC prefix of escape sequence ic.commitText(Character.toString((char) 27), 1); ic.commitText(seq, 1); } else { // send key code, let connectbot handle it sendDownUpKeyEvents(code); } handleModifierKeysUp(false, false); }
From source file:org.distantshoresmedia.keyboard.LatinIME.java
private void sendTab() { InputConnection ic = getCurrentInputConnection(); boolean tabHack = isConnectbot() && mConnectbotTabHack; // FIXME: tab and ^I don't work in connectbot, hackish workaround if (tabHack) { if (mModAlt) { // send ESC prefix ic.commitText(Character.toString((char) 27), 1); }/*from w w w . j a v a 2 s. c o m*/ ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_CENTER)); ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_CENTER)); ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_I)); ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_I)); } else { sendModifiedKeyDownUp(KeyEvent.KEYCODE_TAB); } }
From source file:com.sonetel.ui.dialpad.DialerFragment.java
@Override public boolean onKey(View arg0, int keyCode, KeyEvent arg2) { KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode); return digits.onKeyDown(keyCode, event); }
From source file:org.telegram.ui.ChatActivity.java
private void createEmojiPopup() { emojiView = new EmojiView(parentActivity); emojiView.setListener(new EmojiView.Listener() { public void onBackspace() { messsageEditText.dispatchKeyEvent(new KeyEvent(0, 67)); }/*from ww w . j a v a 2 s. c o m*/ public void onEmojiSelected(String paramAnonymousString) { int i = messsageEditText.getSelectionEnd(); CharSequence localCharSequence = Emoji.replaceEmoji(paramAnonymousString); messsageEditText.setText(messsageEditText.getText().insert(i, localCharSequence)); int j = i + localCharSequence.length(); messsageEditText.setSelection(j, j); } }); emojiPopup = new PopupWindow(emojiView); }
From source file:com.anysoftkeyboard.AnySoftKeyboard.java
private void sendKeyDown(InputConnection ic, int key) { if (ic != null) ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, key)); }
From source file:com.anysoftkeyboard.AnySoftKeyboard.java
private void sendKeyUp(InputConnection ic, int key) { if (ic != null) ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, key)); }
From source file:org.telegram.ui.Components.ChatActivityEnterView.java
private void createEmojiView() { if (emojiView != null) { return;/*ww w .j a v a 2s.c o m*/ } emojiView = new EmojiView(allowStickers, allowGifs, parentActivity); emojiView.setVisibility(GONE); emojiView.setListener(new EmojiView.Listener() { public boolean onBackspace() { if (messageEditText.length() == 0) { return false; } messageEditText.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL)); return true; } public void onEmojiSelected(String symbol) { int i = messageEditText.getSelectionEnd(); if (i < 0) { i = 0; } try { innerTextChange = 2; CharSequence localCharSequence = Emoji.replaceEmoji(symbol, messageEditText.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20), false); messageEditText.setText(messageEditText.getText().insert(i, localCharSequence)); int j = i + localCharSequence.length(); messageEditText.setSelection(j, j); } catch (Exception e) { FileLog.e(e); } finally { innerTextChange = 0; } } public void onStickerSelected(TLRPC.Document sticker) { ChatActivityEnterView.this.onStickerSelected(sticker); StickersQuery.addRecentSticker(StickersQuery.TYPE_IMAGE, sticker, (int) (System.currentTimeMillis() / 1000)); if ((int) dialog_id == 0) { MessagesController.getInstance().saveGif(sticker); } } @Override public void onStickersSettingsClick() { if (parentFragment != null) { parentFragment.presentFragment(new StickersActivity(StickersQuery.TYPE_IMAGE)); } } @Override public void onGifSelected(TLRPC.Document gif) { SendMessagesHelper.getInstance().sendSticker(gif, dialog_id, replyingMessageObject); StickersQuery.addRecentGif(gif, (int) (System.currentTimeMillis() / 1000)); if ((int) dialog_id == 0) { MessagesController.getInstance().saveGif(gif); } if (delegate != null) { delegate.onMessageSend(null); } } @Override public void onGifTab(boolean opened) { if (!AndroidUtilities.usingHardwareInput) { if (opened) { if (messageEditText.length() == 0) { messageEditText.setText("@gif "); messageEditText.setSelection(messageEditText.length()); } } else if (messageEditText.getText().toString().equals("@gif ")) { messageEditText.setText(""); } } } @Override public void onStickersTab(boolean opened) { delegate.onStickersTab(opened); } @Override public void onClearEmojiRecent() { if (parentFragment == null || parentActivity == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setMessage(LocaleController.getString("ClearRecentEmoji", R.string.ClearRecentEmoji)); builder.setPositiveButton( LocaleController.getString("ClearButton", R.string.ClearButton).toUpperCase(), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { emojiView.clearRecentEmoji(); } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); parentFragment.showDialog(builder.create()); } @Override public void onShowStickerSet(TLRPC.StickerSet stickerSet, TLRPC.InputStickerSet inputStickerSet) { if (parentFragment == null || parentActivity == null) { return; } if (stickerSet != null) { inputStickerSet = new TLRPC.TL_inputStickerSetID(); inputStickerSet.access_hash = stickerSet.access_hash; inputStickerSet.id = stickerSet.id; } parentFragment.showDialog(new StickersAlert(parentActivity, parentFragment, inputStickerSet, null, ChatActivityEnterView.this)); } @Override public void onStickerSetAdd(TLRPC.StickerSetCovered stickerSet) { StickersQuery.removeStickersSet(parentActivity, stickerSet.set, 2, parentFragment, false); } @Override public void onStickerSetRemove(TLRPC.StickerSetCovered stickerSet) { StickersQuery.removeStickersSet(parentActivity, stickerSet.set, 0, parentFragment, false); } }); emojiView.setVisibility(GONE); sizeNotifierLayout.addView(emojiView); }