Merge pull request #7395 from Abextm/wasd-modifiers
Ignore modifiers in WASD plugin input
This commit is contained in:
@@ -514,11 +514,15 @@ public class ConfigManager
|
|||||||
{
|
{
|
||||||
return Instant.parse(str);
|
return Instant.parse(str);
|
||||||
}
|
}
|
||||||
if (type == Keybind.class)
|
if (type == Keybind.class || type == ModifierlessKeybind.class)
|
||||||
{
|
{
|
||||||
String[] splitStr = str.split(":");
|
String[] splitStr = str.split(":");
|
||||||
int code = Integer.parseInt(splitStr[0]);
|
int code = Integer.parseInt(splitStr[0]);
|
||||||
int mods = Integer.parseInt(splitStr[1]);
|
int mods = Integer.parseInt(splitStr[1]);
|
||||||
|
if (type == ModifierlessKeybind.class)
|
||||||
|
{
|
||||||
|
return new ModifierlessKeybind(code, mods);
|
||||||
|
}
|
||||||
return new Keybind(code, mods);
|
return new Keybind(code, mods);
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ public class Keybind
|
|||||||
private final int keyCode;
|
private final int keyCode;
|
||||||
private final int modifiers;
|
private final int modifiers;
|
||||||
|
|
||||||
public Keybind(int keyCode, int modifiers)
|
protected Keybind(int keyCode, int modifiers, boolean ignoreModifiers)
|
||||||
{
|
{
|
||||||
modifiers &= KEYBOARD_MODIFIER_MASK;
|
modifiers &= KEYBOARD_MODIFIER_MASK;
|
||||||
|
|
||||||
@@ -73,10 +73,20 @@ public class Keybind
|
|||||||
keyCode = KeyEvent.VK_UNDEFINED;
|
keyCode = KeyEvent.VK_UNDEFINED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ignoreModifiers && keyCode != KeyEvent.VK_UNDEFINED)
|
||||||
|
{
|
||||||
|
modifiers = 0;
|
||||||
|
}
|
||||||
|
|
||||||
this.keyCode = keyCode;
|
this.keyCode = keyCode;
|
||||||
this.modifiers = modifiers;
|
this.modifiers = modifiers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Keybind(int keyCode, int modifiers)
|
||||||
|
{
|
||||||
|
this(keyCode, modifiers, false);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a keybind with that matches the passed KeyEvent
|
* Constructs a keybind with that matches the passed KeyEvent
|
||||||
*/
|
*/
|
||||||
@@ -94,6 +104,11 @@ public class Keybind
|
|||||||
* released
|
* released
|
||||||
*/
|
*/
|
||||||
public boolean matches(KeyEvent e)
|
public boolean matches(KeyEvent e)
|
||||||
|
{
|
||||||
|
return matches(e, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean matches(KeyEvent e, boolean ignoreModifiers)
|
||||||
{
|
{
|
||||||
if (NOT_SET.equals(this))
|
if (NOT_SET.equals(this))
|
||||||
{
|
{
|
||||||
@@ -115,6 +130,11 @@ public class Keybind
|
|||||||
return this.keyCode == keyCode;
|
return this.keyCode == keyCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ignoreModifiers && keyCode != KeyEvent.VK_UNDEFINED)
|
||||||
|
{
|
||||||
|
return this.keyCode == keyCode;
|
||||||
|
}
|
||||||
|
|
||||||
return this.keyCode == keyCode && this.modifiers == modifiers;
|
return this.keyCode == keyCode && this.modifiers == modifiers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2019 Abex
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
package net.runelite.client.config;
|
||||||
|
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
|
||||||
|
public class ModifierlessKeybind extends Keybind
|
||||||
|
{
|
||||||
|
public ModifierlessKeybind(int keyCode, int modifiers)
|
||||||
|
{
|
||||||
|
super(keyCode, modifiers, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a keybind with that matches the passed KeyEvent
|
||||||
|
*/
|
||||||
|
public ModifierlessKeybind(KeyEvent e)
|
||||||
|
{
|
||||||
|
this(e.getExtendedKeyCode(), e.getModifiersEx());
|
||||||
|
|
||||||
|
assert matches(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the KeyEvent is from a KeyPressed event this returns if the
|
||||||
|
* Event is this hotkey being pressed. If the KeyEvent is a
|
||||||
|
* KeyReleased event this returns if the event is this hotkey being
|
||||||
|
* released
|
||||||
|
*/
|
||||||
|
public boolean matches(KeyEvent e)
|
||||||
|
{
|
||||||
|
return matches(e, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -78,6 +78,7 @@ import net.runelite.client.config.ConfigItem;
|
|||||||
import net.runelite.client.config.ConfigItemDescriptor;
|
import net.runelite.client.config.ConfigItemDescriptor;
|
||||||
import net.runelite.client.config.ConfigManager;
|
import net.runelite.client.config.ConfigManager;
|
||||||
import net.runelite.client.config.Keybind;
|
import net.runelite.client.config.Keybind;
|
||||||
|
import net.runelite.client.config.ModifierlessKeybind;
|
||||||
import net.runelite.client.config.Range;
|
import net.runelite.client.config.Range;
|
||||||
import net.runelite.client.config.RuneLiteConfig;
|
import net.runelite.client.config.RuneLiteConfig;
|
||||||
import net.runelite.client.plugins.Plugin;
|
import net.runelite.client.plugins.Plugin;
|
||||||
@@ -508,11 +509,13 @@ public class ConfigPanel extends PluginPanel
|
|||||||
item.add(box, BorderLayout.EAST);
|
item.add(box, BorderLayout.EAST);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cid.getType() == Keybind.class)
|
if (cid.getType() == Keybind.class || cid.getType() == ModifierlessKeybind.class)
|
||||||
{
|
{
|
||||||
Keybind startingValue = configManager.getConfiguration(cd.getGroup().value(), cid.getItem().keyName(), Keybind.class);
|
Keybind startingValue = configManager.getConfiguration(cd.getGroup().value(),
|
||||||
|
cid.getItem().keyName(),
|
||||||
|
(Class<? extends Keybind>) cid.getType());
|
||||||
|
|
||||||
HotkeyButton button = new HotkeyButton(startingValue);
|
HotkeyButton button = new HotkeyButton(startingValue, cid.getType() == ModifierlessKeybind.class);
|
||||||
|
|
||||||
button.addFocusListener(new FocusAdapter()
|
button.addFocusListener(new FocusAdapter()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -29,13 +29,14 @@ import java.awt.event.KeyEvent;
|
|||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import net.runelite.client.config.Keybind;
|
import net.runelite.client.config.Keybind;
|
||||||
|
import net.runelite.client.config.ModifierlessKeybind;
|
||||||
|
|
||||||
public class HotkeyButton extends JButton
|
public class HotkeyButton extends JButton
|
||||||
{
|
{
|
||||||
@Getter
|
@Getter
|
||||||
private Keybind value;
|
private Keybind value;
|
||||||
|
|
||||||
public HotkeyButton(Keybind value)
|
public HotkeyButton(Keybind value, boolean modifierless)
|
||||||
{
|
{
|
||||||
setValue(value);
|
setValue(value);
|
||||||
addActionListener(e ->
|
addActionListener(e ->
|
||||||
@@ -47,7 +48,14 @@ public class HotkeyButton extends JButton
|
|||||||
@Override
|
@Override
|
||||||
public void keyPressed(KeyEvent e)
|
public void keyPressed(KeyEvent e)
|
||||||
{
|
{
|
||||||
setValue(new Keybind(e));
|
if (modifierless)
|
||||||
|
{
|
||||||
|
setValue(new ModifierlessKeybind(e));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
setValue(new Keybind(e));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import java.awt.event.KeyEvent;
|
|||||||
import net.runelite.client.config.Config;
|
import net.runelite.client.config.Config;
|
||||||
import net.runelite.client.config.ConfigGroup;
|
import net.runelite.client.config.ConfigGroup;
|
||||||
import net.runelite.client.config.ConfigItem;
|
import net.runelite.client.config.ConfigItem;
|
||||||
import net.runelite.client.config.Keybind;
|
import net.runelite.client.config.ModifierlessKeybind;
|
||||||
|
|
||||||
@ConfigGroup("wasdcamera")
|
@ConfigGroup("wasdcamera")
|
||||||
public interface WASDCameraConfig extends Config
|
public interface WASDCameraConfig extends Config
|
||||||
@@ -39,9 +39,9 @@ public interface WASDCameraConfig extends Config
|
|||||||
name = "Up key",
|
name = "Up key",
|
||||||
description = "The key which will replace up."
|
description = "The key which will replace up."
|
||||||
)
|
)
|
||||||
default Keybind up()
|
default ModifierlessKeybind up()
|
||||||
{
|
{
|
||||||
return new Keybind(KeyEvent.VK_W, 0);
|
return new ModifierlessKeybind(KeyEvent.VK_W, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
@@ -50,9 +50,9 @@ public interface WASDCameraConfig extends Config
|
|||||||
name = "Down key",
|
name = "Down key",
|
||||||
description = "The key which will replace down."
|
description = "The key which will replace down."
|
||||||
)
|
)
|
||||||
default Keybind down()
|
default ModifierlessKeybind down()
|
||||||
{
|
{
|
||||||
return new Keybind(KeyEvent.VK_S, 0);
|
return new ModifierlessKeybind(KeyEvent.VK_S, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
@@ -61,9 +61,9 @@ public interface WASDCameraConfig extends Config
|
|||||||
name = "Left key",
|
name = "Left key",
|
||||||
description = "The key which will replace left."
|
description = "The key which will replace left."
|
||||||
)
|
)
|
||||||
default Keybind left()
|
default ModifierlessKeybind left()
|
||||||
{
|
{
|
||||||
return new Keybind(KeyEvent.VK_A, 0);
|
return new ModifierlessKeybind(KeyEvent.VK_A, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
@@ -72,8 +72,8 @@ public interface WASDCameraConfig extends Config
|
|||||||
name = "Right key",
|
name = "Right key",
|
||||||
description = "The key which will replace right."
|
description = "The key which will replace right."
|
||||||
)
|
)
|
||||||
default Keybind right()
|
default ModifierlessKeybind right()
|
||||||
{
|
{
|
||||||
return new Keybind(KeyEvent.VK_D, 0);
|
return new ModifierlessKeybind(KeyEvent.VK_D, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user