Package squidpony.squidgrid.gui.gdx
Class SquidInput
java.lang.Object
com.badlogic.gdx.InputAdapter
squidpony.squidgrid.gui.gdx.SquidInput
- All Implemented Interfaces:
com.badlogic.gdx.InputProcessor
- Direct Known Subclasses:
VisualInput
public class SquidInput extends com.badlogic.gdx.InputAdapter
This input processing class can handle mouse and keyboard input, using a squidpony.squidgrid.gui.gdx.SquidMouse for
Mouse input and a user implementation of the SquidInput.KeyHandler interface 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
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
It does not perform the blocking functionality of earlier SquidKey implementations, because this is meant to run in an event-driven libGDX game and should not step on the toes of libGDX's input handling. 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
SquidInput.KeyHandler.handle(char, boolean, boolean, boolean) as chars like DOWN_ARROW or its value, '↓'. 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.
It does not perform the blocking functionality of earlier SquidKey implementations, because this is meant to run in an event-driven libGDX game and should not step on the toes of libGDX's input handling. 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.- Author:
- Eben Howard - http://squidpony.com - howard@squidpony.com, Nathan Sweet, Tommy Ettinger
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceSquidInput.KeyHandlerA single-method interface used to process "typed" characters, special characters produced by unusual keys, and modifiers that can affect them. -
Field Summary
Fields Modifier and Type Field Description static charBACKSPACEBackspace key on most PC keyboards; Delete key on Mac keyboards.static charCENTER_ARROWNot typically a dedicated key, but if numpadDirections is enabled, this will be sent by Numpad 5.static charDOWN_ARROWDown arrow key.static charDOWN_LEFT_ARROWNot typically a dedicated key, but if numpadDirections is enabled, this will be sent by Numpad 1.static charDOWN_RIGHT_ARROWNot typically a dedicated key, but if numpadDirections is enabled, this will be sent by Numpad 3.static charENDEnd key (commonly used for moving a cursor to end of line).static charENTEREnter key, also called Return key.static charESCAPEEsc or Escape keystatic charF1Function key F1static charF10Function key F10static charF11Function key F11static charF12Function key F12static charF2Function key F2static charF3Function key F3static charF4Function key F4static charF5Function key F5static charF6Function key F6static charF7Function key F7static charF8Function key F8static charF9Function key F9static charFORWARD_DELETEDelete key on most PC keyboards; no equivalent on some (all?) Mac keyboards.static charGAMEPAD_AGamepad A button.static charGAMEPAD_BGamepad B button.static charGAMEPAD_CGamepad C button.static charGAMEPAD_L1Gamepad L1 button.static charGAMEPAD_L2Gamepad L2 button.static charGAMEPAD_LEFT_THUMBGamepad Left Thumb button.static charGAMEPAD_R1Gamepad R1 button.static charGAMEPAD_R2Gamepad R2 button.static charGAMEPAD_RIGHT_THUMBGamepad Right Thumb button.static charGAMEPAD_SELECTGamepad Select button.static charGAMEPAD_STARTGamepad Start button.static charGAMEPAD_XGamepad X button.static charGAMEPAD_YGamepad Y button.static charGAMEPAD_ZGamepad Z button.protected IntIntOrderedMapheldCodesstatic charHOMEHome key (commonly used for moving a cursor to start of line).protected booleanignoreInputstatic charINSERTInsert key.protected SquidInput.KeyHandlerkeyActionprotected longlastKeyTimestatic charLEFT_ARROWLeft arrow key.com.badlogic.gdx.utils.IntIntMapmappingprotected SquidMousemouseprotected booleannumpadDirectionsstatic charPAGE_DOWNPage Down key.static charPAGE_UPPage Up key.protected IntVLAqueueprotected longrepeatGapMillisstatic charRIGHT_ARROWDown arrow key.static charTABTab key.static charUP_ARROWUp arrow key.static charUP_LEFT_ARROWNot typically a dedicated key, but if numpadDirections is enabled, this will be sent by Numpad 7.static charUP_RIGHT_ARROWNot typically a dedicated key, but if numpadDirections is enabled, this will be sent by Numpad 9.static charVERTICAL_ARROWNot typically a dedicated key, but if numpadDirections is enabled, this will be sent by Numpad 0. -
Constructor Summary
Constructors Constructor Description SquidInput()Constructs 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 Type Method Description SquidInputclearMapping()Removes 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.booleangetIgnoreInput()Get the status for whether this should ignore input right now or not.SquidInput.KeyHandlergetKeyHandler()SquidMousegetMouse()longgetRepeatGap()Gets 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.booleanisUsingNumpadDirections()booleankeyDown(int keycode)SquidInputkeyMappingFromString(String keymap)Reads in a String (almost certainly produced bykeyMappingToString()) to set the current key remapping.StringkeyMappingToString()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.SquidInputremap(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.SquidInputremap(int[] pairs)Remaps many keypress combinations, each of which is a char and several potential modifiers, to other keypress combinations.SquidInputremap(int pressed, int target)Remaps a keypress combination, which is a char and several potential modifiers, to another keypress combination.booleanscrolled(int amount)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)SquidInputunmap(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.SquidInputunmap(int pressed)Removes a keypress combination from the mapping by specifying the keypress combination as an int.
-
Field Details
-
keyAction
-
numpadDirections
-
ignoreInput
-
mouse
-
queue
-
lastKeyTime
-
heldCodes
-
repeatGapMillis
-
mapping
-
LEFT_ARROW
Left arrow key. If numpadDirections is enabled, this will also be sent by Numpad 4.- See Also:
- Constant Field Values
-
UP_ARROW
Up arrow key. If numpadDirections is enabled, this will also be sent by Numpad 8.- See Also:
- Constant Field Values
-
RIGHT_ARROW
Down arrow key. If numpadDirections is enabled, this will also be sent by Numpad 6.- See Also:
- Constant Field Values
-
DOWN_ARROW
Down arrow key. If numpadDirections is enabled, this will also be sent by Numpad 2.- See Also:
- Constant Field Values
-
DOWN_LEFT_ARROW
Not typically a dedicated key, but if numpadDirections is enabled, this will be sent by Numpad 1.- See Also:
- Constant Field Values
-
DOWN_RIGHT_ARROW
Not typically a dedicated key, but if numpadDirections is enabled, this will be sent by Numpad 3.- See Also:
- Constant Field Values
-
UP_RIGHT_ARROW
Not typically a dedicated key, but if numpadDirections is enabled, this will be sent by Numpad 9.- See Also:
- Constant Field Values
-
UP_LEFT_ARROW
Not typically a dedicated key, but if numpadDirections is enabled, this will be sent by Numpad 7.- See Also:
- Constant Field Values
-
CENTER_ARROW
Not typically a dedicated key, but if numpadDirections is enabled, this will be sent by Numpad 5.- See Also:
- Constant Field Values
-
VERTICAL_ARROW
Not 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:
- Constant Field Values
-
ENTER
Enter key, also called Return key. Used to start a new line of text or confirm entries in forms.- See Also:
- Constant Field Values
-
TAB
Tab key. Used for entering horizontal spacing, such as indentation, but also often to cycle between menu items.- See Also:
- Constant Field Values
-
BACKSPACE
Backspace key on most PC keyboards; Delete key on Mac keyboards. Used to delete the previous character.- See Also:
- Constant Field Values
-
FORWARD_DELETE
Delete 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:
- Constant Field Values
-
INSERT
Insert key. Not recommended for common use because it could affect other application behavior. Not present on some laptop keyboards.- See Also:
- Constant Field Values
-
PAGE_DOWN
Page Down key. Not present on some laptop keyboards.- See Also:
- Constant Field Values
-
PAGE_UP
Page Up key. Not present on some laptop keyboards.- See Also:
- Constant Field Values
-
HOME
Home key (commonly used for moving a cursor to start of line). Not present on some laptop keyboards.- See Also:
- Constant Field Values
-
END
End key (commonly used for moving a cursor to end of line). Not present on some laptop keyboards.- See Also:
- Constant Field Values
-
ESCAPE
Esc or Escape key- See Also:
- Constant Field Values
-
F1
Function key F1- See Also:
- Constant Field Values
-
F2
Function key F2- See Also:
- Constant Field Values
-
F3
Function key F3- See Also:
- Constant Field Values
-
F4
Function key F4- See Also:
- Constant Field Values
-
F5
Function key F5- See Also:
- Constant Field Values
-
F6
Function key F6- See Also:
- Constant Field Values
-
F7
Function key F7- See Also:
- Constant Field Values
-
F8
Function key F8- See Also:
- Constant Field Values
-
F9
Function key F9- See Also:
- Constant Field Values
-
F10
Function key F10- See Also:
- Constant Field Values
-
F11
Function key F11- See Also:
- Constant Field Values
-
F12
Function key F12- See Also:
- Constant Field Values
-
GAMEPAD_A
Gamepad A button.- See Also:
- Constant Field Values
-
GAMEPAD_B
Gamepad B button.- See Also:
- Constant Field Values
-
GAMEPAD_C
Gamepad C button.- See Also:
- Constant Field Values
-
GAMEPAD_X
Gamepad X button.- See Also:
- Constant Field Values
-
GAMEPAD_Y
Gamepad Y button.- See Also:
- Constant Field Values
-
GAMEPAD_Z
Gamepad Z button.- See Also:
- Constant Field Values
-
GAMEPAD_L1
Gamepad L1 button.- See Also:
- Constant Field Values
-
GAMEPAD_L2
Gamepad L2 button.- See Also:
- Constant Field Values
-
GAMEPAD_R1
Gamepad R1 button.- See Also:
- Constant Field Values
-
GAMEPAD_R2
Gamepad R2 button.- See Also:
- Constant Field Values
-
GAMEPAD_LEFT_THUMB
Gamepad Left Thumb button.- See Also:
- Constant Field Values
-
GAMEPAD_RIGHT_THUMB
Gamepad Right Thumb button.- See Also:
- Constant Field Values
-
GAMEPAD_START
Gamepad Start button.- See Also:
- Constant Field Values
-
GAMEPAD_SELECT
Gamepad Select button.- See Also:
- Constant Field Values
-
-
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
-
setUsingNumpadDirections
-
getKeyHandler
-
getMouse
-
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
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:
combineModifiers is usually used to make pressed and target
-
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:
combineModifiers is usually used to make the contents of pairs
-
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:
combineModifiers is usually used to make pressed
-
clearMapping
Removes any remappings to key bindings that were in use in this SquidInput.- Returns:
- this for chaining
-
combineModifiers
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
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
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
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
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
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
Empties the backing queue of data. -
keyDown
- Specified by:
keyDownin interfacecom.badlogic.gdx.InputProcessor- Overrides:
keyDownin classcom.badlogic.gdx.InputAdapter
-
keyUp
- Specified by:
keyUpin interfacecom.badlogic.gdx.InputProcessor- Overrides:
keyUpin classcom.badlogic.gdx.InputAdapter
-
keyTyped
- Specified by:
keyTypedin interfacecom.badlogic.gdx.InputProcessor- Overrides:
keyTypedin classcom.badlogic.gdx.InputAdapter
-
touchDown
- Specified by:
touchDownin interfacecom.badlogic.gdx.InputProcessor- Overrides:
touchDownin classcom.badlogic.gdx.InputAdapter
-
touchUp
- Specified by:
touchUpin interfacecom.badlogic.gdx.InputProcessor- Overrides:
touchUpin classcom.badlogic.gdx.InputAdapter
-
touchDragged
- Specified by:
touchDraggedin interfacecom.badlogic.gdx.InputProcessor- Overrides:
touchDraggedin classcom.badlogic.gdx.InputAdapter
-
mouseMoved
- Specified by:
mouseMovedin interfacecom.badlogic.gdx.InputProcessor- Overrides:
mouseMovedin classcom.badlogic.gdx.InputAdapter
-
scrolled
- Specified by:
scrolledin interfacecom.badlogic.gdx.InputProcessor- Overrides:
scrolledin classcom.badlogic.gdx.InputAdapter
-
fromCode
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
-