Class SquidInput
java.lang.Object
com.badlogic.gdx.InputAdapter
com.github.yellowstonegames.press.SquidInput
- All Implemented Interfaces:
com.badlogic.gdx.InputProcessor
public class SquidInput
extends com.badlogic.gdx.InputAdapter
This input processing class can handle mouse and keyboard input, using a
This also allows some key remapping, including remapping so a key pressed with modifiers like Ctrl and Shift could act like '?' (which could be used by expert players to avoid accidentally opening a help menu they don't need), and that would free up '?' for some other use that could also be remapped. The remap() methods do much of this, often with help from
This does not perform any blocking functionality. To block game logic until an event has been received, check hasNext() in the game's render() method and effectively "block" by not running game logic if hasNext() returns false. You can process an event if hasNext() returns true by calling
SquidMouse for
Mouse input and a user implementation of SquidInput.KeyHandler (often a lambda) to react to keys represented as chars
and the modifiers those keys were pressed with, any of alt, ctrl, and/or shift. Not all keys are representable by
default in Unicode, so symbolic representations are stored in constants in this class, and are passed to
SquidInput.KeyHandler.handle(char, boolean, boolean, boolean) as chars like DOWN_ARROW or its value, '\u2193'. Shift
modifies the input as it would on a QWERTY keyboard, and the exact mapping is documented in
fromCode(int, boolean) as well. This class handles mouse input immediately, but stores keypresses in a
queue, storing all key events and allowing them to be processed one at a time using next() or all at once
using drain(). To have an effect, it needs to be registered by calling
Input.setInputProcessor(InputProcessor). Note that calling hasNext() does more than just check if
there are events that can be processed; because hasNext() is expected to be called frequently, it is also the point
where this class checks if a key is being held and so the next event should occur. Holding a key only causes the
keyDown() method of InputListener to be called once, so this uses hasNext() to see if there should be a next event
coming from a held key.
This also allows some key remapping, including remapping so a key pressed with modifiers like Ctrl and Shift could act like '?' (which could be used by expert players to avoid accidentally opening a help menu they don't need), and that would free up '?' for some other use that could also be remapped. The remap() methods do much of this, often with help from
combineModifiers(char, boolean, boolean, boolean), while the unmap() methods allow removal of
any no-longer-wanted remappings.
This does not perform any blocking functionality. To block game logic until an event has been received, check hasNext() in the game's render() method and effectively "block" by not running game logic if hasNext() returns false. You can process an event if hasNext() returns true by calling
next(). Mouse inputs do not affect hasNext(), and next() will process only key pressed events. Also, see
above about the extra behavior of hasNext regarding held keys.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA single-method interface used to process "typed" characters, special characters produced by unusual keys, and modifiers that can affect them. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final charBackspace key on most PC keyboards; Delete key on Mac keyboards.static final charNot typically a dedicated key, but if numpadDirections is enabled, this will be sent by Numpad 5.static final charDown arrow key.static final charNot typically a dedicated key, but if numpadDirections is enabled, this will be sent by Numpad 1.static final charNot typically a dedicated key, but if numpadDirections is enabled, this will be sent by Numpad 3.static final charEnd key (commonly used for moving a cursor to end of line).static final charEnter key, also called Return key.static final charEsc or Escape keystatic final charFunction key F1static final charFunction key F10static final charFunction key F11static final charFunction key F12static final charFunction key F2static final charFunction key F3static final charFunction key F4static final charFunction key F5static final charFunction key F6static final charFunction key F7static final charFunction key F8static final charFunction key F9static final charDelete key on most PC keyboards; no equivalent on some (all?) Mac keyboards.static final charGamepad A button.static final charGamepad B button.static final charGamepad C button.static final charGamepad L1 button.static final charGamepad L2 button.static final charGamepad Left Thumb button.static final charGamepad R1 button.static final charGamepad R2 button.static final charGamepad Right Thumb button.static final charGamepad Select button.static final charGamepad Start button.static final charGamepad X button.static final charGamepad Y button.static final charGamepad Z button.protected com.github.tommyettinger.ds.IntIntOrderedMapstatic final charHome key (commonly used for moving a cursor to start of line).protected booleanstatic final charInsert key.protected SquidInput.KeyHandlerprotected longstatic final charLeft arrow key.final com.github.tommyettinger.ds.IntIntMapprotected SquidMouseprotected booleanstatic final charPage Down key.static final charPage Up key.protected final com.github.tommyettinger.ds.IntDequeprotected longstatic final charDown arrow key.static final charTab key.static final charUp arrow key.static final charNot typically a dedicated key, but if numpadDirections is enabled, this will be sent by Numpad 7.static final charNot typically a dedicated key, but if numpadDirections is enabled, this will be sent by Numpad 9.static final charNot typically a dedicated key, but if numpadDirections is enabled, this will be sent by Numpad 0. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new SquidInput that does not respond to keyboard or mouse input.SquidInput(SquidInput.KeyHandler keyHandler) Constructs a new SquidInput that does not respond to mouse input, but does take keyboard input and sends keyboard events through some processing before calling keyHandler.handle() on keypresses that can sensibly be processed.SquidInput(SquidInput.KeyHandler keyHandler, boolean ignoreInput) Constructs a new SquidInput that does not respond to mouse input, but does take keyboard input and sends keyboard events through some processing before calling keyHandler.handle() on keypresses that can sensibly be processed.SquidInput(SquidInput.KeyHandler keyHandler, SquidMouse mouse) Constructs a new SquidInput that responds to mouse and keyboard input when given a SquidMouse and a SquidInput.KeyHandler implementation.SquidInput(SquidInput.KeyHandler keyHandler, SquidMouse mouse, boolean ignoreInput) Constructs a new SquidInput that responds to mouse and keyboard input when given a SquidMouse and a SquidInput.KeyHandler implementation, and can be put in an initial state where it ignores input until told otherwise via setIgnoreInput(boolean).SquidInput(SquidMouse mouse) Constructs a new SquidInput that does not respond to keyboard input, but does take mouse input and passes mouse events along to the given SquidMouse. -
Method Summary
Modifier and TypeMethodDescriptionRemoves any remappings to key bindings that were in use in this SquidInput.static intcombineModifiers(char key, boolean alt, boolean ctrl, boolean shift) Combines the key (as it would be given toSquidInput.KeyHandler.handle(char, boolean, boolean, boolean)) with the three booleans for the alt, ctrl, and shift modifier keys, returning an int that can be used with the internal queue of ints or the publicmappingof received inputs to actual inputs the program can process.voiddrain()Processes all events queued up, passing them through this object's key processing and then to keyHandler.voidflush()Empties the backing queue of data.charfromCode(int keycode, boolean shift) Maps keycodes to Unicode chars, sometimes depending on whether the Shift key is held.booleanGet the status for whether this should ignore input right now or not.getMouse()longGets the amount of milliseconds of holding a key this requires to count as a key repeat.booleanhasNext()Returns true if at least one event is queued, but also will callkeyDown(int)if a key is being held but there is a failure to process the repeated event.booleanbooleankeyDown(int keycode) keyMappingFromString(String keymap) Reads in a String (almost certainly produced bykeyMappingToString()) to set the current key remapping.Gets the current key remapping as a String, which can be saved in a file and read back withkeyMappingFromString(String).booleankeyTyped(char character) booleankeyUp(int keycode) booleanmouseMoved(int screenX, int screenY) voidnext()Processes the first key event queued up, passing it to this object's InputProcessor.remap(char pressedChar, boolean pressedAlt, boolean pressedCtrl, boolean pressedShift, char targetChar, boolean targetAlt, boolean targetCtrl, boolean targetShift) Remaps a char that could be input and processed bySquidInput.KeyHandler.handle(char, boolean, boolean, boolean)(possibly with some pressed modifiers) to another char with possible modifiers.remap(int[] pairs) Remaps many keypress combinations, each of which is a char and several potential modifiers, to other keypress combinations.remap(int pressed, int target) Remaps a keypress combination, which is a char and several potential modifiers, to another keypress combination.booleanscrolled(float amountX, float amountY) voidsetIgnoreInput(boolean ignoreInput) Set the status for whether this should ignore input right now or not.voidsetKeyHandler(SquidInput.KeyHandler keyHandler) voidsetMouse(SquidMouse mouse) voidsetRepeatGap(long time) Sets the amount of milliseconds of holding a key this requires to count as a key repeat.voidsetUsingNumpadDirections(boolean using) booleantouchDown(int screenX, int screenY, int pointer, int button) booleantouchDragged(int screenX, int screenY, int pointer) booleantouchUp(int screenX, int screenY, int pointer, int button) unmap(char pressedChar, boolean pressedAlt, boolean pressedCtrl, boolean pressedShift) Removes a keypress combination from the mapping by specifying the char and any modifiers that are part of the keypress combination.unmap(int pressed) Removes a keypress combination from the mapping by specifying the keypress combination as an int.Methods inherited from class com.badlogic.gdx.InputAdapter
touchCancelled
-
Field Details
-
keyAction
-
numpadDirections
protected boolean numpadDirections -
ignoreInput
protected boolean ignoreInput -
mouse
-
queue
protected final com.github.tommyettinger.ds.IntDeque queue -
lastKeyTime
protected long lastKeyTime -
heldCodes
protected com.github.tommyettinger.ds.IntIntOrderedMap heldCodes -
repeatGapMillis
protected long repeatGapMillis -
mapping
public final com.github.tommyettinger.ds.IntIntMap mapping -
LEFT_ARROW
public static final char LEFT_ARROWLeft arrow key. If numpadDirections is enabled, this will also be sent by Numpad 4.- See Also:
-
UP_ARROW
public static final char UP_ARROWUp arrow key. If numpadDirections is enabled, this will also be sent by Numpad 8.- See Also:
-
RIGHT_ARROW
public static final char RIGHT_ARROWDown arrow key. If numpadDirections is enabled, this will also be sent by Numpad 6.- See Also:
-
DOWN_ARROW
public static final char DOWN_ARROWDown arrow key. If numpadDirections is enabled, this will also be sent by Numpad 2.- See Also:
-
DOWN_LEFT_ARROW
public static final char DOWN_LEFT_ARROWNot typically a dedicated key, but if numpadDirections is enabled, this will be sent by Numpad 1.- See Also:
-
DOWN_RIGHT_ARROW
public static final char DOWN_RIGHT_ARROWNot typically a dedicated key, but if numpadDirections is enabled, this will be sent by Numpad 3.- See Also:
-
UP_RIGHT_ARROW
public static final char UP_RIGHT_ARROWNot typically a dedicated key, but if numpadDirections is enabled, this will be sent by Numpad 9.- See Also:
-
UP_LEFT_ARROW
public static final char UP_LEFT_ARROWNot typically a dedicated key, but if numpadDirections is enabled, this will be sent by Numpad 7.- See Also:
-
CENTER_ARROW
public static final char CENTER_ARROWNot typically a dedicated key, but if numpadDirections is enabled, this will be sent by Numpad 5.- See Also:
-
VERTICAL_ARROW
public static final char VERTICAL_ARROWNot typically a dedicated key, but if numpadDirections is enabled, this will be sent by Numpad 0.
Intended for games that might need up a jump or crouch button on the numpad that supplants movement.- See Also:
-
ENTER
public static final char ENTEREnter key, also called Return key. Used to start a new line of text or confirm entries in forms.- See Also:
-
TAB
public static final char TABTab key. Used for entering horizontal spacing, such as indentation, but also often to cycle between menu items.- See Also:
-
BACKSPACE
public static final char BACKSPACEBackspace key on most PC keyboards; Delete key on Mac keyboards. Used to delete the previous character.- See Also:
-
FORWARD_DELETE
public static final char FORWARD_DELETEDelete key on most PC keyboards; no equivalent on some (all?) Mac keyboards. Used to delete the next character.
Not present on some laptop keyboards and some (all?) Mac keyboards.- See Also:
-
INSERT
public static final char INSERTInsert key. Not recommended for common use because it could affect other application behavior.
Not present on some laptop keyboards.- See Also:
-
PAGE_DOWN
public static final char PAGE_DOWNPage Down key.
Not present on some laptop keyboards.- See Also:
-
PAGE_UP
public static final char PAGE_UPPage Up key.
Not present on some laptop keyboards.- See Also:
-
HOME
public static final char HOMEHome key (commonly used for moving a cursor to start of line).
Not present on some laptop keyboards.- See Also:
-
END
public static final char ENDEnd key (commonly used for moving a cursor to end of line).
Not present on some laptop keyboards.- See Also:
-
ESCAPE
public static final char ESCAPEEsc or Escape key- See Also:
-
F1
public static final char F1Function key F1- See Also:
-
F2
public static final char F2Function key F2- See Also:
-
F3
public static final char F3Function key F3- See Also:
-
F4
public static final char F4Function key F4- See Also:
-
F5
public static final char F5Function key F5- See Also:
-
F6
public static final char F6Function key F6- See Also:
-
F7
public static final char F7Function key F7- See Also:
-
F8
public static final char F8Function key F8- See Also:
-
F9
public static final char F9Function key F9- See Also:
-
F10
public static final char F10Function key F10- See Also:
-
F11
public static final char F11Function key F11- See Also:
-
F12
public static final char F12Function key F12- See Also:
-
GAMEPAD_A
public static final char GAMEPAD_AGamepad A button.- See Also:
-
GAMEPAD_B
public static final char GAMEPAD_BGamepad B button.- See Also:
-
GAMEPAD_C
public static final char GAMEPAD_CGamepad C button.- See Also:
-
GAMEPAD_X
public static final char GAMEPAD_XGamepad X button.- See Also:
-
GAMEPAD_Y
public static final char GAMEPAD_YGamepad Y button.- See Also:
-
GAMEPAD_Z
public static final char GAMEPAD_ZGamepad Z button.- See Also:
-
GAMEPAD_L1
public static final char GAMEPAD_L1Gamepad L1 button.- See Also:
-
GAMEPAD_L2
public static final char GAMEPAD_L2Gamepad L2 button.- See Also:
-
GAMEPAD_R1
public static final char GAMEPAD_R1Gamepad R1 button.- See Also:
-
GAMEPAD_R2
public static final char GAMEPAD_R2Gamepad R2 button.- See Also:
-
GAMEPAD_LEFT_THUMB
public static final char GAMEPAD_LEFT_THUMBGamepad Left Thumb button.- See Also:
-
GAMEPAD_RIGHT_THUMB
public static final char GAMEPAD_RIGHT_THUMBGamepad Right Thumb button.- See Also:
-
GAMEPAD_START
public static final char GAMEPAD_STARTGamepad Start button.- See Also:
-
GAMEPAD_SELECT
public static final char GAMEPAD_SELECTGamepad Select button.- See Also:
-
-
Constructor Details
-
SquidInput
public SquidInput()Constructs a new SquidInput that does not respond to keyboard or mouse input. These can be set later by calling setKeyHandler() to allow keyboard handling or setMouse() to allow mouse handling on a grid.
All SquidInput constructors must be called after theApplicationListener.create()method has started, and cannot be called in an ApplicationListener's constructor or in initialization at the class level. This is because all constructors attempt to load a file, if it exists, withGdx.files.local("keymap.preferences"), andGdx.filesis only available starting in create(). This file, keymap.preferences, is meant to contain any key remappings specified by the user, and its contents should be produced bykeyMappingToString()when any key mappings change and are saved. You can use your own filename, but keymap.preferences is the standard one and these can be exchanged between games (so common remappings for users of DVORAK or AZERTY keyboards can be sent between users even if they play different games). If you really want a custom filename, or to load the keymap from a larger user profile, you can give the contents tokeyMappingFromString(String)on a SquidInput after construction. -
SquidInput
Constructs a new SquidInput that does not respond to keyboard input, but does take mouse input and passes mouse events along to the given SquidMouse. The SquidMouse, even though it is an InputProcessor on its own, should not be registered by calling Input.setInputProcessor(SquidMouse), and instead this object should be registered by calling Input.setInputProcessor(SquidInput). The keyboard and mouse handling can be changed later by calling setKeyHandler() to allow keyboard handling or setMouse() to change mouse handling.
All SquidInput constructors must be called after theApplicationListener.create()method has started, and cannot be called in an ApplicationListener's constructor or in initialization at the class level. This is because all constructors attempt to load a file, if it exists, withGdx.files.local("keymap.preferences"), andGdx.filesis only available starting in create(). This file, keymap.preferences, is meant to contain any key remappings specified by the user, and its contents should be produced bykeyMappingToString()when any key mappings change and are saved. You can use your own filename, but keymap.preferences is the standard one and these can be exchanged between games (so common remappings for users of DVORAK or AZERTY keyboards can be sent between users even if they play different games). If you really want a custom filename, or to load the keymap from a larger user profile, you can give the contents tokeyMappingFromString(String)on a SquidInput after construction.- Parameters:
mouse- a SquidMouse instance that will be used for handling mouse input.
-
SquidInput
Constructs a new SquidInput that does not respond to mouse input, but does take keyboard input and sends keyboard events through some processing before calling keyHandler.handle() on keypresses that can sensibly be processed. Modifier keys do not go through the same processing but are checked for their current state when the key is pressed, and the states of alt, ctrl, and shift are passed to keyHandler.handle() as well. You can use setMouse() to allow mouse handling or change the KeyHandler with setKeyHandler().
All SquidInput constructors must be called after theApplicationListener.create()method has started, and cannot be called in an ApplicationListener's constructor or in initialization at the class level. This is because all constructors attempt to load a file, if it exists, withGdx.files.local("keymap.preferences"), andGdx.filesis only available starting in create(). This file, keymap.preferences, is meant to contain any key remappings specified by the user, and its contents should be produced bykeyMappingToString()when any key mappings change and are saved. You can use your own filename, but keymap.preferences is the standard one and these can be exchanged between games (so common remappings for users of DVORAK or AZERTY keyboards can be sent between users even if they play different games). If you really want a custom filename, or to load the keymap from a larger user profile, you can give the contents tokeyMappingFromString(String)on a SquidInput after construction.- Parameters:
keyHandler- must implement the SquidInput.KeyHandler interface so it can handle() key input.
-
SquidInput
Constructs a new SquidInput that does not respond to mouse input, but does take keyboard input and sends keyboard events through some processing before calling keyHandler.handle() on keypresses that can sensibly be processed. Modifier keys do not go through the same processing but are checked for their current state when the key is pressed, and the states of alt, ctrl, and shift are passed to keyHandler.handle() as well. You can use setMouse() to allow mouse handling or change the KeyHandler with setKeyHandler().
All SquidInput constructors must be called after theApplicationListener.create()method has started, and cannot be called in an ApplicationListener's constructor or in initialization at the class level. This is because all constructors attempt to load a file, if it exists, withGdx.files.local("keymap.preferences"), andGdx.filesis only available starting in create(). This file, keymap.preferences, is meant to contain any key remappings specified by the user, and its contents should be produced bykeyMappingToString()when any key mappings change and are saved. You can use your own filename, but keymap.preferences is the standard one and these can be exchanged between games (so common remappings for users of DVORAK or AZERTY keyboards can be sent between users even if they play different games). If you really want a custom filename, or to load the keymap from a larger user profile, you can give the contents tokeyMappingFromString(String)on a SquidInput after construction.- Parameters:
keyHandler- must implement the SquidInput.KeyHandler interface so it can handle() key input.ignoreInput- true if this should ignore input initially, false if it should process input normally.
-
SquidInput
Constructs a new SquidInput that responds to mouse and keyboard input when given a SquidMouse and a SquidInput.KeyHandler implementation. It sends keyboard events through some processing before calling keyHandler.handle() on keypresses that can sensibly be processed. Modifier keys do not go through the same processing but are checked for their current state when the key is pressed, and the states of alt, ctrl, and shift are passed to keyHandler.handle() as well. The SquidMouse, even though it is an InputProcessor on its own, should not be registered by calling Input.setInputProcessor(SquidMouse), and instead this object should be registered by calling Input.setInputProcessor(SquidInput). You can use setKeyHandler() or setMouse() to change keyboard or mouse handling.
All SquidInput constructors must be called after theApplicationListener.create()method has started, and cannot be called in an ApplicationListener's constructor or in initialization at the class level. This is because all constructors attempt to load a file, if it exists, withGdx.files.local("keymap.preferences"), andGdx.filesis only available starting in create(). This file, keymap.preferences, is meant to contain any key remappings specified by the user, and its contents should be produced bykeyMappingToString()when any key mappings change and are saved. You can use your own filename, but keymap.preferences is the standard one and these can be exchanged between games (so common remappings for users of DVORAK or AZERTY keyboards can be sent between users even if they play different games). If you really want a custom filename, or to load the keymap from a larger user profile, you can give the contents tokeyMappingFromString(String)on a SquidInput after construction.- Parameters:
keyHandler- must implement the SquidInput.KeyHandler interface so it can handle() key input.mouse- a SquidMouse instance that will be used for handling mouse input.
-
SquidInput
Constructs a new SquidInput that responds to mouse and keyboard input when given a SquidMouse and a SquidInput.KeyHandler implementation, and can be put in an initial state where it ignores input until told otherwise via setIgnoreInput(boolean). It sends keyboard events through some processing before calling keyHandler.handle() on keypresses that can sensibly be processed. Modifier keys do not go through the same processing but are checked for their current state when the key is pressed, and the states of alt, ctrl, and shift are passed to keyHandler.handle() as well. The SquidMouse, even though it is an InputProcessor on its own, should not be registered by calling Input.setInputProcessor(SquidMouse), and instead this object should be registered by calling Input.setInputProcessor(SquidInput). You can use setKeyHandler() or setMouse() to change keyboard or mouse handling.
All SquidInput constructors must be called after theApplicationListener.create()method has started, and cannot be called in an ApplicationListener's constructor or in initialization at the class level. This is because all constructors attempt to load a file, if it exists, withGdx.files.local("keymap.preferences"), andGdx.filesis only available starting in create(). This file, keymap.preferences, is meant to contain any key remappings specified by the user, and its contents should be produced bykeyMappingToString()when any key mappings change and are saved. You can use your own filename, but keymap.preferences is the standard one and these can be exchanged between games (so common remappings for users of DVORAK or AZERTY keyboards can be sent between users even if they play different games). If you really want a custom filename, or to load the keymap from a larger user profile, you can give the contents tokeyMappingFromString(String)on a SquidInput after construction.- Parameters:
keyHandler- must implement the SquidInput.KeyHandler interface so it can handle() key input.mouse- a SquidMouse instance that will be used for handling mouse input.ignoreInput- true if this should ignore input initially, false if it should process input normally.
-
-
Method Details
-
setKeyHandler
-
setMouse
-
isUsingNumpadDirections
public boolean isUsingNumpadDirections() -
setUsingNumpadDirections
public void setUsingNumpadDirections(boolean using) -
getKeyHandler
-
getMouse
-
getIgnoreInput
public boolean getIgnoreInput()Get the status for whether this should ignore input right now or not. True means this object will ignore and not queue input, false means it should process them normally. Useful to pause processing or delegate it to another object temporarily.- Returns:
- true if this object currently ignores input, false otherwise.
-
setIgnoreInput
public void setIgnoreInput(boolean ignoreInput) Set the status for whether this should ignore input right now or not. True means this object will ignore and not queue input, false means it should process them normally. Useful to pause processing or delegate it to another object temporarily.- Parameters:
ignoreInput- true if this should object should ignore and not queue input, false otherwise.
-
remap
public SquidInput remap(char pressedChar, boolean pressedAlt, boolean pressedCtrl, boolean pressedShift, char targetChar, boolean targetAlt, boolean targetCtrl, boolean targetShift) Remaps a char that could be input and processed bySquidInput.KeyHandler.handle(char, boolean, boolean, boolean)(possibly with some pressed modifiers) to another char with possible modifiers. When the first key/modifier mix is received, it will be translated to the second group in this method.- Parameters:
pressedChar- a source char that might be used in handling, like 'q', 'A', '7', '(', orUP_ARROW.pressedAlt- true if alt is part of the source combined keypress, false otherwisepressedCtrl- true if ctrl is part of the source combined keypress, false otherwisepressedShift- true if shift is part of the source combined keypress, false otherwisetargetChar- a target char that might be used in handling, like 'q', 'A', '7', '(', orUP_ARROW.targetAlt- true if alt is part of the target combined keypress, false otherwisetargetCtrl- true if ctrl is part of the target combined keypress, false otherwisetargetShift- true if shift is part of the target combined keypress, false otherwise- Returns:
- this for chaining
-
remap
Remaps a keypress combination, which is a char and several potential modifiers, to another keypress combination. When thepressedcombination is received, it will be translated totargetin this method.- Parameters:
pressed- an int for the source keypress, probably produced bycombineModifiers(char, boolean, boolean, boolean)target- an int for the target keypress, probably produced bycombineModifiers(char, boolean, boolean, boolean)- Returns:
- this for chaining
- See Also:
-
remap
Remaps many keypress combinations, each of which is a char and several potential modifiers, to other keypress combinations. When the first of a pair of combinations is received, it will be translated to the second combination of the pair.- Parameters:
pairs- an int array alternating source and target keypresses, each probably produced bycombineModifiers(char, boolean, boolean, boolean)- Returns:
- this for chaining
- See Also:
-
unmap
public SquidInput unmap(char pressedChar, boolean pressedAlt, boolean pressedCtrl, boolean pressedShift) Removes a keypress combination from the mapping by specifying the char and any modifiers that are part of the keypress combination. This combination will no longer be remapped, but the original handling will be the same.- Parameters:
pressedChar- a char that might be used in handling, like 'q', 'A', '7', '(', orUP_ARROW.pressedAlt- true if alt is part of the combined keypress, false otherwisepressedCtrl- true if ctrl is part of the combined keypress, false otherwisepressedShift- true if shift is part of the combined keypress, false otherwise- Returns:
- this for chaining
-
unmap
Removes a keypress combination from the mapping by specifying the keypress combination as an int. This combination will no longer be remapped, but the original handling will be the same.- Parameters:
pressed- an int for the source keypress, probably produced bycombineModifiers(char, boolean, boolean, boolean)- Returns:
- this for chaining
- See Also:
-
clearMapping
Removes any remappings to key bindings that were in use in this SquidInput.- Returns:
- this for chaining
-
combineModifiers
public static int combineModifiers(char key, boolean alt, boolean ctrl, boolean shift) Combines the key (as it would be given toSquidInput.KeyHandler.handle(char, boolean, boolean, boolean)) with the three booleans for the alt, ctrl, and shift modifier keys, returning an int that can be used with the internal queue of ints or the publicmappingof received inputs to actual inputs the program can process.- Parameters:
key- a char that might be used in handling, like 'q', 'A', '7', '(', orUP_ARROW.alt- true if alt is part of this combined keypress, false otherwisectrl- true if ctrl is part of this combined keypress, false otherwiseshift- true if shift is part of this combined keypress, false otherwise- Returns:
- an int that contains the information to represent the key with any modifiers as one value
-
keyMappingToString
Gets the current key remapping as a String, which can be saved in a file and read back withkeyMappingFromString(String). Because that method is automatically called by SquidInput's constructor and tries to load a file named "keymap.preferences" in the local folder, it is recommended that you save user-remapped keys to that file, but only if the user has actively changed them (that file could exist from an earlier run, and you don't want to affect it unless the user made some change). This will allow input with any of Shift, Alt, and Ctl modifiers in any script supported by the Unicode Basic Multilingual Plane (the first 65536 chars of Unicode).- Returns:
- a String that stores four chars per remapping.
-
keyMappingFromString
Reads in a String (almost certainly produced bykeyMappingToString()) to set the current key remapping. This is automatically called if a file named "keymap.preferences" is present in the local folder, receiving the contents of that file as a parameter, so games that want to save a user's preferences should try to save that file if possible (this also allows one file to be reused across multiple computers or installations by copying it). This will allow input with any of Shift, Alt, and Ctl modifiers in any script supported by the Unicode Basic Multilingual Plane (the first 65536 chars of Unicode). You may want to callclearMapping()before calling this if you have already set the mapping and want the String's contents to be used as the only mapping.- Parameters:
keymap- a String that was probably produced bykeyMappingToString()- Returns:
- this for chaining
-
drain
public void drain()Processes all events queued up, passing them through this object's key processing and then to keyHandler. Mouse events are not queued and are processed when they come in. -
getRepeatGap
public long getRepeatGap()Gets the amount of milliseconds of holding a key this requires to count as a key repeat. The default is 220.- Returns:
- how long a key needs to be held before this will count it as a key repeat, as a long in milliseconds
-
setRepeatGap
public void setRepeatGap(long time) Sets the amount of milliseconds of holding a key this requires to count as a key repeat. The default is 220.- Parameters:
time- how long a key needs to be held before this will count it as a key repeat, as a positive long in milliseconds
-
hasNext
public boolean hasNext()Returns true if at least one event is queued, but also will callkeyDown(int)if a key is being held but there is a failure to process the repeated event. The conditions this checks:- Is a key is currently being held?
- Are no modifier keys being held (shift, control, alt)? (without this check, the modifier key counts as a repeat of the key it modifies, which is probably never the intended behavior)
- Has
keyDown(int)already been called at least once? - Have there been at least
getRepeatGap()milliseconds between the last key being received and this call?
setRepeatGap(long), but the default of 220 ms is usually suitable. Too low of a value can cause normal key presses to be counted twice or more, and too high of a value may delay an expected key repeat.- Returns:
- true if there is an event queued, false otherwise
-
next
public void next()Processes the first key event queued up, passing it to this object's InputProcessor. Mouse events are not queued and are processed when they come in. -
flush
public void flush()Empties the backing queue of data. -
keyDown
public boolean keyDown(int keycode) - Specified by:
keyDownin interfacecom.badlogic.gdx.InputProcessor- Overrides:
keyDownin classcom.badlogic.gdx.InputAdapter
-
keyUp
public boolean keyUp(int keycode) - Specified by:
keyUpin interfacecom.badlogic.gdx.InputProcessor- Overrides:
keyUpin classcom.badlogic.gdx.InputAdapter
-
keyTyped
public boolean keyTyped(char character) - Specified by:
keyTypedin interfacecom.badlogic.gdx.InputProcessor- Overrides:
keyTypedin classcom.badlogic.gdx.InputAdapter
-
touchDown
public boolean touchDown(int screenX, int screenY, int pointer, int button) - Specified by:
touchDownin interfacecom.badlogic.gdx.InputProcessor- Overrides:
touchDownin classcom.badlogic.gdx.InputAdapter
-
touchUp
public boolean touchUp(int screenX, int screenY, int pointer, int button) - Specified by:
touchUpin interfacecom.badlogic.gdx.InputProcessor- Overrides:
touchUpin classcom.badlogic.gdx.InputAdapter
-
touchDragged
public boolean touchDragged(int screenX, int screenY, int pointer) - Specified by:
touchDraggedin interfacecom.badlogic.gdx.InputProcessor- Overrides:
touchDraggedin classcom.badlogic.gdx.InputAdapter
-
mouseMoved
public boolean mouseMoved(int screenX, int screenY) - Specified by:
mouseMovedin interfacecom.badlogic.gdx.InputProcessor- Overrides:
mouseMovedin classcom.badlogic.gdx.InputAdapter
-
scrolled
public boolean scrolled(float amountX, float amountY) - Specified by:
scrolledin interfacecom.badlogic.gdx.InputProcessor- Overrides:
scrolledin classcom.badlogic.gdx.InputAdapter
-
fromCode
public char fromCode(int keycode, boolean shift) Maps keycodes to Unicode chars, sometimes depending on whether the Shift key is held.
It is strongly recommended that you refer to key combinations regarding non-alphabet keys by using, for example, Ctrl-Shift-; instead of Ctrl-:, that is to use the unshifted key with Shift instead of assuming that all keyboards will use the QWERTY layout. Pressing shift while pressing just about any representable symbol will map to the shifted version as if on a QWERTY keyboard, and if you don't have a QWERTY keyboard, the mappings are documented in full below.
Keys 'a' to 'z' report 'A' to 'Z' when shift is held. Non-ASCII-Latin characters do not have this behavior, since most keyboards would be unable to send keys for a particular language and A-Z are very common. You can still allow a response to, e.g. 'ä' and 'Ä' separately by checking for whether Shift was pressed in conjunction with 'ä' on a keyboard with that key, which can be useful when users can configure their own keyboard layouts.
Top row numbers map as follows:
'1' to '!', '2' to '@', '3' to '#', '4' to '$', '5' to '%', '6' to '^', '7' to '&', '8' to '*', '9' to '(', '0' to ')'
Numpad numbers will report a SquidInput constant such as UP_LEFT_ARROW for Numpad 7, but only if numpadDirections is true; otherwise they send the number (here, 7). Numpad 0 sends VERTICAL_ARROW or 0.
Most symbol keys are mapped to a single Unicode char as a constant in SquidInput and disregard Shift. The constant is usually the same as the name of the char; possible exceptions are Backspace (on PC) or Delete (on Mac) mapping to BACKSPACE, Delete (on PC) mapping to FORWARD_DELETE, Esc mapping to ESCAPE, and Enter (on PC) or Return (on Mac) mapping to ENTER.
':', '*', '#', '@', and space keys, if present, always map to themselves, regardless of Shift.
Other characters map as follows when Shift is held, as they would on a QWERTY keyboard:','to'<''.'to'>''/'to'?'';'to':''\''to'"''['to'{'']'to'}''|'to'\\''-'to'_''+'to'=''`'to'~'(note, this key produces no event on the GWT backend)
- Parameters:
keycode- a keycode as passed by libGDXshift- true if Shift key is being held.- Returns:
- a char appropriate to the given keycode; often uses shift to capitalize or change a char, but not for keys like the arrow keys that normally don't produce chars
-