Java Code Examples for android.view.KeyEvent#isCtrlPressed()

The following examples show how to use android.view.KeyEvent#isCtrlPressed() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From Xndroid with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN && event.isCtrlPressed()) {
        switch (event.getKeyCode()) {
            case KeyEvent.KEYCODE_P:
                // Open a new private window
                if(event.isShiftPressed()) {
                    startActivity(new Intent(this, IncognitoActivity.class));
                    overridePendingTransition(R.anim.slide_up_in, R.anim.fade_out_scale);
                    return true;
                }
                break;
        }
    }
    return super.dispatchKeyEvent(event);
}
 
Example 2
Source File: Editor.java    From turbo-editor with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onKeyUp(int keyCode, @NonNull KeyEvent event) {
    if (event.isCtrlPressed()) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_A:
            case KeyEvent.KEYCODE_X:
            case KeyEvent.KEYCODE_C:
            case KeyEvent.KEYCODE_V:
            case KeyEvent.KEYCODE_Z:
            case KeyEvent.KEYCODE_Y:
            case KeyEvent.KEYCODE_S:
                return true;
            default:
                return false;
        }
    } else {
        switch (keyCode) {
            case KeyEvent.KEYCODE_TAB:
                return true;
            default:
                return false;
        }
    }
}
 
Example 3
Source File: EditMessage.java    From Pix-Art-Messenger with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent e) {
    if (keyCode == KeyEvent.KEYCODE_ENTER && !e.isShiftPressed()) {
        lastInputWasTab = false;
        if (keyboardListener != null && keyboardListener.onEnterPressed()) {
            return true;
        }
    } else if (keyCode == KeyEvent.KEYCODE_TAB && !e.isAltPressed() && !e.isCtrlPressed()) {
        if (keyboardListener != null && keyboardListener.onTabPressed(this.lastInputWasTab)) {
            lastInputWasTab = true;
            return true;
        }
    } else {
        lastInputWasTab = false;
    }
    return super.onKeyDown(keyCode, e);
}
 
Example 4
Source File: EditMessage.java    From Conversations with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent e) {
    if (keyCode == KeyEvent.KEYCODE_ENTER && !e.isShiftPressed()) {
        lastInputWasTab = false;
        if (keyboardListener != null && keyboardListener.onEnterPressed()) {
            return true;
        }
    } else if (keyCode == KeyEvent.KEYCODE_TAB && !e.isAltPressed() && !e.isCtrlPressed()) {
        if (keyboardListener != null && keyboardListener.onTabPressed(this.lastInputWasTab)) {
            lastInputWasTab = true;
            return true;
        }
    } else {
        lastInputWasTab = false;
    }
    return super.onKeyDown(keyCode, e);
}
 
Example 5
Source File: EditorActivity.java    From PHONK with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onKeyShortcut(int keyCode, KeyEvent event) {
    if (event.isCtrlPressed()) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_R:
                saveAndRun();
                break;

            case KeyEvent.KEYCODE_S:
                onlySave();
                break;

            case KeyEvent.KEYCODE_F:
                toggleApiDrawer();

                break;
        }
    }
    return super.onKeyShortcut(keyCode, event);
}
 
Example 6
Source File: AppCompatPreferenceActivity.java    From MHViewer with Apache License 2.0 6 votes vote down vote up
/**
 * KeyEvents with non-default modifiers are not dispatched to menu's performShortcut in API 25
 * or lower. Here, we check if the keypress corresponds to a menuitem's shortcut combination
 * and perform the corresponding action.
 */
private boolean performMenuItemShortcut(int keycode, KeyEvent event) {
    if (!(Build.VERSION.SDK_INT >= 26) && !event.isCtrlPressed()
        && !KeyEvent.metaStateHasNoModifiers(event.getMetaState())
        && event.getRepeatCount() == 0
        && !KeyEvent.isModifierKey(event.getKeyCode())) {
        final Window currentWindow = getWindow();
        if (currentWindow != null && currentWindow.getDecorView() != null) {
            final View decorView = currentWindow.getDecorView();
            if (decorView.dispatchKeyShortcutEvent(event)) {
                return true;
            }
        }
    }
    return false;
}
 
