需要jna.jar和platform.jar
每隔3秒移动一下鼠标看console中的输出
import com.sun.jna.Native;
import com.sun.jna.win32.StdCallLibrary;
public class mouse_position {
public interface USER32 extends StdCallLibrary{
USER32 INSTANCE = (USER32) Native.loadLibrary("user32", USER32.class);
boolean GetCursorPos(int[] coor);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] pointer = new int[2];
for(int i=0;i<5;i++){
try {
Thread.sleep(3000);
}catch (InterruptedException e1) {
e1.printStackTrace();
}
USER32.INSTANCE.GetCursorPos(pointer);//获取当前鼠标位置
System.out.println(pointer[0]+"---"+pointer[1]);
}
}
}
含库源代码:http://pan.baidu.com/share/link?shareid=410163&uk=3878681452