client: block extra mouse keys
The key remapping plugin has no way to operate being on and also not blocking chat input, due to the other features of the plugin all doing key remaps and thus are required to know whether or not you are trying to type, or using a remapped key. This moves the blocking to the core, which we think won't affect many users anyway, and those that it does can just remap their mouse keys.
This commit is contained in:
@@ -33,6 +33,9 @@ import javax.inject.Singleton;
|
||||
@Singleton
|
||||
public class MouseManager
|
||||
{
|
||||
// Button numbers greater than BUTTON3 have no constant identifier
|
||||
private static final int MOUSE_BUTTON_4 = 4;
|
||||
|
||||
private final List<MouseListener> mouseListeners = new CopyOnWriteArrayList<>();
|
||||
private final List<MouseWheelListener> mouseWheelListeners = new CopyOnWriteArrayList<>();
|
||||
|
||||
@@ -74,6 +77,7 @@ public class MouseManager
|
||||
|
||||
public MouseEvent processMousePressed(MouseEvent mouseEvent)
|
||||
{
|
||||
checkExtraMouseButtons(mouseEvent);
|
||||
for (MouseListener mouseListener : mouseListeners)
|
||||
{
|
||||
mouseEvent = mouseListener.mousePressed(mouseEvent);
|
||||
@@ -83,6 +87,7 @@ public class MouseManager
|
||||
|
||||
public MouseEvent processMouseReleased(MouseEvent mouseEvent)
|
||||
{
|
||||
checkExtraMouseButtons(mouseEvent);
|
||||
for (MouseListener mouseListener : mouseListeners)
|
||||
{
|
||||
mouseEvent = mouseListener.mouseReleased(mouseEvent);
|
||||
@@ -92,6 +97,7 @@ public class MouseManager
|
||||
|
||||
public MouseEvent processMouseClicked(MouseEvent mouseEvent)
|
||||
{
|
||||
checkExtraMouseButtons(mouseEvent);
|
||||
for (MouseListener mouseListener : mouseListeners)
|
||||
{
|
||||
mouseEvent = mouseListener.mouseClicked(mouseEvent);
|
||||
@@ -99,6 +105,17 @@ public class MouseManager
|
||||
return mouseEvent;
|
||||
}
|
||||
|
||||
private void checkExtraMouseButtons(MouseEvent mouseEvent)
|
||||
{
|
||||
// Prevent extra mouse buttins from being passed into the client,
|
||||
// as it treats them all as left click
|
||||
int button = mouseEvent.getButton();
|
||||
if (button >= MOUSE_BUTTON_4)
|
||||
{
|
||||
mouseEvent.consume();
|
||||
}
|
||||
}
|
||||
|
||||
public MouseEvent processMouseEntered(MouseEvent mouseEvent)
|
||||
{
|
||||
for (MouseListener mouseListener : mouseListeners)
|
||||
|
||||
@@ -241,15 +241,4 @@ 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,7 +27,6 @@ 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;
|
||||
@@ -36,13 +35,9 @@ import net.runelite.api.GameState;
|
||||
import net.runelite.api.VarClientStr;
|
||||
import net.runelite.client.callback.ClientThread;
|
||||
import net.runelite.client.input.KeyListener;
|
||||
import net.runelite.client.input.MouseAdapter;
|
||||
|
||||
class KeyRemappingListener extends MouseAdapter implements KeyListener
|
||||
class KeyRemappingListener implements KeyListener
|
||||
{
|
||||
// Button numbers greater than BUTTON3 have no constant identifier
|
||||
private static final int MOUSE_BUTTON_4 = 4;
|
||||
|
||||
@Inject
|
||||
private KeyRemappingPlugin plugin;
|
||||
|
||||
@@ -310,32 +305,4 @@ 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,7 +43,6 @@ 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;
|
||||
@@ -70,9 +69,6 @@ public class KeyRemappingPlugin extends Plugin
|
||||
@Inject
|
||||
private KeyManager keyManager;
|
||||
|
||||
@Inject
|
||||
private MouseManager mouseManager;
|
||||
|
||||
@Inject
|
||||
private KeyRemappingListener inputListener;
|
||||
|
||||
@@ -85,7 +81,6 @@ public class KeyRemappingPlugin extends Plugin
|
||||
{
|
||||
typing = false;
|
||||
keyManager.registerKeyListener(inputListener);
|
||||
mouseManager.registerMouseListener(inputListener);
|
||||
|
||||
clientThread.invoke(() ->
|
||||
{
|
||||
@@ -109,7 +104,6 @@ public class KeyRemappingPlugin extends Plugin
|
||||
}
|
||||
});
|
||||
|
||||
mouseManager.unregisterMouseListener(inputListener);
|
||||
keyManager.unregisterKeyListener(inputListener);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user