Example 7
Source File: NoteEditActivity.java    From Notepad with Apache License 2.0 5 votes vote down vote up
@Override
public boolean dispatchKeyShortcutEvent(KeyEvent event) {
    if(event.getAction() == KeyEvent.ACTION_DOWN && event.isCtrlPressed()) {
        NoteEditFragment fragment = (NoteEditFragment) getSupportFragmentManager().findFragmentByTag("NoteEditFragment");
        fragment.dispatchKeyShortcutEvent(event.getKeyCode());

        return true;
    }
    return super.dispatchKeyShortcutEvent(event);
}
 
Example 8
Source File: EditorActivity.java    From spline with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {

    switch (keyCode) {
        case KeyEvent.KEYCODE_R:
            mViewModel.addRectLayer();
            return true;
        case KeyEvent.KEYCODE_T:
            mViewModel.addTriangleLayer();
            return true;
        case KeyEvent.KEYCODE_O:
            mViewModel.addOvalLayer();
            return true;
    }

    if (mBinding.documentView.hasFocus()) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_DEL:
            case KeyEvent.KEYCODE_FORWARD_DEL:
                return onContextMenuAction(DELETE);
        }

        if (event.isCtrlPressed()) {
            switch (keyCode) {
                case KeyEvent.KEYCODE_X:
                    return onContextMenuAction(CUT);
                case KeyEvent.KEYCODE_C:
                    return onContextMenuAction(COPY);
                case KeyEvent.KEYCODE_V:
                    return onContextMenuAction(PASTE);
                case KeyEvent.KEYCODE_D:
                    return onContextMenuAction(DUPLICATE);
                case KeyEvent.KEYCODE_G:
                    return onContextMenuAction(GROUP);
            }
        }
    }

    return super.onKeyDown(keyCode, event);
}
 
Example 9
Source File: AppRunnerActivity.java    From PHONK with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onKeyShortcut(int keyCode, KeyEvent event) {
    if (event.isCtrlPressed()) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_R:
                finish();
                break;
        }
    }
    return super.onKeyShortcut(keyCode, event);
}
 
Example 10
Source File: LauncherActivity.java    From HgLauncher with GNU General Public License v3.0 5 votes vote down vote up
@Override public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN && event.isCtrlPressed()) {
        return Utils.handleInputShortcut(this, searchBar, keyCode);
    } else {
        if (keyCode == KeyEvent.KEYCODE_SPACE) {
            if (getWindow().getCurrentFocus() != searchBar) {
                doThis("show_panel");
            }
            return true;
        } else {
            return super.onKeyUp(keyCode, event);
        }
    }
}
 
Example 11
Source File: ContentViewClient.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public boolean shouldOverrideKeyEvent(KeyEvent event) {
    int keyCode = event.getKeyCode();
    // We need to send almost every key to WebKit. However:
    // 1. We don't want to block the device on the renderer for
    // some keys like menu, home, call.
    // 2. There are no WebKit equivalents for some of these keys
    // (see app/keyboard_codes_win.h)
    // Note that these are not the same set as KeyEvent.isSystemKey:
    // for instance, AKEYCODE_MEDIA_* will be dispatched to webkit.
    if (keyCode == KeyEvent.KEYCODE_MENU ||
        keyCode == KeyEvent.KEYCODE_HOME ||
        keyCode == KeyEvent.KEYCODE_BACK ||
        keyCode == KeyEvent.KEYCODE_CALL ||
        keyCode == KeyEvent.KEYCODE_ENDCALL ||
        keyCode == KeyEvent.KEYCODE_POWER ||
        keyCode == KeyEvent.KEYCODE_HEADSETHOOK ||
        keyCode == KeyEvent.KEYCODE_CAMERA ||
        keyCode == KeyEvent.KEYCODE_FOCUS ||
        keyCode == KeyEvent.KEYCODE_VOLUME_DOWN ||
        keyCode == KeyEvent.KEYCODE_VOLUME_MUTE ||
        keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
        return true;
    }

    // We also have to intercept some shortcuts before we send them to the ContentView.
    if (event.isCtrlPressed() && (
            keyCode == KeyEvent.KEYCODE_TAB ||
            keyCode == KeyEvent.KEYCODE_W ||
            keyCode == KeyEvent.KEYCODE_F4)) {
        return true;
    }

    return false;
}
 
