Class VirtualKey

  • All Implemented Interfaces:

    
    public final class VirtualKey
    
                        

    A virtual key represents a physical key on the keyboard. It's not the character generated by pressing the key.

    Since the input device isn't a physical keyboard, but is instead a virtual keyboard, the virtual key will be set by the browser to match as closely as possible to what would happen with a physical keyboard, to maximize compatibility between physical and virtual input devices.

    • Method Detail

      • getKey

         final String getKey()

        The VirtualKey.key of the key pressed by the user, taking into consideration the state of modifier keys such as Shift as well as the keyboard locale and layout.

        Examples: "a", "b", "A", "B", "1", "2", "3", "Shift", "Enter", ...

      • setKey

         final Unit setKey(String key)

        The VirtualKey.key of the key pressed by the user, taking into consideration the state of modifier keys such as Shift as well as the keyboard locale and layout.

        Examples: "a", "b", "A", "B", "1", "2", "3", "Shift", "Enter", ...

      • getKeyCodeWithoutLocation

         final Integer getKeyCodeWithoutLocation()

        Represents a system and implementation dependent numerical code identifying the unmodified value of the pressed key.

        Note: The key code is a numeric value that represents a physical key on the keyboard. It's not the character.

        Key code examples: 13, 65, 51, ...

        You should avoid using this if possible; it's been deprecated for some time. Instead, you should use code if available. Codes are more reliable than key codes, because they are not affected by layout. Code example: "KeyA", "Digit3", "Enter", ...

      • setKeyCodeWithoutLocation

         final Unit setKeyCodeWithoutLocation(Integer keyCodeWithoutLocation)

        Represents a system and implementation dependent numerical code identifying the unmodified value of the pressed key.

        Note: The key code is a numeric value that represents a physical key on the keyboard. It's not the character.

        Key code examples: 13, 65, 51, ...

        You should avoid using this if possible; it's been deprecated for some time. Instead, you should use code if available. Codes are more reliable than key codes, because they are not affected by layout. Code example: "KeyA", "Digit3", "Enter", ...

      • getCode

         final String getCode()

        The VirtualKey.code property represents a physical key on the keyboard (as opposed to the character generated by pressing the key). In other words, this property returns a value that isn't altered by keyboard layout or the state of the modifier keys.

        If the input device isn't a physical keyboard, but is instead a virtual keyboard or accessibility device, the returned value will be set by the browser to match as closely as possible to what would happen with a physical keyboard, to maximize compatibility between physical and virtual input devices.

        For example, the code returned is "KeyQ" for the Q key on a QWERTY layout keyboard. Code example: "KeyA", "Digit3", "Enter", ...

      • setCode

         final Unit setCode(String code)

        The VirtualKey.code property represents a physical key on the keyboard (as opposed to the character generated by pressing the key). In other words, this property returns a value that isn't altered by keyboard layout or the state of the modifier keys.

        If the input device isn't a physical keyboard, but is instead a virtual keyboard or accessibility device, the returned value will be set by the browser to match as closely as possible to what would happen with a physical keyboard, to maximize compatibility between physical and virtual input devices.

        For example, the code returned is "KeyQ" for the Q key on a QWERTY layout keyboard. Code example: "KeyA", "Digit3", "Enter", ...

      • getLocation

         final Integer getLocation()

        The VirtualKey.location read-only property returns an unsigned long representing the location of the key on the keyboard or other input device.

      • getKeyCode

         final Integer getKeyCode()

        The deprecated VirtualKey.keyCode property represents a system and implementation dependent numerical code identifying the unmodified value of the pressed key.

        Note: The key code is a numeric value that represents a physical key on the keyboard. It's not the character.

        Key code examples: 13, 65, 51, ...

        You should avoid using this if possible; it's been deprecated for some time. Instead, you should use code if available. Codes are more reliable than key codes, because they are not affected by layout.

      • setKeyCode

         final Unit setKeyCode(Integer keyCode)

        The deprecated VirtualKey.keyCode property represents a system and implementation dependent numerical code identifying the unmodified value of the pressed key.

        Note: The key code is a numeric value that represents a physical key on the keyboard. It's not the character.

        Key code examples: 13, 65, 51, ...

        You should avoid using this if possible; it's been deprecated for some time. Instead, you should use code if available. Codes are more reliable than key codes, because they are not affected by layout.

      • getText

         final String getText()

        Returns the value of the key pressed by the user. If the key is a printable character, this property returns the character.

      • setText

         final Unit setText(String text)

        Returns the value of the key pressed by the user. If the key is a printable character, this property returns the character.