I am learning java as a beginner and I was tasked to make an auto-click tool. I used JFrame as an Interface but now I'm stuck with this problem: - I want to get location of pointer related to screen after user clicked a button (Ctrl for example). I added a button on JFrame, click it and the JFrame will be minimized so user can move the pointer around desktop. - Whenever user pressed Ctrl key, I should println the x,y position of the pointer at that time. - I've been swum around to find a solution, but it seemed like my brain couldn't catch up.
It would be a very appreciation if anyone can provide me a simple example. Thanks. My idea so far:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
this.setState(JFrame.ICONIFIED);
this.addKeyListener(this);
}
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.CTRL_DOWN_MASK) {
PointerInfo a = MouseInfo.getPointerInfo();
Point b = a.getLocation();
int x = (int) b.getX();
int y = (int) b.getY();
System.out.println(x + ":" + y);
}
}