Example 12
Source File: FindToolbar.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_F3
            || (keyCode == KeyEvent.KEYCODE_G && event.isCtrlPressed())) {
        mFindToolbar.hideKeyboardAndStartFinding(!event.isShiftPressed());
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
 
Example 13
Source File: FindToolbar.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_F3
            || (keyCode == KeyEvent.KEYCODE_G && event.isCtrlPressed())) {
        mFindToolbar.hideKeyboardAndStartFinding(!event.isShiftPressed());
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
 
Example 14
Source File: LauncherActivity.java    From HgLauncher with GNU General Public License v3.0 5 votes vote down vote up
@Override public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN && event.isCtrlPressed()) {
        return Utils.handleInputShortcut(this, searchBar, keyCode);
    } else {
        if (keyCode == KeyEvent.KEYCODE_SPACE) {
            if (getWindow().getCurrentFocus() != searchBar) {
                doThis("show_panel");
            }
            return true;
        } else {
            return super.onKeyUp(keyCode, event);
        }
    }
}
 
Example 15
Source File: ContentViewClient.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public boolean shouldOverrideKeyEvent(KeyEvent event) {
    int keyCode = event.getKeyCode();
    // We need to send almost every key to WebKit. However:
    // 1. We don't want to block the device on the renderer for
    // some keys like menu, home, call.
    // 2. There are no WebKit equivalents for some of these keys
    // (see app/keyboard_codes_win.h)
    // Note that these are not the same set as KeyEvent.isSystemKey:
    // for instance, AKEYCODE_MEDIA_* will be dispatched to webkit.
    if (keyCode == KeyEvent.KEYCODE_MENU ||
        keyCode == KeyEvent.KEYCODE_HOME ||
        keyCode == KeyEvent.KEYCODE_BACK ||
        keyCode == KeyEvent.KEYCODE_CALL ||
        keyCode == KeyEvent.KEYCODE_ENDCALL ||
        keyCode == KeyEvent.KEYCODE_POWER ||
        keyCode == KeyEvent.KEYCODE_HEADSETHOOK ||
        keyCode == KeyEvent.KEYCODE_CAMERA ||
        keyCode == KeyEvent.KEYCODE_FOCUS ||
        keyCode == KeyEvent.KEYCODE_VOLUME_DOWN ||
        keyCode == KeyEvent.KEYCODE_VOLUME_MUTE ||
        keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
        return true;
    }

    // We also have to intercept some shortcuts before we send them to the ContentView.
    if (event.isCtrlPressed() && (
            keyCode == KeyEvent.KEYCODE_TAB ||
            keyCode == KeyEvent.KEYCODE_W ||
            keyCode == KeyEvent.KEYCODE_F4)) {
        return true;
    }

    return false;
}
 
Example 16
Source File: Editor.java    From turbo-editor with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, @NonNull KeyEvent event) {

    if (event.isCtrlPressed()) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_A:
                return onTextContextMenuItem(ID_SELECT_ALL);
            case KeyEvent.KEYCODE_X:
                return onTextContextMenuItem(ID_CUT);
            case KeyEvent.KEYCODE_C:
                return onTextContextMenuItem(ID_COPY);
            case KeyEvent.KEYCODE_V:
                return onTextContextMenuItem(ID_PASTE);
            case KeyEvent.KEYCODE_Z:
                if (getCanUndo()) {
                    return onTextContextMenuItem(ID_UNDO);
                }
            case KeyEvent.KEYCODE_Y:
                if (getCanRedo()) {
                    return onTextContextMenuItem(ID_REDO);
                }
            case KeyEvent.KEYCODE_S:
                getMainActivity().saveTheFile(false);
                return true;
            default:
                return super.onKeyDown(keyCode, event);
        }
    } else {
        switch (keyCode) {
            case KeyEvent.KEYCODE_TAB:
                String textToInsert = "  ";
                int start, end;
                start = Math.max(getSelectionStart(), 0);
                end = Math.max(getSelectionEnd(), 0);
                getText().replace(Math.min(start, end), Math.max(start, end),
                        textToInsert, 0, textToInsert.length());
                return true;
            default:
                return super.onKeyDown(keyCode, event);
        }
    }
}
 
