Package playn.core

Class Input

java.lang.Object
playn.core.Input

public class Input extends Object
Provides information about user input: mouse, touch, and keyboard. This class provides the platform-specific code, and events are dispatched via the platform-independent Mouse, Touch and Keyboard classes.
  • Field Details

    • mouseEnabled

      public boolean mouseEnabled
      Enables or disables mouse interaction. No mouse events will be dispatched whilst this big switch is in the off position.
    • touchEnabled

      public boolean touchEnabled
      Enables or disables touch interaction. No touch events will be dispatched whilst this big switch is in the off position.
    • keyboardEnabled

      public boolean keyboardEnabled
      Enables or disables keyboard interaction. No keyboard events will be dispatched whilst this big switch is in the off position.
    • mouseEvents

      public Signal<Mouse.Event> mouseEvents
      A signal which emits mouse events.
    • touchEvents

      public Signal<Touch.Event[]> touchEvents
      A signal via which touch events are emitted.
    • keyboardEvents

      public Signal<Keyboard.Event> keyboardEvents
      A signal via which keyboard events are emitted.
    • focus

      public Signal<Boolean> focus
      A signal emitted when the game application gains or loses focus.
  • Method Details

    • hasMouse

      public boolean hasMouse()
      Returns true if this platform has mouse input.
    • hasTouch

      public boolean hasTouch()
      Returns true if this platform has touch input.
    • hasHardwareKeyboard

      public boolean hasHardwareKeyboard()
      Returns true if this device has a hardware keyboard, false if not. Devices that lack a hardware keyboard will generally not generate keyboard events. Older Android devices that support four hardware buttons are an exception. Use getText(playn.core.Keyboard.TextType, java.lang.String, java.lang.String) for text entry on a non-hardware-keyboard having device.
    • hasMouseLock

      public boolean hasMouseLock()
      Returns true if this platform supports mouse locking. The user may still block it when it is requested, or detection may be broken for some browsers.
    • isMouseLocked

      public boolean isMouseLocked()
      Returns whether the mouse is currently locked.
    • setMouseLocked

      public void setMouseLocked(boolean locked)
      Lock or unlock the mouse. When the mouse is locked, mouse events are still received even when the pointer leaves the game window.
    • getText

      public RFuture<String> getText(Keyboard.TextType textType, String label, String initialValue)
      Requests a line of text from the user. On platforms that have only a virtual keyboard, this will display a text entry interface, obtain the line of text, and dismiss the text entry interface when finished.
      Parameters:
      textType - the expected type of text. On mobile devices this hint may be used to display a keyboard customized to the particular type of text.
      label - a label to display over the text entry interface, may be null.
      initialValue - the initial value to display in the text input field, may be null.
      Returns:
      a future which provides the text when it becomes available. If the user cancels the text entry process, null is supplied. Otherwise the entered text is supplied.
    • getText

      public RFuture<String> getText(Keyboard.TextType textType, String label, String initialValue, String ok, String cancel)
      Requests a line of text from the user. On platforms that have only a virtual keyboard, this will display a text entry interface, obtain the line of text, and dismiss the text entry interface when finished. Note that HTML5 and some Java backends do not support customization of the OK and Cancel labels. Thus those platforms will ignore the supplied labels and use their mandatory labels.
      Parameters:
      textType - the expected type of text. On mobile devices this hint may be used to display a keyboard customized to the particular type of text.
      label - a label to display over the text entry interface, may be null.
      initialValue - the initial value to display in the text input field, may be null.
      ok - the text of the button which will deliver a true result and be placed in "OK" position for the platform.
      cancel - the text of the button that will deliver a false result and be placed in "Cancel" position.
      Returns:
      a future which provides the text when it becomes available. If the user cancels the text entry process, null is supplied. Otherwise the entered text is supplied.
    • sysDialog

      public RFuture<Boolean> sysDialog(String title, String text, String ok, String cancel)
      Displays a system dialog with the specified title and text, an OK button and optionally a Cancel button.
      Parameters:
      title - the title for the dialog window. Note: some platforms (mainly mobile) do not display the title, so be sure your dialog makes sense if only text is showing.
      text - the text of the dialog. The text will be wrapped by the underlying platform, but PlayN will do its utmost to ensure that newlines are honored by the platform in question so that hard line breaks and blank lines are reproduced correctly.
      ok - the text of the button which will deliver a true result and be placed in "OK" position for the platform. Note: the HTML platform does not support customizing this label, so on that platform the label will be "OK". Yay for HTML5.
      cancel - the text of the button that will deliver a false result and be placed in "Cancel" position. If null is supplied, the dialog will only have an OK button. Note: the HTML platform does not support customizing this label, so on that platform a non-null cancel string will result in the button reading "Cancel". Yay for HTML5.
      Returns:
      a future which delivers true or false when the user clicks the OK or cancel buttons respectively. If some unexpected error occurs displaying the dialog (unlikley), it will be reported by failing the future.