Class Key
java.lang.Object
dev.xichil.mvui.Key
A keyboard key or mouse button that a
Keybind can be set to, the same in every Minecraft version. Immutable;
compare with equals(Object).
- A keyboard key is identified by its GLFW key code (what 1.13+ uses), e.g. 82 for R, 340 for Left Shift.
Create one with
keyboard(int). - A mouse button is identified by its number: 0 left, 1 right, 2 middle, 3 and up the side buttons. Create one
with
mouse(int). UNBOUNDis "no key".
Storing keys
name() is what 1.13+ writes to options.txt (key.keyboard.r, key.mouse.left), and
fromName(String) reads it back, so a mod can store a key as text in its config:
String text = key.name(); // "key.keyboard.left.shift"
Key back = Key.fromName(text); // equals key; null for text that is no key name
Old versions
1.7.10 – 1.12.2 use LWJGL 2 key codes, and mouse buttons as-100 + button; their backend (and a mod that
compares keys there) converts with fromLwjgl2(int) and toLwjgl2(), the same table vanilla's 1.13 options
upgrade uses. Keys LWJGL 2 doesn't know (F20 – F25, World 1/2) can't be bound there; LWJGL 2 keys GLFW doesn't know
become UNBOUND.-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionintcode()The GLFW key code for a keyboard key (-1 forUNBOUND), the button number for a mouse button.The English name, as vanilla's en_us shows it: "R", "Left Shift", "Button 4", "Not Bound".booleanEqual if both are the same type with the same code.static KeyfromLwjgl2(int code) The key for a 1.7.10 – 1.12.2 key code, as vanilla'sKeyBindingstores them there: an LWJGL 2Keyboard.KEY_*code, or-100 + buttonfor a mouse button.static KeyinthashCode()booleanWhether this isUNBOUND, "no key".static Keykeyboard(int glfwCode) The keyboard key with GLFW key codeglfwCode, e.g.static Keymouse(int button) A mouse button.name()The key's name as in 1.13+'soptions.txt:key.keyboard.r,key.mouse.left,key.keyboard.unknown.inttoLwjgl2()The 1.7.10 – 1.12.2 key code: the inverse offromLwjgl2(int).toString()Thename().type()Whether this is a keyboard key (includingUNBOUND) or a mouse button.
-
Field Details
-
UNBOUND
No key: GLFW_KEY_UNKNOWN (-1), namedkey.keyboard.unknown, shown as "Not Bound". -
ESCAPE
-
-
Method Details
-
keyboard
The keyboard key with GLFW key codeglfwCode, e.g.Key.keyboard(82)for R (GLFW_KEY_R). Codes the library has no name for are accepted too.- Parameters:
glfwCode- a GLFW key code (32 and up), or -1 (GLFW_KEY_UNKNOWN) forUNBOUND- Returns:
- the key
- Throws:
IllegalArgumentException- ifglfwCodeis below 32 and not -1
-
mouse
A mouse button.- Parameters:
button- 0 left, 1 right, 2 middle, 3 and up the side buttons- Returns:
- the key
- Throws:
IllegalArgumentException- ifbuttonis negative
-
fromName
The key namednameas in 1.13+'soptions.txt: the inverse ofname(). Examples:key.keyboard.r,key.keyboard.left.shift,key.mouse.left,key.mouse.4(the first side button, number 3),key.keyboard.unknown(UNBOUND). Keys without a name are writtenkey.keyboard.<GLFW code>.- Parameters:
name- a key name, may benull- Returns:
- the key, or
nullifnameis null or no key name
-
fromLwjgl2
The key for a 1.7.10 – 1.12.2 key code, as vanilla'sKeyBindingstores them there: an LWJGL 2Keyboard.KEY_*code, or-100 + buttonfor a mouse button.- Parameters:
code- an LWJGL 2 key code or-100 + button- Returns:
- the key;
UNBOUNDfor 0 (KEY_NONE) and codes without a GLFW equivalent
-
type
Whether this is a keyboard key (includingUNBOUND) or a mouse button.- Returns:
Key.Type.KEYBOARDorKey.Type.MOUSE
-
code
-
isUnbound
-
name
The key's name as in 1.13+'soptions.txt:key.keyboard.r,key.mouse.left,key.keyboard.unknown. A stable text form for storing keys;fromName(String)reads it back.- Returns:
- the name as in
options.txt;key.keyboard.unknownforUNBOUND
-
toLwjgl2
public int toLwjgl2()The 1.7.10 – 1.12.2 key code: the inverse offromLwjgl2(int).- Returns:
- an LWJGL 2 key code,
-100 + buttonfor a mouse button, or 0 (KEY_NONE) forUNBOUNDand keys LWJGL 2 doesn't have
-
englishName
The English name, as vanilla's en_us shows it: "R", "Left Shift", "Button 4", "Not Bound". For tests, logs and as a fallback only: backends show vanilla's own name, which is translated and follows the keyboard layout.- Returns:
- the English name, such as
"R","Button 4"or"Not Bound"forUNBOUND
-
equals
-
hashCode
-
toString
-