net.minecraft.client.util.InputUtil Java Examples

The following examples show how to use net.minecraft.client.util.InputUtil. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CmdBind.java    From bleachhack-1.14 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCommand(String command, String[] args) throws Exception {
	for (Module m: ModuleManager.getModules()) {
		if (m.getName().equalsIgnoreCase(args[1])) {
			if (args[0].equalsIgnoreCase("add")) {
				m.setKey(InputUtil.fromName("key.keyboard." + args[2].toLowerCase()).getKeyCode());
				BleachLogger.infoMessage("Bound " + m.getName() + " To " + args[2]);
			} else if (args[0].equalsIgnoreCase("del")) {
				m.setKey(-1);
				BleachLogger.infoMessage("Removed Bind For " + m.getName());
			}
			return;
		}
	}
	BleachLogger.errorMessage("Could Not Find Module \"" + args[1] + "\"");
}
 
Example #2
Source File: BindsCmd.java    From Wurst7 with GNU General Public License v3.0 6 votes vote down vote up
private String parseKey(String displayKey) throws CmdSyntaxError
{
	String key = displayKey.toLowerCase();
	
	String prefix = "key.keyboard.";
	if(!key.startsWith(prefix))
		key = prefix + key;
	
	try
	{
		InputUtil.fromTranslationKey(key);
		return key;
		
	}catch(IllegalArgumentException e)
	{
		throw new CmdSyntaxError("Unknown key: " + displayKey);
	}
}
 
Example #3
Source File: CmdBind.java    From bleachhack-1.14 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCommand(String command, String[] args) throws Exception {
	for (Module m: ModuleManager.getModules()) {
		if (m.getName().equalsIgnoreCase(args[1])) {
			if (args[0].equalsIgnoreCase("add")) {
				m.setKey(InputUtil.fromTranslationKey("key.keyboard." + args[2].toLowerCase()).getCode());
				BleachLogger.infoMessage("Bound " + m.getName() + " To " + args[2]);
			} else if (args[0].equalsIgnoreCase("del")) {
				m.setKey(-1);
				BleachLogger.infoMessage("Removed Bind For " + m.getName());
			}
			return;
		}
	}
	BleachLogger.errorMessage("Could Not Find Module \"" + args[1] + "\"");
}
 
Example #4
Source File: CmdBind.java    From bleachhack-1.14 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCommand(String command, String[] args) throws Exception {
	for (Module m: ModuleManager.getModules()) {
		if (m.getName().equalsIgnoreCase(args[1])) {
			if (args[0].equalsIgnoreCase("add")) {
				m.setKey(InputUtil.fromName("key.keyboard." + args[2].toLowerCase()).getKeyCode());
				BleachLogger.infoMessage("Bound " + m.getName() + " To " + args[2]);
			} else if (args[0].equalsIgnoreCase("del")) {
				m.setKey(-1);
				BleachLogger.infoMessage("Removed Bind For " + m.getName());
			}
			return;
		}
	}
	BleachLogger.errorMessage("Could Not Find Module \"" + args[1] + "\"");
}
 
Example #5
Source File: ModuleWindowDark.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
public void drawBindSetting(Module m, int key, int x, int y) {
	Screen.fill(x, y, x+len, y+12, 0x70000000);
	
	if (key != -1 && mouseOver(x, y, x+len, y+12)) m.setKey((key != 261 && key != 256) ? key : -1);
	String name = InputUtil.getKeycodeName(m.getKey());
	if (name == null) name = "KEY" + m.getKey();
	if (name.isEmpty()) name = "NONE";
	
	font.drawWithShadow("Bind: " + name + (mouseOver(x, y, x+len, y+12) ? "..." : "")
			, x+2, y+2, mouseOver(x, y, x+len, y+12) ? 0xcfc3cf : 0xcfe0cf);
}
 
Example #6
Source File: MixinKeyboard.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "onKey", at = @At(value = "INVOKE", target = "net/minecraft/client/util/InputUtil.isKeyPressed(JI)Z", ordinal = 5), cancellable = true)
private void onKeyEvent(long windowPointer, int key, int scanCode, int action, int modifiers, CallbackInfo callbackInfo) {
	if (InputUtil.getKeycodeName(InputUtil.getKeyCode(key, scanCode).getKeyCode()) != null && InputUtil.getKeycodeName(InputUtil.getKeyCode(key, scanCode).getKeyCode()).equals(CommandManager.prefix)) {
        MinecraftClient.getInstance().openScreen(new ChatScreen(CommandManager.prefix));
    }
	
    EventKeyPress event = new EventKeyPress(key, scanCode);
	BleachHack.eventBus.post(event);
	if (event.isCancelled()) callbackInfo.cancel();
}
 
