dot_b0T Posted November 15, 2017 Share Posted November 15, 2017 (edited) Hey guys, got this little idea for an "assistive" script. Basically the only thing i want it to do is to press the proper number key for a certain answer in a dialogue window when the dialogue is active. so basically I'm going self-play but with a script quick skipping a certain dialogue now and then. I'm still very fresh to osbot and java scripting, so far I've only made a shop-buyer that quick hops between worlds, very basic stuff. The info and help I'm looking for is maybe an example/snippet that shows how to send keystrokes with osbot when a certain dialogue is open. Hopefully this is not too much to ask for, if I manage to make something cool out of it I'll just share it here and give back to the forum for helping! something like dialogues.selectOption but that instead of clicks with the mouse use the corresponding hotkey for the answer. Edited November 15, 2017 by dot_b0T Quote Link to comment Share on other sites More sharing options...
Lemons Posted November 15, 2017 Share Posted November 15, 2017 Something like this could do what you need: final String[] DIALOGUE_OPTIONS = { "Dialogue option", }; void solveDialogue() throws InterruptedException { if (getDialogues().inDialogue()) { // In dialogue, try and find a widget for our option RS2Widget widget = getWidgets().getWidgetContainingText(DIALOGUE_OPTIONS); if (widget != null && widget.isVisible()) { // Widget exists and is visible, solve it getKeyboard().typeString(""+widget.getThirdLevelId(), false); sleep(2000); // Some sleep to prevent spamming } } } Just populate DIALOGUE_OPTIONS with the choices you want to make, and call "solveDialogue()" in onLoop. Quote Link to comment Share on other sites More sharing options...
Chris Posted November 15, 2017 Share Posted November 15, 2017 https://osbot.org/api/org/osbot/rs07/api/Keyboard.html https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=3&cad=rja&uact=8&ved=0ahUKEwj3mZfcssHXAhWG6yYKHQNoBrEQFgg0MAI&url=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F13552229%2Fhow-to-use-keyevent&usg=AOvVaw0NCa1reVynMGPBD_iA_pH3 Quote Link to comment Share on other sites More sharing options...
dot_b0T Posted November 15, 2017 Author Share Posted November 15, 2017 8 minutes ago, Lemons said: Something like this could do what you need: final String[] DIALOGUE_OPTIONS = { "Dialogue option", }; void solveDialogue() throws InterruptedException { if (getDialogues().inDialogue()) { // In dialogue, try and find a widget for our option RS2Widget widget = getWidgets().getWidgetContainingText(DIALOGUE_OPTIONS); if (widget != null && widget.isVisible()) { // Widget exists and is visible, solve it getKeyboard().typeString(""+widget.getThirdLevelId(), false); sleep(2000); // Some sleep to prevent spamming } } } Just populate DIALOGUE_OPTIONS with the choices you want to make, and call "solveDialogue()" in onLoop. 3 minutes ago, Chris said: https://osbot.org/api/org/osbot/rs07/api/Keyboard.html https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=3&cad=rja&uact=8&ved=0ahUKEwj3mZfcssHXAhWG6yYKHQNoBrEQFgg0MAI&url=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F13552229%2Fhow-to-use-keyevent&usg=AOvVaw0NCa1reVynMGPBD_iA_pH3 Thank you so much guys for the spot on replies, exactly what i was looking for. This will keep me occupied for a while gonna play and fool around with this now for a bit. Quote Link to comment Share on other sites More sharing options...
Alek Posted November 15, 2017 Share Posted November 15, 2017 Dialogue API does this for you; I mean you could re-write your own Dialogue API, not sure what that would achieve though. 4 Quote Link to comment Share on other sites More sharing options...