至於我現在用更快的方法:用於獲取鼠標位置
import java.awt.MouseInfo;
import java.awt.Point;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
public class nnn {
public static void main(String[] args) {
OutputStream os = new ByteArrayOutputStream();
while(true) {
Point point = MouseInfo.getPointerInfo().getLocation();
try {
ByteBuffer byteBuffer = ByteBuffer.allocate(8);
byteBuffer.putInt(point.x);
byteBuffer.putInt(point.y);
byte[] buffer = byteBuffer.array();
os.write(buffer);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
讓屏幕上的鼠標位置。它仍然是該計劃中最慢的部分。
它持續191520028ns(0.191),所以頻率是每秒5次,我需要的東西接近電影運動(每秒25次)。我不使用任何Swing或AWT組件。該應用程序嚴格命令行。
爲了更快地獲得更好的幫助,請發佈[MCTaRE](http://stackoverflow.com/help/mcve)(最小完整測試和可讀示例)。我真的懷疑,獲得鼠標位置需要很長時間。 –
@AndrewThompson,加... –
失敗!請*閱讀* MCTaRE上的文檔,而不是隨意猜測它的含義。這當然不是*'不可編譯的代碼片段'。 –