Example 17
Source File: FastEdit.java    From fastedit with Apache License 2.0 4 votes vote down vote up
void onKeyEvent(KeyEvent event) {
    int action = event.getAction();
    int keyCode = event.getKeyCode();
    switch (action) {
        case KeyEvent.ACTION_DOWN: {

            //输入模式
            int unicodeChar = event.getUnicodeChar();
            if (unicodeChar != 0) {

                input((char) unicodeChar);
                event.cancel();
            }
            if (!event.isCanceled() && !event.isCtrlPressed() && !event.isAltPressed()
                    && !event.isShiftPressed()) {
                switch (keyCode) {
                    case KeyEvent.KEYCODE_TAB:
                        //tab
                        input(tabText);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_SPACE:
                        //空格
                        input(' ');
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_ENTER:
                        //enter
                        onKeyCodeEnter(event);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_DEL:
                        //del
                        onKeyCodeDel(event);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_FORWARD_DEL:
                        //del
                        onKeyCodeForwardDel(event);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_DPAD_LEFT:
                        //left
                        onKeyCodeDpadLeft(event);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_DPAD_RIGHT:
                        //right
                        onKeyCodeDpadRight(event);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_DPAD_UP:
                        //up
                        onKeyCodeDpadUp(event);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_DPAD_DOWN:
                        //down
                        onKeyCodeDpadDown(event);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_VOLUME_DOWN:

                    case KeyEvent.KEYCODE_PAGE_DOWN:
                        //page down
                        onKeyCodePageDown(event);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_VOLUME_UP:

                    case KeyEvent.KEYCODE_PAGE_UP:
                        //page up
                        onKeyCodePageUp(event);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_MOVE_HOME:
                        onKeyCodeMoveHome(event);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_MOVE_END:
                        onKeyCodeMoveEnd(event);
                        event.cancel();
                        break;
                }
            }
            if (!event.isCanceled()) {
                //快捷键模式
                if (onShortKey(event.isCtrlPressed(), event.isAltPressed(), event.isShiftPressed(), keyCode)) {
                    event.cancel();
                }
            }

            break;
        }

    }
}
 
Example 18
Source File: KeyboardShortcuts.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
private static int getMetaState(KeyEvent event) {
    return (event.isCtrlPressed() ? CTRL : 0)
            | (event.isAltPressed() ? ALT : 0)
            | (event.isShiftPressed() ? SHIFT : 0);
}
 
Example 19
Source File: TextProcessor.java    From CodeEditor with Apache License 2.0 4 votes vote down vote up
@Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (event.isCtrlPressed()) {
            switch (keyCode) {
                case KeyEvent.KEYCODE_X: // CTRL+X - Cut
                    cut();
                    return true;
                case KeyEvent.KEYCODE_C: // CTRL+C - Copy
                    copy();
                    return true;
                case KeyEvent.KEYCODE_V: // CTRL+V - Paste
                    paste();
                    return true;
                case KeyEvent.KEYCODE_Z: // CTRL+Z - Undo
                    undo();
                    return true;
                case KeyEvent.KEYCODE_Y: // CTRL+Y - Redo
                    redo();
                    return true;
                case KeyEvent.KEYCODE_A: // CTRL+A - Select All
                    selectAll();
                    return true;
                case KeyEvent.KEYCODE_DEL: // CTRL+Delete - Delete Line
                    deleteLine();
                    return true;
                case KeyEvent.KEYCODE_D: // CTRL+D - Duplicate Line
                    duplicateLine();
                    return true;
//                case KeyEvent.KEYCODE_S: // CTRL+S - Save File
//                    codeEditor.saveFile();
//                    return true;
                default:
                    return super.onKeyDown(keyCode, event);
            }
        } else {
            switch (keyCode) {
                case KeyEvent.KEYCODE_TAB: // TAB
                    int start, end;
                    start = Math.max(getSelectionStart(), 0);
                    end = Math.max(getSelectionEnd(), 0);
                    getText().replace(Math.min(start, end),
                            Math.max(start, end), TAB_STR, 0, TAB_STR.length());
                    return true;
                default:
                    try {
                        return super.onKeyDown(keyCode, event);
                    } catch (Exception e) {
                        Logger.error(TAG, e);
                    }
                    return false;
            }
        }
    }
 
Example 20
Source File: KeyboardShortcuts.java    From 365browser with Apache License 2.0 4 votes vote down vote up
private static int getMetaState(KeyEvent event) {
    return (event.isCtrlPressed() ? CTRL : 0)
            | (event.isAltPressed() ? ALT : 0)
            | (event.isShiftPressed() ? SHIFT : 0);
}