Java Code Examples for android.view.KeyEvent#META_CTRL_ON

The following examples show how to use android.view.KeyEvent#META_CTRL_ON . 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: ImeAdapter.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private static int getModifiers(int metaState) {
    int modifiers = 0;
    if ((metaState & KeyEvent.META_SHIFT_ON) != 0) {
        modifiers |= WebInputEventModifier.SHIFT_KEY;
    }
    if ((metaState & KeyEvent.META_ALT_ON) != 0) {
        modifiers |= WebInputEventModifier.ALT_KEY;
    }
    if ((metaState & KeyEvent.META_CTRL_ON) != 0) {
        modifiers |= WebInputEventModifier.CONTROL_KEY;
    }
    if ((metaState & KeyEvent.META_CAPS_LOCK_ON) != 0) {
        modifiers |= WebInputEventModifier.CAPS_LOCK_ON;
    }
    if ((metaState & KeyEvent.META_NUM_LOCK_ON) != 0) {
        modifiers |= WebInputEventModifier.NUM_LOCK_ON;
    }
    return modifiers;
}
 
Example 2
Source File: EspressoKey.java    From android-test with Apache License 2.0 6 votes vote down vote up
private int getMetaState() {
  int metaState = 0;
  if (isShiftPressed) {
    metaState |= KeyEvent.META_SHIFT_ON;
  }

  if (isAltPressed) {
    metaState |= KeyEvent.META_ALT_ON;
  }

  if (isCtrlPressed && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
    metaState |= KeyEvent.META_CTRL_ON;
  }

  return metaState;
}
 
Example 3
Source File: ImeAdapter.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private static int getModifiers(int metaState) {
    int modifiers = 0;
    if ((metaState & KeyEvent.META_SHIFT_ON) != 0) {
      modifiers |= sModifierShift;
    }
    if ((metaState & KeyEvent.META_ALT_ON) != 0) {
      modifiers |= sModifierAlt;
    }
    if ((metaState & KeyEvent.META_CTRL_ON) != 0) {
      modifiers |= sModifierCtrl;
    }
    if ((metaState & KeyEvent.META_CAPS_LOCK_ON) != 0) {
      modifiers |= sModifierCapsLockOn;
    }
    if ((metaState & KeyEvent.META_NUM_LOCK_ON) != 0) {
      modifiers |= sModifierNumLockOn;
    }
    return modifiers;
}
 
Example 4
Source File: ImeAdapter.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private static int getModifiers(int metaState) {
    int modifiers = 0;
    if ((metaState & KeyEvent.META_SHIFT_ON) != 0) {
      modifiers |= sModifierShift;
    }
    if ((metaState & KeyEvent.META_ALT_ON) != 0) {
      modifiers |= sModifierAlt;
    }
    if ((metaState & KeyEvent.META_CTRL_ON) != 0) {
      modifiers |= sModifierCtrl;
    }
    if ((metaState & KeyEvent.META_CAPS_LOCK_ON) != 0) {
      modifiers |= sModifierCapsLockOn;
    }
    if ((metaState & KeyEvent.META_NUM_LOCK_ON) != 0) {
      modifiers |= sModifierNumLockOn;
    }
    return modifiers;
}
 
Example 5
Source File: LatinIME.java    From hackerskeyboard with Apache License 2.0 5 votes vote down vote up
private int getMetaState(boolean shifted) {
    int meta = 0;
    if (shifted) meta |= KeyEvent.META_SHIFT_ON | KeyEvent.META_SHIFT_LEFT_ON;
    if (mModCtrl) meta |= KeyEvent.META_CTRL_ON | KeyEvent.META_CTRL_LEFT_ON;
    if (mModAlt) meta |= KeyEvent.META_ALT_ON | KeyEvent.META_ALT_LEFT_ON;
    if (mModMeta) meta |= KeyEvent.META_META_ON | KeyEvent.META_META_LEFT_ON;
    return meta;
}
 
Example 6
Source File: LatinIME.java    From hackerskeyboard with Apache License 2.0 5 votes vote down vote up
private void sendCtrlKey(InputConnection ic, boolean isDown, boolean chording) {
    if (chording && delayChordingCtrlModifier()) return;

    int key = sKeyboardSettings.chordingCtrlKey;
    if (key == 0) key = KeyEvent.KEYCODE_CTRL_LEFT;
    int meta = KeyEvent.META_CTRL_ON | KeyEvent.META_CTRL_LEFT_ON;
    if (isDown) {
        sendKeyDown(ic, key, meta);
    } else {
        sendKeyUp(ic, key, meta);
    }
}
 
