MALS Posted August 21, 2018 Share Posted August 21, 2018 (edited) Hey, I am writing a script that has to do a lot of talking with NPC's. In order to speed this up I want to simulate holding down the spacebar, but I can't seem to get it working. The build in Dialogues class does press spacebar to continue, but doesn't hold it down. The Keyboard class has a pressKey() method but this also doesn't seem to hold down spacebar. My question; is it possible to simulate holding down the spacebar in dialogues? Thanks in advance! edit: Found a solution myself! public void holdSpacebar() throws InterruptedException { while (getDialogues().isPendingContinuation()) { getKeyboard().pressKey(' '); sleep(30); } getKeyboard().releaseKey(' '); } By testing I found that a key gets repeated about 2000 times a minute on Windows 10 with the repeat rate set to max in keyboard properties. This translates to a key press every 30ms. This method seems to have the same behavior as a human holding down spacebar. The talking process in my script seems to be sped up by about 100%! Edited August 22, 2018 by MALS Quote Link to comment Share on other sites More sharing options...
FuryShark Posted August 21, 2018 Share Posted August 21, 2018 (edited) if (getDialogues().isPendingContinuation()) { getDialogues().clickContinue(); } edit: im not sure if thats what you want Edited August 21, 2018 by FuryShark Quote Link to comment Share on other sites More sharing options...
MALS Posted August 21, 2018 Author Share Posted August 21, 2018 5 minutes ago, FuryShark said: if (getDialogues().isPendingContinuation()) { getDialogues().clickContinue(); } edit: im not sure if thats what you want Nope, this would press the spacebar repeatedly and not hold it Quote Link to comment Share on other sites More sharing options...
Rays Posted August 21, 2018 Share Posted August 21, 2018 8 minutes ago, MALS said: Nope, this would press the spacebar repeatedly and not hold it Any particular reason as to why it should hold the key and not just press it? Quote Link to comment Share on other sites More sharing options...
MALS Posted August 21, 2018 Author Share Posted August 21, 2018 (edited) 11 minutes ago, Rays said: Any particular reason as to why it should hold the key and not just press it? It's about 100% faster in my case. Simulating a spacebar press 100x a second would also work, but thats not something what humans do. Edited August 21, 2018 by MALS Quote Link to comment Share on other sites More sharing options...
Chris Posted August 21, 2018 Share Posted August 21, 2018 4 minutes ago, MALS said: It's about 100% faster in my case. Simulating a spacebar press 100x a second would also work, but thats not something what humans do. keyboard class Quote Link to comment Share on other sites More sharing options...
Zappster Posted August 21, 2018 Share Posted August 21, 2018 (edited) 1 hour ago, MALS said: Nope, this would press the spacebar repeatedly and not hold it You should have a look at the conditional sleep class if (getDialogues().isPendingContinuation()) { //hold space getKeyboard().pressKey(KeyEvent.VK_SPACE); int timeout = 1600; //2 tick surpassed + 400ms ping compensate int sleepTime = 700; //1 tick surpassed + 100ms ping compensate //sleep until isPendingContinuation() == false new ConditionalSleep(timeout, sleepTime) { @Override public boolean condition() throws InterruptedException { return !getDialogues().isPendingContinuation(); } }.sleep(); //release space getKeyboard().releaseKey(KeyEvent.VK_SPACE); } Edited August 21, 2018 by Zappster Quote Link to comment Share on other sites More sharing options...
BronzeTier Posted August 21, 2018 Share Posted August 21, 2018 2 hours ago, Rays said: Any particular reason as to why it should hold the key and not just press it? way more efficient when you need to run through 100 dialogues then having it press spacebar each time a dialogue pops up Quote Link to comment Share on other sites More sharing options...
MALS Posted August 22, 2018 Author Share Posted August 22, 2018 8 hours ago, Zappster said: You should have a look at the conditional sleep class if (getDialogues().isPendingContinuation()) { //hold space getKeyboard().pressKey(KeyEvent.VK_SPACE); int timeout = 1600; //2 tick surpassed + 400ms ping compensate int sleepTime = 700; //1 tick surpassed + 100ms ping compensate //sleep until isPendingContinuation() == false new ConditionalSleep(timeout, sleepTime) { @Override public boolean condition() throws InterruptedException { return !getDialogues().isPendingContinuation(); } }.sleep(); //release space getKeyboard().releaseKey(KeyEvent.VK_SPACE); } Yeah you'd think this would work but in the problem is that getKeyboard().pressKey(KeyEvent.VK_SPACE); doesn't actually seems to hold the spacebarm, but only press it once in a dialogue. Overnight I might have came up with a solution though, if you long press a key in the chatbox, it types like 10 characters a second, the same as calling typeKey(' ') 10 times a second would do. I might just simulate that. Quote Link to comment Share on other sites More sharing options...
The_Danger97 Posted July 17, 2022 Share Posted July 17, 2022 thank you! Quote Link to comment Share on other sites More sharing options...