Skip to content

Commit

Permalink
chatcommands: support keybinds in pms
Browse files Browse the repository at this point in the history
  • Loading branch information
dekvall authored and Adam- committed Dec 29, 2019
1 parent 2586da3 commit 5ad94ea
Showing 1 changed file with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
import javax.inject.Singleton;
import net.runelite.api.Client;
import net.runelite.api.ScriptID;
import net.runelite.api.VarClientInt;
import net.runelite.api.VarClientStr;
import net.runelite.api.vars.InputType;
import net.runelite.client.callback.ClientThread;
import net.runelite.client.input.KeyListener;

Expand All @@ -56,7 +58,11 @@ public void keyPressed(KeyEvent e)
{
if (chatCommandsConfig.clearSingleWord().matches(e))
{
String input = client.getVar(VarClientStr.CHATBOX_TYPED_TEXT);
int inputTye = client.getVar(VarClientInt.INPUT_TYPE);
String input = inputTye == InputType.NONE.getType()
? client.getVar(VarClientStr.CHATBOX_TYPED_TEXT)
: client.getVar(VarClientStr.INPUT_TEXT);

if (input != null)
{
// remove trailing space
Expand All @@ -77,20 +83,27 @@ public void keyPressed(KeyEvent e)
replacement = "";
}

clientThread.invoke(() ->
{
client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, replacement);
client.runScript(ScriptID.CHAT_PROMPT_INIT);
});
clientThread.invoke(() -> applyText(inputTye, replacement));
}
}
else if (chatCommandsConfig.clearChatBox().matches(e))
{
clientThread.invoke(() ->
{
client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, "");
client.runScript(ScriptID.CHAT_PROMPT_INIT);
});
int inputTye = client.getVar(VarClientInt.INPUT_TYPE);
clientThread.invoke(() -> applyText(inputTye, ""));
}
}

private void applyText(int inputType, String replacement)
{
if (inputType == InputType.NONE.getType())
{
client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, replacement);
client.runScript(ScriptID.CHAT_PROMPT_INIT);
}
else if (inputType == InputType.PRIVATE_MESSAGE.getType())
{
client.setVar(VarClientStr.INPUT_TEXT, replacement);
client.runScript(ScriptID.CHAT_TEXT_INPUT_REBUILD, "");
}
}

Expand Down

0 comments on commit 5ad94ea

Please sign in to comment.