keyremapping: add option to block extra mouse buttons
This commit is contained in:
@@ -241,4 +241,15 @@ public interface KeyRemappingConfig extends Config
|
||||
{
|
||||
return new ModifierlessKeybind(KeyEvent.VK_ESCAPE, 0);
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
position = 20,
|
||||
keyName = "consumeExtraMouseButtons",
|
||||
name = "Block extra mouse buttons",
|
||||
description = "Blocks mouse buttons 4 and 5"
|
||||
)
|
||||
default boolean consumeExtraMouseButtons()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ package net.runelite.client.plugins.keyremapping;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.inject.Inject;
|
||||
@@ -39,6 +40,8 @@ import net.runelite.client.input.MouseAdapter;
|
||||
|
||||
class KeyRemappingListener extends MouseAdapter implements KeyListener
|
||||
{
|
||||
// Button numbers greater than BUTTON3 have no constant identifier
|
||||
private static final int MOUSE_BUTTON_4 = 4;
|
||||
|
||||
@Inject
|
||||
private KeyRemappingPlugin plugin;
|
||||
@@ -307,4 +310,32 @@ class KeyRemappingListener extends MouseAdapter implements KeyListener
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MouseEvent mouseClicked(MouseEvent mouseEvent)
|
||||
{
|
||||
return consumeMouseEvent(mouseEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MouseEvent mousePressed(MouseEvent mouseEvent)
|
||||
{
|
||||
return consumeMouseEvent(mouseEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MouseEvent mouseReleased(MouseEvent mouseEvent)
|
||||
{
|
||||
return consumeMouseEvent(mouseEvent);
|
||||
}
|
||||
|
||||
private MouseEvent consumeMouseEvent(MouseEvent mouseEvent)
|
||||
{
|
||||
int button = mouseEvent.getButton();
|
||||
if (button >= MOUSE_BUTTON_4 && config.consumeExtraMouseButtons())
|
||||
{
|
||||
mouseEvent.consume();
|
||||
}
|
||||
return mouseEvent;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ import net.runelite.client.callback.ClientThread;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.eventbus.Subscribe;
|
||||
import net.runelite.client.input.KeyManager;
|
||||
import net.runelite.client.input.MouseManager;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.plugins.PluginDescriptor;
|
||||
import net.runelite.client.ui.JagexColors;
|
||||
@@ -69,6 +70,9 @@ public class KeyRemappingPlugin extends Plugin
|
||||
@Inject
|
||||
private KeyManager keyManager;
|
||||
|
||||
@Inject
|
||||
private MouseManager mouseManager;
|
||||
|
||||
@Inject
|
||||
private KeyRemappingListener inputListener;
|
||||
|
||||
@@ -81,6 +85,7 @@ public class KeyRemappingPlugin extends Plugin
|
||||
{
|
||||
typing = false;
|
||||
keyManager.registerKeyListener(inputListener);
|
||||
mouseManager.registerMouseListener(inputListener);
|
||||
|
||||
clientThread.invoke(() ->
|
||||
{
|
||||
@@ -104,6 +109,7 @@ public class KeyRemappingPlugin extends Plugin
|
||||
}
|
||||
});
|
||||
|
||||
mouseManager.unregisterMouseListener(inputListener);
|
||||
keyManager.unregisterKeyListener(inputListener);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user