#Simulate a keyboard press in a cmd program in java
1 messages · Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
While you are waiting for getting help, here are some tips to improve your experience:
If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.
Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.
u have to understand how the program originally got hands on the input via cmd
it works via System.in and System.out of that program
which the CMD ties to its window
processbuilder gives u full access to those two streams
so u can feed it with data and also read what it responds
alright
its sth like process.getOutputStream() and process.getInputStream()
which u can wrap with BufferedReader and PrintWriter for example
and how do i simulate the keyboard press?
and then easily interact with it
well, it depends how the program did it
if it reads it as text input from system.in
u can just literally write it text input
writer.print("r")
alright
like this?
i made a mistake; i need to press p, wait 5 seconds and then press r
and then wait 2 min
maybe u dont know, but there is TimeUnit.MINUTES.sleep(2)
and similar
much easier to read, lol
but is it correct?
well, it compiles
it doesnt look "wrong"
see if it works
if not, its wrong
its for sure improvable. but u should first figure out whether the approach works or not
You can't simulate a keyboard press, you can send text to it put you can't simulate presses