Class Input
public final class Input
extends java.lang.Object
- Since:
- 2.0.0
-
Field Summary
Fields Modifier and Type Field Description static int
AI_GAMEPAD_1
static int
AI_GAMEPAD_10
static int
AI_GAMEPAD_11
static int
AI_GAMEPAD_12
static int
AI_GAMEPAD_13
static int
AI_GAMEPAD_14
static int
AI_GAMEPAD_15
static int
AI_GAMEPAD_16
static int
AI_GAMEPAD_2
static int
AI_GAMEPAD_3
static int
AI_GAMEPAD_4
static int
AI_GAMEPAD_5
static int
AI_GAMEPAD_6
static int
AI_GAMEPAD_7
static int
AI_GAMEPAD_8
static int
AI_GAMEPAD_9
static int
KEY_MOUSE_COMBO
Special case value associated with theKeyMouseCombo
input device.static Widget
missingGamepad
A widget object provided by the engine that will be rendered anytime an input device is disconnected. -
Constructor Summary
Constructors Constructor Description Input()
-
Method Summary
Modifier and Type Method Description static void
bindPreviousPuppet(int deviceID)
Reverts the binding of an input device to its previous puppet object if it had one.static java.util.Map<Control,java.lang.Integer>
getDeviceControls(int deviceID)
Obtains the current control configuration of an input device.static boolean
getDeviceEnabled(int deviceID)
Checks whether or not an input device is currently allowing the engine to process its input actions.static java.lang.String
getDeviceName(int deviceID)
Obtains the name of an input device.static boolean
getDevicePresent(int deviceID)
Checks whether or not an input device is currently connected to the system.static Puppet
getDevicePuppet(int deviceID)
Obtains the current puppet object an input device is using (if any).static float
getDeviceSetting(int deviceID, java.lang.String name)
Obtains the value of some setting that an input device can use to adjust the responsiveness of input actions during gameplay.static java.lang.Character
getKeyChar(int key, int mods)
Obtains the letter/symbol of a keyboard key.static int[]
getKeyMouseAxisValues()
Obtains an array of values denoting which GLFW keys will be used by theKeyMouseCombo
input device to mimic the action of an analog stick.static int
getNumDevices()
Obtains the amount of input devices that are currently connected to the system.static void
revertEnabledState(int deviceID)
Reverts the enabled state of an input device to its previous value.static void
setDeviceControls(int deviceID, java.util.Map<Control,java.lang.Integer> config)
Sets the current control configuration of an input device.static void
setDeviceEnabled(int deviceID, boolean enabled)
Sets the current enabled state of an input device.static void
setDevicePuppet(int deviceID, Puppet puppet)
Sets the current puppet object an input device will control.static void
setDeviceSetting(int deviceID, java.lang.String name, float value)
Changes the setting value of the specified input device.static void
setKeyMouseAxisValues(int x1, int x2, int y1, int y2)
Sets the GLFW keys the keyboard will use to mimic the action of an analog stick.static void
setVirtualGamepadInput(int deviceID, Control control, float inputValue)
Changes the input value of a virtual gamepads control component.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
AI_GAMEPAD_1
public static final int AI_GAMEPAD_1- See Also:
- Constant Field Values
-
AI_GAMEPAD_2
public static final int AI_GAMEPAD_2- See Also:
- Constant Field Values
-
AI_GAMEPAD_3
public static final int AI_GAMEPAD_3- See Also:
- Constant Field Values
-
AI_GAMEPAD_4
public static final int AI_GAMEPAD_4- See Also:
- Constant Field Values
-
AI_GAMEPAD_5
public static final int AI_GAMEPAD_5- See Also:
- Constant Field Values
-
AI_GAMEPAD_6
public static final int AI_GAMEPAD_6- See Also:
- Constant Field Values
-
AI_GAMEPAD_7
public static final int AI_GAMEPAD_7- See Also:
- Constant Field Values
-
AI_GAMEPAD_8
public static final int AI_GAMEPAD_8- See Also:
- Constant Field Values
-
AI_GAMEPAD_9
public static final int AI_GAMEPAD_9- See Also:
- Constant Field Values
-
AI_GAMEPAD_10
public static final int AI_GAMEPAD_10- See Also:
- Constant Field Values
-
AI_GAMEPAD_11
public static final int AI_GAMEPAD_11- See Also:
- Constant Field Values
-
AI_GAMEPAD_12
public static final int AI_GAMEPAD_12- See Also:
- Constant Field Values
-
AI_GAMEPAD_13
public static final int AI_GAMEPAD_13- See Also:
- Constant Field Values
-
AI_GAMEPAD_14
public static final int AI_GAMEPAD_14- See Also:
- Constant Field Values
-
AI_GAMEPAD_15
public static final int AI_GAMEPAD_15- See Also:
- Constant Field Values
-
AI_GAMEPAD_16
public static final int AI_GAMEPAD_16- See Also:
- Constant Field Values
-
KEY_MOUSE_COMBO
public static final int KEY_MOUSE_COMBOSpecial case value associated with theKeyMouseCombo
input device.- See Also:
- Constant Field Values
-
missingGamepad
A widget object provided by the engine that will be rendered anytime an input device is disconnected. This object is left uninitialized by default so you will need to initialize it with your ownWidget
subclass for it to appear.
-
-
Constructor Details
-
Input
public Input()
-
-
Method Details
-
getNumDevices
public static int getNumDevices()Obtains the amount of input devices that are currently connected to the system. The value provided by this method includes only peripheral devices such as gamepads.- Returns:
- the number of connected input devices
-
getDevicePresent
public static boolean getDevicePresent(int deviceID)Checks whether or not an input device is currently connected to the system.NOTE: The keyboard/mouse along with virtual AI controlled gamepads are always connected by default.
- Parameters:
deviceID
- the number which corresponds to the input device in question. One of:GLFW_JOYSTICK_1
GLFW_JOYSTICK_2
GLFW_JOYSTICK_3
GLFW_JOYSTICK_4
- Returns:
- true if the input device is connected
-
getDeviceSetting
public static float getDeviceSetting(int deviceID, java.lang.String name)Obtains the value of some setting that an input device can use to adjust the responsiveness of input actions during gameplay.It's recommended that gameplay systems instead use
Command.getDeviceSetting(String)
and reserve this method for instances where the current value of the setting in question needs to be exposed to the user- such as an interface that allows the user to edit their devices preferences.NOTE: By default the engine provides deadzone settings for both the left and right analog sticks of each input device. These settings determine how much a stick will need to be moved before its input is recognized. The values of these settings can be queried with "leftDeadzone" and "rightDeadzone" respectively.
- Parameters:
deviceID
- the number which corresponds to the input device in question. One of:GLFW_JOYSTICK_1
GLFW_JOYSTICK_2
GLFW_JOYSTICK_3
GLFW_JOYSTICK_4
KEY_MOUSE_COMBO
name
- the name of the setting to parse a value from- Returns:
- the value of the setting or
NaN
if the device and/or setting could not be found
-
getDeviceEnabled
public static boolean getDeviceEnabled(int deviceID)Checks whether or not an input device is currently allowing the engine to process its input actions.- Parameters:
deviceID
- the number which corresponds to the input device in question. One of:GLFW_JOYSTICK_1
GLFW_JOYSTICK_2
GLFW_JOYSTICK_3
GLFW_JOYSTICK_4
KEY_MOUSE_COMBO
AI_GAMEPAD_1
AI_GAMEPAD_2
AI_GAMEPAD_3
AI_GAMEPAD_4
AI_GAMEPAD_5
AI_GAMEPAD_6
AI_GAMEPAD_7
AI_GAMEPAD_8
AI_GAMEPAD_9
AI_GAMEPAD_10
AI_GAMEPAD_11
AI_GAMEPAD_12
AI_GAMEPAD_13
AI_GAMEPAD_14
AI_GAMEPAD_15
AI_GAMEPAD_16
- Returns:
- true if the input device is in an enabled state
- See Also:
setDeviceEnabled(int,boolean)
-
getDeviceName
public static java.lang.String getDeviceName(int deviceID)Obtains the name of an input device.NOTE: Device names are not guaranteed to be unique and typically only reflect the model and/or manufacturer. This information can often help better identify a device, but shouldn't be used to refer to it.
- Parameters:
deviceID
- the number which corresponds to the input device in question. One of:GLFW_JOYSTICK_1
GLFW_JOYSTICK_2
GLFW_JOYSTICK_3
GLFW_JOYSTICK_4
KEY_MOUSE_COMBO
AI_GAMEPAD_1
AI_GAMEPAD_2
AI_GAMEPAD_3
AI_GAMEPAD_4
AI_GAMEPAD_5
AI_GAMEPAD_6
AI_GAMEPAD_7
AI_GAMEPAD_8
AI_GAMEPAD_9
AI_GAMEPAD_10
AI_GAMEPAD_11
AI_GAMEPAD_12
AI_GAMEPAD_13
AI_GAMEPAD_14
AI_GAMEPAD_15
AI_GAMEPAD_16
- Returns:
- a human-readable description of the input device
-
getDeviceControls
Obtains the current control configuration of an input device.Control configurations are user-defined input preferences that will be retained between runtime sessions. These configurations dictate how controls on an input device will be mapped to actions in game.
- Parameters:
deviceID
- the number which corresponds to the input device in question. One of:GLFW_JOYSTICK_1
GLFW_JOYSTICK_2
GLFW_JOYSTICK_3
GLFW_JOYSTICK_4
KEY_MOUSE_COMBO
- Returns:
- an immutable collection containing the current control configuration of an input device
- See Also:
setDeviceControls(int,java.util.Map<org.xjge.core.Control,java.lang.Integer>)
-
getKeyMouseAxisValues
public static int[] getKeyMouseAxisValues()Obtains an array of values denoting which GLFW keys will be used by theKeyMouseCombo
input device to mimic the action of an analog stick.- Returns:
- an array containing the axis values corresponding to various GLFW keyboard keys
- See Also:
setKeyMouseAxisValues(int,int,int,int)
-
getDevicePuppet
Obtains the current puppet object an input device is using (if any).- Parameters:
deviceID
- the number which corresponds to the input device in question. One of:GLFW_JOYSTICK_1
GLFW_JOYSTICK_2
GLFW_JOYSTICK_3
GLFW_JOYSTICK_4
KEY_MOUSE_COMBO
AI_GAMEPAD_1
AI_GAMEPAD_2
AI_GAMEPAD_3
AI_GAMEPAD_4
AI_GAMEPAD_5
AI_GAMEPAD_6
AI_GAMEPAD_7
AI_GAMEPAD_8
AI_GAMEPAD_9
AI_GAMEPAD_10
AI_GAMEPAD_11
AI_GAMEPAD_12
AI_GAMEPAD_13
AI_GAMEPAD_14
AI_GAMEPAD_15
AI_GAMEPAD_16
- Returns:
- the current puppet object of the specified input device or null if no puppet object is bound/the device cannot be found
-
getKeyChar
public static java.lang.Character getKeyChar(int key, int mods)Obtains the letter/symbol of a keyboard key.NOTE: This method assumes that the keyboard producing the input is an unmodified english model. As such, the letter/symbol of the key in question must correspond to an ASCII character between the ranges of 32-127, any characters outside of this range will return null.
- Parameters:
key
- the value supplied by GLFW of a single key on the keyboardmods
- a value supplied by GLFW denoting whether any mod keys where held (such as shift or control)- Returns:
- a character corresponding to the pressed key or null if one cannot be found
-
setDeviceSetting
public static void setDeviceSetting(int deviceID, java.lang.String name, float value)Changes the setting value of the specified input device.This method can also be used to provide additional settings the implementation may require from input devices. To achieve this, simply pass the value obtained from
getDeviceSetting(int,java.lang.String)
to thevalue
argument of this method and it will be retained between runtime sessions.For example, you might do something like this:
XJGE.init()... float prevValue = Input.getDeviceSetting(KEY_MOUSE_COMBO, "settingName"); Input.setDeviceSetting(KEY_MOUSE_COMBO, "settingName", prevValue); XJGE.start()...
- Parameters:
deviceID
- the number which corresponds to the input device in question. One of:GLFW_JOYSTICK_1
GLFW_JOYSTICK_2
GLFW_JOYSTICK_3
GLFW_JOYSTICK_4
KEY_MOUSE_COMBO
name
- the name of the setting that will be changedvalue
- the new value to change the setting to- See Also:
getDeviceSetting(int,java.lang.String)
-
setDeviceEnabled
public static void setDeviceEnabled(int deviceID, boolean enabled)Sets the current enabled state of an input device.- Parameters:
deviceID
- the number which corresponds to the input device in question. One of:GLFW_JOYSTICK_1
GLFW_JOYSTICK_2
GLFW_JOYSTICK_3
GLFW_JOYSTICK_4
KEY_MOUSE_COMBO
AI_GAMEPAD_1
AI_GAMEPAD_2
AI_GAMEPAD_3
AI_GAMEPAD_4
AI_GAMEPAD_5
AI_GAMEPAD_6
AI_GAMEPAD_7
AI_GAMEPAD_8
AI_GAMEPAD_9
AI_GAMEPAD_10
AI_GAMEPAD_11
AI_GAMEPAD_12
AI_GAMEPAD_13
AI_GAMEPAD_14
AI_GAMEPAD_15
AI_GAMEPAD_16
enabled
- if true, the device will allow the engine to process its input actions- See Also:
getDeviceEnabled(int)
-
revertEnabledState
public static void revertEnabledState(int deviceID)Reverts the enabled state of an input device to its previous value. This is useful in the case of an event or cutscene where the players input device may have been temporarily disabled.- Parameters:
deviceID
- the number which corresponds to the input device in question. One of:GLFW_JOYSTICK_1
GLFW_JOYSTICK_2
GLFW_JOYSTICK_3
GLFW_JOYSTICK_4
KEY_MOUSE_COMBO
AI_GAMEPAD_1
AI_GAMEPAD_2
AI_GAMEPAD_3
AI_GAMEPAD_4
AI_GAMEPAD_5
AI_GAMEPAD_6
AI_GAMEPAD_7
AI_GAMEPAD_8
AI_GAMEPAD_9
AI_GAMEPAD_10
AI_GAMEPAD_11
AI_GAMEPAD_12
AI_GAMEPAD_13
AI_GAMEPAD_14
AI_GAMEPAD_15
AI_GAMEPAD_16
-
setDeviceControls
public static void setDeviceControls(int deviceID, java.util.Map<Control,java.lang.Integer> config)Sets the current control configuration of an input device.NOTE: When setting the configuration of controls
LEFT_STICK_X
andLEFT_STICK_Y
for theKeyMouseCombo
input device, a bitwise OR (symbolized as |) should be used to pass two values representing the GLFW keyboard keys that will be used to move the analog stick along a single axis.For example, you might do something like this:
var keyMouseConfig = new HashMap() {{ ... put(LEFT_STICK_X, GLFW_KEY_A | GLFW_KEY_D); put(LEFT_STICK_Y, GLFW_KEY_W | GLFW_KEY_S); ... }};
- Parameters:
deviceID
- the number which corresponds to the input device in question. One of:GLFW_JOYSTICK_1
GLFW_JOYSTICK_2
GLFW_JOYSTICK_3
GLFW_JOYSTICK_4
KEY_MOUSE_COMBO
config
- the collection containing the new control configuration to apply- See Also:
getDeviceControls(int)
-
setKeyMouseAxisValues
public static void setKeyMouseAxisValues(int x1, int x2, int y1, int y2)Sets the GLFW keys the keyboard will use to mimic the action of an analog stick. Typically you'd use this anytime the player wishes to use a key combination other than WASD to move (in first person for example).- Parameters:
x1
- the GLFW key used to move left along the x-axisx2
- the GLFW key used to move right along the x-axisy1
- the GLFW key used to move down along the y-axisy2
- the GLFW key that to move up along the y-axis- See Also:
getKeyMouseAxisValues()
-
setDevicePuppet
Sets the current puppet object an input device will control.- Parameters:
deviceID
- the number which corresponds to the input device in question. One of:GLFW_JOYSTICK_1
GLFW_JOYSTICK_2
GLFW_JOYSTICK_3
GLFW_JOYSTICK_4
KEY_MOUSE_COMBO
AI_GAMEPAD_1
AI_GAMEPAD_2
AI_GAMEPAD_3
AI_GAMEPAD_4
AI_GAMEPAD_5
AI_GAMEPAD_6
AI_GAMEPAD_7
AI_GAMEPAD_8
AI_GAMEPAD_9
AI_GAMEPAD_10
AI_GAMEPAD_11
AI_GAMEPAD_12
AI_GAMEPAD_13
AI_GAMEPAD_14
AI_GAMEPAD_15
AI_GAMEPAD_16
puppet
- the puppet object the input device will use- See Also:
getDevicePuppet(int)
-
bindPreviousPuppet
public static void bindPreviousPuppet(int deviceID)Reverts the binding of an input device to its previous puppet object if it had one. This is useful in instances such as vehicles where the player may assume control of a puppet temporarily before switching back to their main binding.- Parameters:
deviceID
- the number which corresponds to the input device in question. One of:GLFW_JOYSTICK_1
GLFW_JOYSTICK_2
GLFW_JOYSTICK_3
GLFW_JOYSTICK_4
KEY_MOUSE_COMBO
AI_GAMEPAD_1
AI_GAMEPAD_2
AI_GAMEPAD_3
AI_GAMEPAD_4
AI_GAMEPAD_5
AI_GAMEPAD_6
AI_GAMEPAD_7
AI_GAMEPAD_8
AI_GAMEPAD_9
AI_GAMEPAD_10
AI_GAMEPAD_11
AI_GAMEPAD_12
AI_GAMEPAD_13
AI_GAMEPAD_14
AI_GAMEPAD_15
AI_GAMEPAD_16
-
setVirtualGamepadInput
Changes the input value of a virtual gamepads control component. Use this if you'd like to hook up an AI to an existing puppet object.- Parameters:
deviceID
- the number which corresponds to the input device in question. One of:control
- a component such as a button whos input value will be changedinputValue
- the input value denoting to what extent the control was manipulated or zero if not at all
-