Package net.minecraft.client.option
Class KeyBinding
java.lang.Object
net.minecraft.client.option.KeyBinding
- All Implemented Interfaces:
Comparable<KeyBinding>
- Direct Known Subclasses:
StickyKeyBinding
@Environment(CLIENT) public class KeyBinding extends Object implements Comparable<KeyBinding>
-
Field Summary
Fields Modifier and Type Field Description private InputUtil.KeyboundKeyprivate Stringcategoryprivate static Map<String,Integer>categoryOrderMapprivate InputUtil.KeydefaultKeyprivate static Set<String>keyCategoriesprivate static Map<String,KeyBinding>keysByIdprivate static Map<InputUtil.Key,KeyBinding>keyToBindingsprivate booleanpressedprivate inttimesPressedprivate StringtranslationKey -
Constructor Summary
Constructors Constructor Description KeyBinding(String translationKey, int code, String category)KeyBinding(String translationKey, InputUtil.Type type, int code, String category) -
Method Summary
Modifier and Type Method Description intcompareTo(KeyBinding keyBinding)booleanequals(KeyBinding other)TextgetBoundKeyLocalizedText()StringgetBoundKeyTranslationKey()StringgetCategory()InputUtil.KeygetDefaultKey()static Supplier<Text>getLocalizedName(String id)StringgetTranslationKey()booleanisDefault()booleanisPressed(){@return if the key is being held down}booleanisUnbound()booleanmatchesKey(int keyCode, int scanCode)booleanmatchesMouse(int code)static voidonKeyPressed(InputUtil.Key key)private voidreset()voidsetBoundKey(InputUtil.Key boundKey)static voidsetKeyPressed(InputUtil.Key key, boolean pressed)voidsetPressed(boolean pressed)static voidunpressAll()static voidupdateKeysByCode()static voidupdatePressedStates()booleanwasPressed(){@return if the key was pressed}
-
Field Details
-
keysById
-
keyToBindings
-
keyCategories
-
categoryOrderMap
-
translationKey
-
defaultKey
-
category
-
boundKey
-
pressed
private boolean pressed -
timesPressed
private int timesPressed
-
-
Constructor Details
-
KeyBinding
-
KeyBinding
-
-
Method Details
-
onKeyPressed
-
setKeyPressed
-
updatePressedStates
public static void updatePressedStates() -
unpressAll
public static void unpressAll() -
updateKeysByCode
public static void updateKeysByCode() -
isPressed
public boolean isPressed(){@return if the key is being held down}Note that if you are continuously calling this method (like every tick), it doesn't always catch all key presses. This is because the key can be pressed and released before the next check.
- See Also:
wasPressed()
-
getCategory
-
wasPressed
public boolean wasPressed(){@return if the key was pressed}A key binding counts the number of times the key is pressed. This method "consumes" it and returns
trueas many times as the key is pressed.To consume all remaining key presses, while-loop idiom can be used:
while(keyBinding.wasPressed()) { // do your action }- See Also:
isPressed(), MC-118107
-
reset
private void reset() -
getTranslationKey
-
getDefaultKey
-
setBoundKey
-
compareTo
- Specified by:
compareToin interfaceComparable<KeyBinding>
-
getLocalizedName
-
equals
-
isUnbound
public boolean isUnbound() -
matchesKey
public boolean matchesKey(int keyCode, int scanCode) -
matchesMouse
public boolean matchesMouse(int code) -
getBoundKeyLocalizedText
-
isDefault
public boolean isDefault() -
getBoundKeyTranslationKey
-
setPressed
public void setPressed(boolean pressed)
-