gpt4 book ai didi

java - 有没有java函数可以在鼠标进入屏幕时将鼠标坐标更改为屏幕中心?

转载 作者:行者123 更新时间:2023-12-02 07:52:07 25 4
gpt4 key购买 nike

我知道有一个鼠标运动监听器可以检查鼠标何时进入应用程序。有没有办法让用户进入应用程序时鼠标移动到屏幕中央?游戏《我的世界》就是一个例子。一旦用户将鼠标指针悬停在应用程序内,鼠标点就会位于屏幕中心,任何鼠标移动都会决定您正在查看的内容。我正在尝试实现这一目标,但我只想知道如何使鼠标坐标更改为屏幕原点,而不使鼠标指针本身通过人体 Action 移动到屏幕。

    public static void main(String[] args) {
Jogl3DApp display = new Jogl3DApp();
// make display listen for mouse events
display.addMouseListener(display);
// make display listen for keyboard events
display.addKeyListener(display);
// Uncomment the following line to create a timer object and start it
// generating events, one every 30 milliseconds
new Timer(10, display).start();
// make display listen for the OpenGL graphics events
display.addGLEventListener(display);

// create a GUI window
JFrame window = new JFrame("Jogl Application");
// make window contain the display object
window.setContentPane(display);

window.setLocation(100, 100);
window.setVisible(true);
// A JFrame object's size includes the window decorations, like
// the title bar and borders. So if you want a 500x500 drawing space,
// you must set the window size a little bit bigger than that. Insets
// gives
// you the size of the decorations, so you make the window of size
// 500x500
// plus the size of the decorations.
Insets insets = window.getInsets();
window.setSize(500 + insets.right + insets.left, 500 + insets.top
+ insets.bottom);

// kills thread (in particular the timer event thread) when window is
// closed
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}
public void display(GLAutoDrawable drawable) {

// get the OpenGL context object
GL gl = drawable.getGL();
GLU glu = new GLU();
GLUT glut = new GLUT();
// clear the window
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

// replace what follows with your own drawing code
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
}

最佳答案

您可以使用java.awt.Robot类。我不相信在用户与屏幕交互时移动鼠标是一个很好的用户体验选择,但该类应该可以帮助您开始满足您的需要。

final Robot robot = new Robot();
robot.mouseMove(100, 100);

Robot - Javadoc

关于java - 有没有java函数可以在鼠标进入屏幕时将鼠标坐标更改为屏幕中心?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10115084/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com