Example 7
Source File: KeyAssignmentUtils.java    From talkback with Apache License 2.0 5 votes vote down vote up
/**
 * Convert a KeyEvent into a long which can be kept in settings and compared to key presses when
 * the service is in use.
 *
 * @param keyEvent The key event to convert. The (non-extended) keycode must not be a modifier.
 * @return An extended key code that includes modifier information
 */
public static long keyEventToExtendedKeyCode(KeyEvent keyEvent) {
  long returnValue = keyEvent.getKeyCode();
  returnValue |= (keyEvent.isShiftPressed()) ? (((long) KeyEvent.META_SHIFT_ON) << 32) : 0;
  returnValue |= (keyEvent.isCtrlPressed()) ? (((long) KeyEvent.META_CTRL_ON) << 32) : 0;
  returnValue |= (keyEvent.isAltPressed()) ? (((long) KeyEvent.META_ALT_ON) << 32) : 0;
  return returnValue;
}
 
Example 8
Source File: KeyAssignmentUtils.java    From talkback with Apache License 2.0 4 votes vote down vote up
/**
 * Create a string that describes the extended key code. This string can be shown to the user to
 * indicate the current choice of key.
 *
 * @param extendedKeyCode The key code to describe
 * @param context The current Context
 * @return A description of the key code
 */
public static String describeExtendedKeyCode(long extendedKeyCode, Context context) {
  if (extendedKeyCode == INVALID_EXTENDED_KEY_CODE) {
    return context.getString(R.string.no_key_assigned);
  }

  if (extendedKeyCode == KEYCODE_SCREEN_SWITCH) {
    return context.getString(R.string.name_of_screen_switch);
  }
  /* If meta keys are pressed, build a string to represent this combination of keys */
  StringBuilder keystrokeDescriptionBuilder = new StringBuilder();
  if ((extendedKeyCode & (((long) KeyEvent.META_CTRL_ON) << 32)) != 0) {
    keystrokeDescriptionBuilder.append(
        context.getString(R.string.key_combo_preference_control_plus));
  }
  if ((extendedKeyCode & (((long) KeyEvent.META_ALT_ON) << 32)) != 0) {
    keystrokeDescriptionBuilder.append(context.getString(R.string.key_combo_preference_alt_plus));
  }
  if ((extendedKeyCode & (((long) KeyEvent.META_SHIFT_ON) << 32)) != 0) {
    keystrokeDescriptionBuilder.append(
        context.getString(R.string.key_combo_preference_shift_plus));
  }

  /* Try to obtain a localized representation of the key */
  KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, (int) extendedKeyCode);
  char displayLabel = keyEvent.getDisplayLabel();
  if (displayLabel != 0 && !Character.isWhitespace(displayLabel)) {
    keystrokeDescriptionBuilder.append(displayLabel);
  } else if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_SPACE) {
    keystrokeDescriptionBuilder.append(context.getString(R.string.name_of_space_bar));
  } else if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
    keystrokeDescriptionBuilder.append(context.getString(R.string.name_of_enter_key));
  } else if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_TAB) {
    keystrokeDescriptionBuilder.append(context.getString(R.string.name_of_tab_key));
  } else {
    /* Fall back on non-localized descriptions */
    keystrokeDescriptionBuilder.append(KeyEvent.keyCodeToString((int) extendedKeyCode));
  }

  return keystrokeDescriptionBuilder.toString();
}
 