Example #7
Source File: ClickGuiScreen.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
public void drawBindSetting(Module m, int key, int x, int y) {
	Screen.fill(x, y+11, x+len-2, y+12, 0x90b0b0b0);
	Screen.fill(x+len - 2, y, x+len-1, y+12, 0x90b0b0b0);
	Screen.fill(x, y - 1, x + 1, y+11, 0x90000000);
	
	if (key != -1 && mouseOver(x, y, x+len, y+12)) m.setKey((key != 261 && key != 256) ? key : -1);
	String name = InputUtil.getKeycodeName(m.getKey());
	if (name == null) name = "KEY" + m.getKey();
	if (name.isEmpty()) name = "NONE";
	
	font.drawWithShadow("Bind: " + name + (mouseOver(x, y, x+len, y+12) ? "..." : "")
			, x+2, y+2, mouseOver(x, y, x+len, y+12) ? 0xcfc3cf : 0xcfe0cf);
}
 
Example #8
Source File: ClickGuiScreen.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
public void drawBindSetting(MatrixStack matrix, Module m, int key, int x, int y) {
	Screen.fill(matrix, x, y+11, x+len-2, y+12, 0x90b0b0b0);
	Screen.fill(matrix, x+len - 2, y, x+len-1, y+12, 0x90b0b0b0);
	Screen.fill(matrix, x, y - 1, x + 1, y+11, 0x90000000);
	
	if (key != -1 && mouseOver(x, y, x+len, y+12)) m.setKey((key != 261 && key != 256) ? key : -1);
	String name = InputUtil.fromKeyCode(m.getKey(), -1).getLocalizedText().getString();
	if (name == null) name = "KEY" + m.getKey();
	if (name.isEmpty()) name = "NONE";
	
	textRenderer.drawWithShadow(matrix, "Bind: " + name + (mouseOver(x, y, x+len, y+12) ? "..." : "")
			, x+2, y+2, mouseOver(x, y, x+len, y+12) ? 0xcfc3cf : 0xcfe0cf);
}
 
Example #9
Source File: MixinKeyboard.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "onKey", at = @At(value = "INVOKE", target = "net/minecraft/client/util/InputUtil.isKeyPressed(JI)Z", ordinal = 5), cancellable = true)
private void onKeyEvent(long windowPointer, int key, int scanCode, int action, int modifiers, CallbackInfo callbackInfo) {
	if (InputUtil.getKeycodeName(InputUtil.getKeyCode(key, scanCode).getKeyCode()) != null && InputUtil.getKeycodeName(InputUtil.getKeyCode(key, scanCode).getKeyCode()).equals(CommandManager.prefix)) {
        MinecraftClient.getInstance().openScreen(new ChatScreen(CommandManager.prefix));
    }
	
    EventKeyPress event = new EventKeyPress(key, scanCode);
	BleachHack.eventBus.post(event);
	if (event.isCancelled()) callbackInfo.cancel();
}
 
Example #10
Source File: ModuleWindowLight.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
public void drawBindSetting(Module m, int key, int x, int y) {
	Screen.fill(x, y, x+len, y+12, 0x70000000);
	
	if (key != -1 && mouseOver(x, y, x+len, y+12)) m.setKey((key != 261 && key != 256) ? key : -1);
	String name = InputUtil.getKeycodeName(m.getKey());
	if (name == null) name = "KEY" + m.getKey();
	if (name.isEmpty()) name = "NONE";
	
	font.drawWithShadow("Bind: " + name + (mouseOver(x, y, x+len, y+12) ? "..." : "")
			, x+2, y+2, mouseOver(x, y, x+len, y+12) ? 0xffc3ff : 0xffe0ff);
}
 
