Class Keyboard


  • public final class Keyboard
    extends java.lang.Object
    Class representing the system keyboard.
    • Method Detail

      • getModifiers

        public static int getModifiers()
        Returns:
        A bitfield representing the keyboard modifiers that are currently pressed.
      • setModifiers

        protected static void setModifiers​(int modifiers)
        Set the current set of pressed keyboard modifiers.
        Parameters:
        modifiers - The complete bit mask of current modifiers.
      • isPressed

        public static boolean isPressed​(Keyboard.Modifier modifier)
        Tests the pressed state of a modifier.

        Note: this method tests whether or not one modifier is pressed. It does not, however, test if this is the ONLY modifier pressed. Use one of the arePressed(...) methods for that purpose. To test efficiently for whether more than one modifier is pressed, use one of the areAnyPressed(...) or areAllPressed(...) methods. And finally, to succinctly test for the "Cmd" key (which is platform-dependent) being pressed, use isCmdPressed().

        Parameters:
        modifier - The modifier to test.
        Returns:
        true if the modifier is pressed; false, otherwise.
      • arePressed

        public static boolean arePressed​(Set<Keyboard.Modifier> modifierSet)
        Test to see if and only if the given set of modifier(s) are pressed.
        Parameters:
        modifierSet - The set of modifiers to test.
        Returns:
        true if only those modifiers (and no others) are pressed.
      • arePressed

        public static boolean arePressed​(Keyboard.Modifier... modifiers)
        Test to see if and only if the given modifier(s) are pressed.
        Parameters:
        modifiers - The modifiers to test.
        Returns:
        true if only those modifiers (and no others) are pressed.
      • areAnyPressed

        public static boolean areAnyPressed​(Set<Keyboard.Modifier> modifierSet)
        Are any of the given set of Keyboard.Modifiers pressed?
        Parameters:
        modifierSet - The set of modifiers to test.
        Returns:
        true if any of them are pressed, false if none are pressed.
      • areAnyPressed

        public static boolean areAnyPressed​(Keyboard.Modifier... modifiers)
        Are any of the given list of Keyboard.Modifiers pressed?
        Parameters:
        modifiers - The modifiers to test.
        Returns:
        true if any of them are pressed, false if none are pressed.
      • areAllPressed

        public static boolean areAllPressed​(Set<Keyboard.Modifier> modifierSet)
        Are all of the given set of Keyboard.Modifiers pressed?

        This is typically used to test two modifiers (like CTRL and SHIFT).

        Parameters:
        modifierSet - The set of modifiers to test.
        Returns:
        true if all of the modifiers are pressed, false if only some or none are pressed.
      • areAllPressed

        public static boolean areAllPressed​(Keyboard.Modifier... modifiers)
        Are all of the given list of Keyboard.Modifiers pressed?

        This is typically used to test two modifiers (like CTRL and SHIFT).

        Parameters:
        modifiers - The modifiers to test.
        Returns:
        true if all of the modifiers are pressed, false if only some or none are pressed.
      • isCmdPressed

        public static boolean isCmdPressed()
        Shortcut method to test if the Platform.getCommandModifier() is pressed.
        Returns:
        The result of isPressed(Platform.getCommandModifier()).
      • getDropAction

        public static DropAction getDropAction()
        Returns the current drop action.
        Returns:
        The drop action corresponding to the currently pressed modifier keys.
        See Also:
        DropAction.getDropAction(int)