Example 9
Source File: KeyboardShortcuts.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * This method should be called when overriding from
 * {@link android.app.Activity#onProvideKeyboardShortcuts(List, android.view.Menu, int)}
 * in an activity. It will return a list of the possible shortcuts. If
 * someone adds a shortcut they also need to add an explanation in the
 * appropriate group in this method so the user can see it when this method
 * is called.
 *
 * @param context We need an activity so we can call the strings from our
 *            resource.
 * @return a list of shortcuts organized into groups.
 */
@TargetApi(Build.VERSION_CODES.N)
public static List<KeyboardShortcutGroup> createShortcutGroup(Context context) {

    final int ctrlShift = KeyEvent.META_CTRL_ON | KeyEvent.META_SHIFT_ON;

    List<KeyboardShortcutGroup> shortcutGroups = new ArrayList<>();

    KeyboardShortcutGroup tabShortcutGroup = new KeyboardShortcutGroup(
            context.getString(R.string.keyboard_shortcut_tab_group_header));
    addShortcut(context, tabShortcutGroup, R.string.keyboard_shortcut_open_new_tab,
            KeyEvent.KEYCODE_N, KeyEvent.META_CTRL_ON);
    addShortcut(context, tabShortcutGroup, R.string.keyboard_shortcut_reopen_new_tab,
            KeyEvent.KEYCODE_T, ctrlShift);
    addShortcut(context, tabShortcutGroup, R.string.keyboard_shortcut_new_incognito_tab,
            KeyEvent.KEYCODE_N, ctrlShift);
    addShortcut(context, tabShortcutGroup, R.string.keyboard_shortcut_next_tab,
            KeyEvent.KEYCODE_TAB, KeyEvent.META_CTRL_ON);
    addShortcut(context, tabShortcutGroup, R.string.keyboard_shortcut_prev_tab,
            KeyEvent.KEYCODE_TAB, ctrlShift);
    addShortcut(context, tabShortcutGroup, R.string.keyboard_shortcut_close_tab,
            KeyEvent.KEYCODE_W, KeyEvent.META_CTRL_ON);
    shortcutGroups.add(tabShortcutGroup);

    KeyboardShortcutGroup chromeFeatureShortcutGroup = new KeyboardShortcutGroup(
            context.getString(R.string.keyboard_shortcut_chrome_feature_group_header));
    addShortcut(context, chromeFeatureShortcutGroup, R.string.keyboard_shortcut_open_menu,
            KeyEvent.KEYCODE_E, KeyEvent.META_ALT_ON);
    addShortcut(context, chromeFeatureShortcutGroup,
            R.string.keyboard_shortcut_bookmark_manager, KeyEvent.KEYCODE_B, ctrlShift);
    addShortcut(context, chromeFeatureShortcutGroup, R.string.keyboard_shortcut_history_manager,
            KeyEvent.KEYCODE_H, KeyEvent.META_CTRL_ON);
    addShortcut(context, chromeFeatureShortcutGroup, R.string.keyboard_shortcut_find_bar,
            KeyEvent.KEYCODE_F, KeyEvent.META_CTRL_ON);
    addShortcut(context, chromeFeatureShortcutGroup, R.string.keyboard_shortcut_address_bar,
            KeyEvent.KEYCODE_L, KeyEvent.META_CTRL_ON);
    shortcutGroups.add(chromeFeatureShortcutGroup);

    KeyboardShortcutGroup webpageShortcutGroup = new KeyboardShortcutGroup(
            context.getString(R.string.keyboard_shortcut_webpage_group_header));
    addShortcut(context, webpageShortcutGroup, R.string.keyboard_shortcut_print_page,
            KeyEvent.KEYCODE_P, KeyEvent.META_CTRL_ON);
    addShortcut(context, webpageShortcutGroup, R.string.keyboard_shortcut_reload_page,
            KeyEvent.KEYCODE_R, KeyEvent.META_CTRL_ON);
    addShortcut(context, webpageShortcutGroup, R.string.keyboard_shortcut_reload_no_cache,
            KeyEvent.KEYCODE_R, ctrlShift);
    addShortcut(context, webpageShortcutGroup, R.string.keyboard_shortcut_bookmark_page,
            KeyEvent.KEYCODE_D, KeyEvent.META_CTRL_ON);
    addShortcut(context, webpageShortcutGroup, R.string.keyboard_shortcut_zoom_in,
            KeyEvent.KEYCODE_EQUALS, KeyEvent.META_CTRL_ON);
    addShortcut(context, webpageShortcutGroup, R.string.keyboard_shortcut_zoom_out,
            KeyEvent.KEYCODE_MINUS, KeyEvent.META_CTRL_ON);
    addShortcut(context, webpageShortcutGroup, R.string.keyboard_shortcut_reset_zoom,
            KeyEvent.KEYCODE_0, KeyEvent.META_CTRL_ON);
    addShortcut(context, webpageShortcutGroup, R.string.keyboard_shortcut_help_center,
            KeyEvent.KEYCODE_SLASH, ctrlShift);
    shortcutGroups.add(webpageShortcutGroup);

    return shortcutGroups;
}