我想從遊戲中獲取像素顏色並作出反應。 所以我有這個sript:AutoIT WinWaitActive不理解該窗口是活動的
#include <Color.au3>
Local $pause = False;
$WinName = "Game" ; Let's say there is a game with this name =)
$hwnd = WinGetHandle($WinName) ; Checked handle with powershell and Au3Info, handle is correct
local $res
Opt("PixelCoordMode", 2);
HotKeySet("{F10}", "exitNow");
HotKeySet("{F11}", "Pause");
While 1
;WinWaitActive($hwnd) ; The script stops here if it is uncommented no matter if window is active or not
if ($pause) Then
$res = GetPos();
ConsoleWrite (StringFormat ("Result color: %s %s", $res[0], $res[1]))
Sleep (1000)
EndIf
WEnd
Func exitNow()
Exit
EndFunc
Func Pause()
$pause = Not $pause
EndFunc
Func GetPos()
local $var = Hex(PixelGetColor(5, 5, $hwnd)) ; Only works in windowed mode, FullScreen return some random colors like 00FFFFFF or 00AAAAAA
$var = StringTrimLeft($var,2) ; Removing first 2 numbers they r always 00
local $var1 = Hex(PixelGetColor(15, 5, $hwnd)) ; Only works in windowed mode, FullScreen return some random colors like 00FFFFFF or 00AAAAAA
$var1 = StringTrimLeft($var1,2) ; Removing first 2 numbers they r always 00
local $result[2] = [ $var, $var1 ]
return $result
EndFunc
主要腳本之前應該窗口處於活動狀態,然後才應該儘量GetPixelColor但從未發生過,不管我做什麼,我已經試過WindowActivate仍然沒有結果。
a) - 我在做什麼錯?或者可能有另一種方法來檢查窗口當前是否處於活動狀態?
所以此刻我啓動腳本禁用,當我手動激活窗口時,我按F11啓用。
B) - PixelGetColor只有當遊戲在窗口模式下運行的工作,如果它是一個全屏模式的結果是不可預知的。有沒有辦法讓PixelGetColor全屏工作。
我試着用不同的組合運行遊戲x32,x64,DX9和DX11全屏結果是錯誤的。
新增:
趁現在這個樣子的,並且工作:) 感謝Xenobeologist!
While 1
$hwnd = WinGetHandle('[Active]');
If ($pause) Then
If WinGetTitle($hwnd) <> $WinName Then
Pause()
ContinueLoop
EndIf
$res = GetPos();
ConsoleWrite (StringFormat ("Result color: %s %s", $res[0], $res[1]))
Sleep (1000)
Else
If WinGetTitle($hwnd) = $WinName Then
Pause()
ContinueLoop
EndIf
EndIf
WEnd
一)現在解決
B)仍未解決。還有一件事,這個問題的主題並沒有提到這個問題,應該將這個問題添加到主題中,還是開始一個新的線程更好? a)是我的主要問題,它將是完美的解決b),但我可以沒有它的生活。據我瞭解,這更復雜。你怎麼看?
ADDED2:
據我明白問題b)中可以通過使用更復雜的代碼來解決。在這裏http://www.autohotkey.com/board/topic/63664-solved-imagesearch-failure-wdirectx-fullscreen-gamewin7/被討論了很相似的問題。這是AHK和ImageSearch功能,但我敢肯定,我在全屏中弄錯顏色的原因是一樣的。我不想使代碼複雜化太多,而PrintScreen太慢,所以我會使用窗口模式,並且不會受到b)的困擾。
是的!這實際上有助於=)問題a)解決了。任何線索如何解決問題b)? – BolnoYGaD 2014-12-03 17:15:07
我認爲這可以通過使用DirectX或視頻驅動程序來完成......我正在通過網絡搜索到目前爲止我無法理解或使用的任何內容 – BolnoYGaD 2014-12-03 17:27:12