public class RobotTest {
public static void main(String[] args){
test();
}
public static void test(){
User32Ext USER32EXT = (User32Ext) Native.loadLibrary("user32", User32Ext.class, W32APIOptions.DEFAULT_OPTIONS);
MousePointer ptr = new MousePointer();
USER32EXT.GetCursorPos(ptr);
System.out.println(ptr.getX()+" : "+ptr.getY());//此处打印0:0
}
}
public interface User32Ext extends User32 {
void GetCursorPos(MousePointer ptr);
}
public class MousePointer extends Structure {
public long x;
public long y;
public Pointer pointer;
public long getX() {
return x;
}
public void setX(long x) {
this.x = x;
}
public long getY() {
return y;
}
public void setY(long y) {
this.y = y;
}
public Pointer getPointer() {
return pointer;
}
public void setPointer(Pointer pointer) {
this.pointer = pointer;
}
/* (non-Javadoc)
* @see com.sun.jna.Structure#getFieldOrder()
*/
@Override
protected List getFieldOrder() {
List a = new ArrayList();
a.add("x");
a.add("y");
a.add("pointer");
return a;
}
}
这个是我自己写的尝试通过jna获取鼠标当前坐标的程序,但是不知道为什么打印出来的坐标都是0,有人能帮忙看一下吗?
------解决思路----------------------
有神马问题?基础实例的话,到我的博客那里看看那个入门吧,自己写的很详细
------解决思路----------------------
USER32EXT.GetCursorPos(ptr);
这个没有给ptr初始化x,y值,去debug看下内部实现吧。。。