keyremapping plugin: add F-key remapping

Co-authored-by: Robert Alexander <rla@navadrag.com>
This commit is contained in:
Adam
2019-06-01 21:49:47 -04:00
committed by Adam
parent 907dc37d40
commit 8e2fe91ec8
3 changed files with 206 additions and 48 deletions

View File

@@ -35,6 +35,17 @@ public interface KeyRemappingConfig extends Config
{ {
@ConfigItem( @ConfigItem(
position = 1, position = 1,
keyName = "cameraRemap",
name = "Remap Camera",
description = "Configures whether the camera movement uses remapped keys"
)
default boolean cameraRemap()
{
return true;
}
@ConfigItem(
position = 2,
keyName = "up", keyName = "up",
name = "Camera Up key", name = "Camera Up key",
description = "The key which will replace up." description = "The key which will replace up."
@@ -45,7 +56,7 @@ public interface KeyRemappingConfig extends Config
} }
@ConfigItem( @ConfigItem(
position = 2, position = 3,
keyName = "down", keyName = "down",
name = "Camera Down key", name = "Camera Down key",
description = "The key which will replace down." description = "The key which will replace down."
@@ -56,7 +67,7 @@ public interface KeyRemappingConfig extends Config
} }
@ConfigItem( @ConfigItem(
position = 3, position = 4,
keyName = "left", keyName = "left",
name = "Camera Left key", name = "Camera Left key",
description = "The key which will replace left." description = "The key which will replace left."
@@ -67,7 +78,7 @@ public interface KeyRemappingConfig extends Config
} }
@ConfigItem( @ConfigItem(
position = 4, position = 5,
keyName = "right", keyName = "right",
name = "Camera Right key", name = "Camera Right key",
description = "The key which will replace right." description = "The key which will replace right."
@@ -76,4 +87,15 @@ public interface KeyRemappingConfig extends Config
{ {
return new ModifierlessKeybind(KeyEvent.VK_D, 0); return new ModifierlessKeybind(KeyEvent.VK_D, 0);
} }
@ConfigItem(
position = 6,
keyName = "fkeyRemap",
name = "Remap F Keys",
description = "Configures whether F-Keys are Remapped to 1 (F1) through 0 (F10), '-' (F11), and '=' (F12)"
)
default boolean fkeyRemap()
{
return false;
}
} }

View File

@@ -34,11 +34,26 @@ import net.runelite.api.Client;
import net.runelite.api.GameState; import net.runelite.api.GameState;
import net.runelite.api.VarClientStr; import net.runelite.api.VarClientStr;
import net.runelite.client.callback.ClientThread; import net.runelite.client.callback.ClientThread;
import net.runelite.client.config.Keybind;
import net.runelite.client.config.ModifierlessKeybind;
import net.runelite.client.input.KeyListener; import net.runelite.client.input.KeyListener;
import net.runelite.client.input.MouseAdapter; import net.runelite.client.input.MouseAdapter;
class KeyRemappingListener extends MouseAdapter implements KeyListener class KeyRemappingListener extends MouseAdapter implements KeyListener
{ {
private static final Keybind ONE = new ModifierlessKeybind(KeyEvent.VK_1, 0);
private static final Keybind TWO = new ModifierlessKeybind(KeyEvent.VK_2, 0);
private static final Keybind THREE = new ModifierlessKeybind(KeyEvent.VK_3, 0);
private static final Keybind FOUR = new ModifierlessKeybind(KeyEvent.VK_4, 0);
private static final Keybind FIVE = new ModifierlessKeybind(KeyEvent.VK_5, 0);
private static final Keybind SIX = new ModifierlessKeybind(KeyEvent.VK_6, 0);
private static final Keybind SEVEN = new ModifierlessKeybind(KeyEvent.VK_7, 0);
private static final Keybind EIGHT = new ModifierlessKeybind(KeyEvent.VK_8, 0);
private static final Keybind NINE = new ModifierlessKeybind(KeyEvent.VK_9, 0);
private static final Keybind ZERO = new ModifierlessKeybind(KeyEvent.VK_0, 0);
private static final Keybind MINUS = new ModifierlessKeybind(KeyEvent.VK_MINUS, 0);
private static final Keybind EQUALS = new ModifierlessKeybind(KeyEvent.VK_EQUALS, 0);
@Inject @Inject
private KeyRemappingPlugin plugin; private KeyRemappingPlugin plugin;
@@ -68,42 +83,108 @@ class KeyRemappingListener extends MouseAdapter implements KeyListener
if (!plugin.isTyping()) if (!plugin.isTyping())
{ {
if (config.up().matches(e)) if (config.cameraRemap())
{ {
modified.put(e.getKeyCode(), KeyEvent.VK_UP); if (config.up().matches(e))
e.setKeyCode(KeyEvent.VK_UP);
}
else if (config.down().matches(e))
{
modified.put(e.getKeyCode(), KeyEvent.VK_DOWN);
e.setKeyCode(KeyEvent.VK_DOWN);
}
else if (config.left().matches(e))
{
modified.put(e.getKeyCode(), KeyEvent.VK_LEFT);
e.setKeyCode(KeyEvent.VK_LEFT);
}
else if (config.right().matches(e))
{
modified.put(e.getKeyCode(), KeyEvent.VK_RIGHT);
e.setKeyCode(KeyEvent.VK_RIGHT);
}
else
{
switch (e.getKeyCode())
{ {
case KeyEvent.VK_ENTER: modified.put(e.getKeyCode(), KeyEvent.VK_UP);
case KeyEvent.VK_SLASH: e.setKeyCode(KeyEvent.VK_UP);
case KeyEvent.VK_COLON: }
// refocus chatbox else if (config.down().matches(e))
plugin.setTyping(true); {
clientThread.invoke(() -> modified.put(e.getKeyCode(), KeyEvent.VK_DOWN);
{ e.setKeyCode(KeyEvent.VK_DOWN);
plugin.unlockChat(); }
}); else if (config.left().matches(e))
break; {
modified.put(e.getKeyCode(), KeyEvent.VK_LEFT);
e.setKeyCode(KeyEvent.VK_LEFT);
}
else if (config.right().matches(e))
{
modified.put(e.getKeyCode(), KeyEvent.VK_RIGHT);
e.setKeyCode(KeyEvent.VK_RIGHT);
} }
} }
if (config.fkeyRemap())
{
if (ONE.matches(e))
{
modified.put(e.getKeyCode(), KeyEvent.VK_F1);
e.setKeyCode(KeyEvent.VK_F1);
}
else if (TWO.matches(e))
{
modified.put(e.getKeyCode(), KeyEvent.VK_F2);
e.setKeyCode(KeyEvent.VK_F2);
}
else if (THREE.matches(e))
{
modified.put(e.getKeyCode(), KeyEvent.VK_F3);
e.setKeyCode(KeyEvent.VK_F3);
}
else if (FOUR.matches(e))
{
modified.put(e.getKeyCode(), KeyEvent.VK_F4);
e.setKeyCode(KeyEvent.VK_F4);
}
else if (FIVE.matches(e))
{
modified.put(e.getKeyCode(), KeyEvent.VK_F5);
e.setKeyCode(KeyEvent.VK_F5);
}
else if (SIX.matches(e))
{
modified.put(e.getKeyCode(), KeyEvent.VK_F6);
e.setKeyCode(KeyEvent.VK_F6);
}
else if (SEVEN.matches(e))
{
modified.put(e.getKeyCode(), KeyEvent.VK_F7);
e.setKeyCode(KeyEvent.VK_F7);
}
else if (EIGHT.matches(e))
{
modified.put(e.getKeyCode(), KeyEvent.VK_F8);
e.setKeyCode(KeyEvent.VK_F8);
}
else if (NINE.matches(e))
{
modified.put(e.getKeyCode(), KeyEvent.VK_F9);
e.setKeyCode(KeyEvent.VK_F9);
}
else if (ZERO.matches(e))
{
modified.put(e.getKeyCode(), KeyEvent.VK_F10);
e.setKeyCode(KeyEvent.VK_F10);
}
else if (MINUS.matches(e))
{
modified.put(e.getKeyCode(), KeyEvent.VK_F11);
e.setKeyCode(KeyEvent.VK_F11);
}
else if (EQUALS.matches(e))
{
modified.put(e.getKeyCode(), KeyEvent.VK_F12);
e.setKeyCode(KeyEvent.VK_F12);
}
}
switch (e.getKeyCode())
{
case KeyEvent.VK_ENTER:
case KeyEvent.VK_SLASH:
case KeyEvent.VK_COLON:
// refocus chatbox
plugin.setTyping(true);
clientThread.invoke(() ->
{
plugin.unlockChat();
});
break;
}
} }
else else
{ {
@@ -146,21 +227,76 @@ class KeyRemappingListener extends MouseAdapter implements KeyListener
{ {
modified.remove(e.getKeyCode()); modified.remove(e.getKeyCode());
if (config.up().matches(e)) if (config.cameraRemap())
{ {
e.setKeyCode(KeyEvent.VK_UP); if (config.up().matches(e))
{
e.setKeyCode(KeyEvent.VK_UP);
}
else if (config.down().matches(e))
{
e.setKeyCode(KeyEvent.VK_DOWN);
}
else if (config.left().matches(e))
{
e.setKeyCode(KeyEvent.VK_LEFT);
}
else if (config.right().matches(e))
{
e.setKeyCode(KeyEvent.VK_RIGHT);
}
} }
else if (config.down().matches(e))
if (config.fkeyRemap())
{ {
e.setKeyCode(KeyEvent.VK_DOWN); if (ONE.matches(e))
} {
else if (config.left().matches(e)) e.setKeyCode(KeyEvent.VK_F1);
{ }
e.setKeyCode(KeyEvent.VK_LEFT); else if (TWO.matches(e))
} {
else if (config.right().matches(e)) e.setKeyCode(KeyEvent.VK_F2);
{ }
e.setKeyCode(KeyEvent.VK_RIGHT); else if (THREE.matches(e))
{
e.setKeyCode(KeyEvent.VK_F3);
}
else if (FOUR.matches(e))
{
e.setKeyCode(KeyEvent.VK_F4);
}
else if (FIVE.matches(e))
{
e.setKeyCode(KeyEvent.VK_F5);
}
else if (SIX.matches(e))
{
e.setKeyCode(KeyEvent.VK_F6);
}
else if (SEVEN.matches(e))
{
e.setKeyCode(KeyEvent.VK_F7);
}
else if (EIGHT.matches(e))
{
e.setKeyCode(KeyEvent.VK_F8);
}
else if (NINE.matches(e))
{
e.setKeyCode(KeyEvent.VK_F9);
}
else if (ZERO.matches(e))
{
e.setKeyCode(KeyEvent.VK_F10);
}
else if (MINUS.matches(e))
{
e.setKeyCode(KeyEvent.VK_F11);
}
else if (EQUALS.matches(e))
{
e.setKeyCode(KeyEvent.VK_F12);
}
} }
} }
else else

View File

@@ -51,7 +51,7 @@ import net.runelite.client.util.ColorUtil;
@PluginDescriptor( @PluginDescriptor(
name = "Key Remapping", name = "Key Remapping",
description = "Allows use of WASD keys for camera movement with 'Press Enter to Chat'", description = "Allows use of WASD keys for camera movement with 'Press Enter to Chat', and remapping number keys to F-keys",
tags = {"enter", "chat", "wasd", "camera"}, tags = {"enter", "chat", "wasd", "camera"},
enabledByDefault = false enabledByDefault = false
) )