L
L
lif5272020-10-15 16:41:32
Java
lif527, 2020-10-15 16:41:32

How can I check for a key?

How do I check if the user has pressed the "x" key (You need to write the check in if)
here is my code:

import org.w3c.dom.events.Event;

import java.awt.*;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;

public class Main {

    public static void CloseTable() throws AWTException, InterruptedException {
        Robot rb = new Robot();
        if () {
            rb.mouseMove(1400, 750);
            rb.mousePress(InputEvent.BUTTON1_DOWN_MASK);
            rb.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
            Thread.sleep(100);
            rb.mouseMove(800, 225);
            rb.mousePress(InputEvent.BUTTON1_DOWN_MASK);
            rb.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
        }
    }

    public static void main(String[] args) throws InterruptedException, AWTException {
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Cheremisin, 2020-10-15
@leahch

Are you trying to do swing? The very first line in Google - https://www.google.com/search?channel=fs&client=ub...
gives out www.java2s.com/Tutorial/Java/0260__Swing-Event/Get...
If on a robot, then read here livecomp.blogspot.com/2013/02/java-robot.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question