Pertinate Posted October 15, 2017 Share Posted October 15, 2017 (edited) Hey everyone! I did some light researching to reveal that there wasn't a way to be able to type in game without enabling all input. So to help myself get more familiar with java I wrote this little snippet to be able to type while all input is disabled! I am still currently working on disabling and enabling the JFrame for when the client is minimized or is not the focused window. I currently have the GetState() working but the onLoop does not work correctly. I am still tinkering with things as I am learning. I hope this is helpful to somebody! EDIT: fixed an error I didn't realize I didn't fix. Also now detects when the JFrame and client is not the main focus. It will turn off the JFrame while the client is in the background. InputOverride override = new InputOverride(ScriptInstance, alpha); in your onLoop add InputOverrideInstance.onLoop(); Spoiler import java.awt.Color; import java.awt.Dimension; import java.awt.Point; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import javax.swing.JComponent; import javax.swing.JFrame; import org.osbot.rs07.script.Script; @SuppressWarnings("serial") public class InputOverride extends JFrame { public InputOverride(Script api, Float alpha) { this.api = api; pointToMatch = api.getBot().getCanvas().getLocationOnScreen(); dimensionToMatch = api.getBot().getCanvas().getSize(); this.alpha = alpha; init(); } protected Script api; protected boolean hasInit = false; protected void init() { dispose(); setLocation(pointToMatch); setSize(dimensionToMatch); setUndecorated(true); setBackground(new Color(1.0f, 1.0f, 1.0f, alpha)); addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent e) {} @Override public void keyReleased(KeyEvent e) {} @Override public void keyPressed(KeyEvent e) { api.getKeyboard().typeKey(e.getKeyChar()); } }); setAlwaysOnTop(true); setVisible(true); hasInit = true; } public enum State{ Idle, Reposition, Resize, AdjustAlpha, OffScreen } public State GetState() { if(pointToMatch != null && dimensionToMatch != null && hasInit && api != null) { if(!api.getBot().getCanvas().isFocusOwner() && !isFocusOwner()) { return State.OffScreen; } else { if(isShowing()){ if(getLocationOnScreen().distance(pointToMatch) > 5 && getLocationOnScreen().distance(pointToMatch) < -5) { return State.Reposition; } } else if(dimensionToMatch.getHeight() != getSize().getHeight() && dimensionToMatch.getWidth() != getSize().getWidth()) { return State.Resize; } else if(getBackground().getAlpha() / 255 <= alpha - alphaDeadZone && getBackground().getAlpha() / 255 >= alpha + alphaDeadZone) { return State.AdjustAlpha; } else { return State.Idle; } } } return State.Idle; } public Point pointToMatch; public Dimension dimensionToMatch; public Float alpha; public Float deadZoneX = 5.0f; public Float deadZoneY = 5.0f; public float alphaDeadZone = 0.05f; public void onLoop() { pointToMatch = api.getBot().getCanvas().getLocationOnScreen(); dimensionToMatch = api.getBot().getCanvas().getSize(); switch (GetState()) { case Reposition: setLocation(pointToMatch.x, pointToMatch.y); break; case Resize: setSize(dimensionToMatch.width, dimensionToMatch.height); break; case AdjustAlpha: setBackground(new Color(1.0f, 1.0f, 1.0f, alpha)); break; case OffScreen: if(isVisible()) setVisible(false); break; default: if(!isVisible()) setVisible(true); break; } } public void OnQuit() { dispose(); } } Edited October 25, 2017 by Pertinate Quote Link to comment Share on other sites More sharing options...