Example #11
Source File: ModuleWindowFuture.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
public void drawBindSetting(Module m, int key, int x, int y) {
	Screen.fill(x, y, x+len, y+14, mouseOver(x, y, x+len, y+14) ? 0x70303030 : 0x70000000);
	
	if (key != -1 && mouseOver(x, y, x+len, y+14)) m.setKey((key != 261 && key != 256) ? key : -1);
	String name = InputUtil.getKeycodeName(m.getKey());
	if (name == null) name = "KEY" + m.getKey();
	if (name.isEmpty()) name = "NONE";
	
	font.drawWithShadow("Bind ยง7" + name + (mouseOver(x, y, x+len, y+14) ? "..." : "")
			, x+2, y+3, -1);
}
 
Example #12
Source File: ExcavatorHack.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
private void handlePositionSelection()
{
	// continue with next step
	if(step.pos != null && InputUtil
		.isKeyPressed(MC.getWindow().getHandle(), GLFW.GLFW_KEY_ENTER))
	{
		step = Step.values()[step.ordinal() + 1];
		
		// delete posLookingAt
		if(!step.selectPos)
			posLookingAt = null;
		
		return;
	}
	
	if(MC.crosshairTarget != null
		&& MC.crosshairTarget instanceof BlockHitResult)
	{
		// set posLookingAt
		posLookingAt = ((BlockHitResult)MC.crosshairTarget).getBlockPos();
		
		// offset if sneaking
		if(MC.options.keySneak.isPressed())
			posLookingAt = posLookingAt
				.offset(((BlockHitResult)MC.crosshairTarget).getSide());
		
	}else
		posLookingAt = null;
	
	// set selected position
	if(posLookingAt != null && MC.options.keyUse.isPressed())
		step.pos = posLookingAt;
}
 
Example #13
Source File: MixinKeyboard.java    From Sandbox with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Redirect(method = "onKey", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/ScreenshotUtils;saveScreenshot(Ljava/io/File;IILnet/minecraft/client/gl/Framebuffer;Ljava/util/function/Consumer;)V"))
public void takeScreenshot(File file_1, int int_1, int int_2, Framebuffer glFramebuffer_1, Consumer<Text> consumer_1) {
    if (InputUtil.isKeyPressed(MinecraftClient.getInstance().getWindow().getHandle(), GLFW.GLFW_KEY_P)) {
        PanoramaHandler.takeScreenshot(consumer_1);
    } else {
        ScreenshotUtils.saveScreenshot(file_1, int_1, int_2, glFramebuffer_1, consumer_1);
    }
}
 
Example #14
Source File: NavigatorNewKeybindScreen.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onKeyPress(int keyCode, int scanCode, int int_3)
{
	if(choosingKey)
	{
		selectedKey =
			InputUtil.fromKeyCode(keyCode, scanCode).getTranslationKey();
		okButton.active = !selectedKey.equals("key.keyboard.unknown");
		
	}else if(keyCode == 1)
		WurstClient.MC.openScreen(parent);
}
 
Example #15
Source File: KeyBindingMixin.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean isActallyPressed()
{
	long handle = WurstClient.MC.getWindow().getHandle();
	int code = boundKey.getCode();
	return InputUtil.isKeyPressed(handle, code);
}
 
Example #16
Source File: ZoomManagerScreen.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setKey(String key)
{
	WurstClient.INSTANCE.getZoomKey()
		.setBoundKey(InputUtil.fromTranslationKey(key));
	client.options.write();
	KeyBinding.updateKeysByCode();
	keyButton.setMessage(new LiteralText("Zoom Key: " + key));
}
 
Example #17
Source File: KeybindsFile.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
private boolean isValidKeyName(String key)
{
	try
	{
		InputUtil.fromTranslationKey(key);
		return true;
		
	}catch(IllegalArgumentException e)
	{
		return false;
	}
}
 
Example #18
Source File: PressAKeyScreen.java    From Wurst7 with GNU General Public License v3.0 4 votes vote down vote up
private String getKeyName(int keyCode, int scanCode)
{
	return InputUtil.fromKeyCode(keyCode, scanCode).getTranslationKey();
}
 
Example #19
Source File: KeybindProcessor.java    From Wurst7 with GNU General Public License v3.0 4 votes vote down vote up
private String getKeyName(KeyPressEvent event)
{
	int keyCode = event.getKeyCode();
	int scanCode = event.getScanCode();
	return InputUtil.fromKeyCode(keyCode, scanCode).getTranslationKey();
}