#Simulating a keyboard click for a binary file

1 messages ยท Page 1 of 1 (latest)

woven pythonBOT
#

<@&987246399047479336> please have a look, thanks.

#

Here is an AI assisted attempt to answer your question ๐Ÿค–. Maybe it helps! In any case, a human is on the way ๐Ÿ‘. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#
TJ-Bot
Hi, I have a binary file that opens in cmd and if i press 'k', it shows some value. I want to run this binary file as a Process and i need to somehow input a button click or something. How do I do that?

t the 'k' key press programmatically in Java to see the value. Is there a way to simulate a keyboard click or input a specific key in Java for a binary file running as a Process?

Yes, you can simulate a keyboard click or input a specific key in Java using the Robot class. The Robot class allows you to generate native system input events for the purposes of test automation, self-running demos, and other applications where control of the mouse and keyboard is needed.

Here's an example code snippet that shows how to use the Robot class to simulate pressing the 'k' key:

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;

public class KeyboardSimulator {
    public static void main(String[] args) {
        try {
            Robot robot = new Robot();
            robot.keyPress(KeyEvent.VK_K);
            robot.keyRelease(KeyEvent.VK_K);
        } catch (AWTException e) {
            e.printStackTrace();
        }
    }
}

In this code snippet, we create an instance of the Robot class and then use its keyPress and keyRelease methods to simulate pressing and releasing the 'k' key. You can integrate this code into your program where you are running the binary file as a Process to programmatically input the 'k' key press.

woven pythonBOT
#

Activities have been reset.

woven pythonBOT
#

@drowsy drum

Your question has been closed due to inactivity.

If it was not resolved yet, feel free to just post a message below
to reopen it, or create a new thread.

Note that usually the reason for nobody calling back is that your
question may have been not well asked and hence no one felt confident
enough answering.

When you reopen the thread, try to use your time to improve the quality
of the question by elaborating, providing details, context, all relevant code
snippets, any errors you are getting, concrete examples and perhaps also some
screenshots. Share your attempt, explain the expected results and compare
them to the current results.

Also try to make the information easily accessible by sharing code
or assignment descriptions directly on Discord, not behind a link or
PDF-file; provide some guidance for long code snippets and ensure
the code is well formatted and has syntax highlighting. Kindly read through
https://stackoverflow.com/help/how-to-ask for more.

With enough info, someone knows the answer for sure ๐Ÿ‘

stuck spire
#

What is "a binary file?"

faint pewter
#

What's the binary file? Why do you want/need to use a java command to send the input?

livid sage
#

I'm not entirely sure how to do this but basically, unless you did something stupid complicated, you would have to invoke the binary from a java class and then you can send the "k" key through the standard Input using System.In I believe. You would essentially turn your java program into a wrapper then right?

#

For something like that, I would use a script like bash or python instead, unless you're going to do something more complicated. If you just want to run a binary and press a key, nothing a shell script can't handle

woven pythonBOT
#

Activities have been reset.