Dom*_*nik 9 java import dll autoit jna
我想对我的Java程序中的屏幕事件做出反应,所以我想在实际屏幕中找到一个图像.我试着编写一个方法来从机器人类中获取一个截图,然后搜索像素 - 但它已经过了很长时间.
我知道在AutoIt中有一个外部DLL可以很好地完成这项工作,现在我试图让它在java中运行......但我被卡住了:/
.Ill在AutoIt中调用包括如下:
Func _ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance)
return _ImageSearchArea($findImage,$resultPosition,0,0,@DesktopWidth,@DesktopHeight,$x,$y,$tolerance)
EndFunc
Run Code Online (Sandbox Code Playgroud)
和:
Func _ImageSearchArea($findImage,$resultPosition,$x1,$y1,$right,$bottom,ByRef $x, ByRef $y, $tolerance)
if $tolerance>0 then $findImage = "*" & $tolerance & " " & $findImage
$result = DllCall("ImageSearchDLL.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"str",$findImage)
if $result[0]="0" then return 0
$array = StringSplit($result[0],"|")
$x=Int(Number($array[2]))
$y=Int(Number($array[3]))
if $resultPosition=1 then
$x=$x + Int(Number($array[4])/2)
$y=$y + Int(Number($array[5])/2)
endif
return 1
EndFunc
Run Code Online (Sandbox Code Playgroud)
我得到了dll并尝试了像jna这样的东西,但我无法让它工作.我还尝试使用AutoItX来使用Java运行AutoIt函数,但它不能用于包含.你能帮助我吗?
编辑:好的我在JNA上做了另一次尝试,现在我得到了一个String - 但是String意味着错误.有什么问题?我有一个界面:
public interface ImageSearchDLL extends Library{
ImageSearchDLL INSTANCE = (ImageSearchDLL) Native.loadLibrary("ImageSearchDLL", ImageSearchDLL.class);
String ImageSearch(int x1, int y1, int x2, int y2, String findImage);
}
Run Code Online (Sandbox Code Playgroud)
我称之为:
static {
File file = new File("libs", "ImageSearchDLL.dll");
System.load(file.getAbsolutePath());
}
(...)
String a = ImageSearchDLL.INSTANCE.ImageSearch(0, 0, 500, 500, "C:\myProg\OK.bmp");
Run Code Online (Sandbox Code Playgroud)
我总是得到"0"返回意味着错误或找不到像我在AutoIT文件中看到的那样:
; If error exit
if $result[0]="0" then return 0
Run Code Online (Sandbox Code Playgroud)
你能帮我解决这个问题吗?
您采用的路径的替代方法是生成Runtime.getRuntime().exec()
一个应用程序(c、autoit 脚本等),该应用程序执行图像搜索并利用基于文件/轮询方法(或通过标准输出)在它们之间进行通信,以便将结果发送到您的计算机。 java应用程序。