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 Details

    • keysById

      private static final Map<String,​KeyBinding> keysById
    • keyToBindings

      private static final Map<InputUtil.Key,​KeyBinding> keyToBindings
    • keyCategories

      private static final Set<String> keyCategories
    • categoryOrderMap

      private static final Map<String,​Integer> categoryOrderMap
    • translationKey

      private final String translationKey
    • defaultKey

      private final InputUtil.Key defaultKey
    • category

      private final String category
    • boundKey

      private InputUtil.Key boundKey
    • pressed

      private boolean pressed
    • timesPressed

      private int timesPressed
  • Constructor Details

    • KeyBinding

      public KeyBinding​(String translationKey, int code, String category)
    • KeyBinding

      public KeyBinding​(String translationKey, InputUtil.Type type, int code, String category)
  • Method Details

    • onKeyPressed

      public static void onKeyPressed​(InputUtil.Key key)
    • setKeyPressed

      public static void setKeyPressed​(InputUtil.Key key, boolean pressed)
    • 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

      public String 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 true as 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

      public String getTranslationKey()
    • getDefaultKey

      public InputUtil.Key getDefaultKey()
    • setBoundKey

      public void setBoundKey​(InputUtil.Key boundKey)
    • compareTo

      public int compareTo​(KeyBinding keyBinding)
      Specified by:
      compareTo in interface Comparable<KeyBinding>
    • getLocalizedName

      public static Supplier<Text> getLocalizedName​(String id)
    • equals

      public boolean equals​(KeyBinding other)
    • isUnbound

      public boolean isUnbound()
    • matchesKey

      public boolean matchesKey​(int keyCode, int scanCode)
    • matchesMouse

      public boolean matchesMouse​(int code)
    • getBoundKeyLocalizedText

      public Text getBoundKeyLocalizedText()
    • isDefault

      public boolean isDefault()
    • getBoundKeyTranslationKey

      public String getBoundKeyTranslationKey()
    • setPressed

      public void setPressed​(boolean pressed)