Autoit PixelGetColor not working - windows-8

Hello there everyone,
I have recently downloaded a bot for a game that I play, this bot uses Autoit to automate movements on screen, alongside Autoit I downloaded some scripts that allow me to automate in-game movements. I downloaded these scripts on my main pc and my laptop so I can run them on 2 accounts if need be. The download is exactly the same and although the bot works perfectly on my PC, it does something weird on my laptop:
The cursor seems to be able to go to places I have specificly told it to go but once it needs to imagesearch or pixelsearch it simply stops. The program doesnt stop running and will continue performing the actions that it can perform, at the right timing, however all imagesearching functions get left out.
The only major diference between the pc and laptop is that the laptop is running windows 8.
Things Iv tried by searching prior to asking here:
I have read that imagesearch.dll should be in sysWOW64 in order for it to work and I beleive I have done that by copying the DLL files and pasting them in syswow64. That did not help.
I also tried adding #requireadmin to the top of the script which did not help either.
this is happening with ALL the scripts I downloaded. They all work on pc and none work on laptop. I dont have alot of understanding with this code as I did not write it myself. However I have familirized myself with it a little as I do edit it for my personal uses on my pc and make it work very well. So I thought that it not functioning on my laptop must be some amateur mistake about windows 8 or similar.
here is an example script.
#RequireAdmin
#include <Misc.au3>
HotKeySet("{[}", "MakeLock")
HotKeySet("{z}", "Start")
HotKeySet("{ESC}", "_Exit")
HotKeySet("{x}", "Shafts")
HotKeySet("{c}", "Heads")
HotKeySet("{v}", "bsb")
$handle = WinGetHandle("Wurm Online", "")
Global $running=0
Global $shaftLoc
Global $headLoc
Global $shaft=0
Global $head=0
Global $bsb=0
Global $bsbloc
Func _Exit()
Exit
EndFunc ;==>_Exit
Func Getfrombsb()
MouseMove($bsbloc[0], $bsbloc[1], 5)
MouseDown("left")
Sleep(100)
MouseMove($shaftloc[0], $shaftloc[1], 5)
Sleep(100)
MouseUp("left")
sleep(2500)
send ("4")
sleep(250)
Send("{Enter}")
sleep(3000)
EndFunc
Func Shafts()
MsgBox(0, "", "title of items")
$shaft=1
EndFunc
Func Drop()
MouseMove($shaftloc[0], $shaftloc[1], 5)
MouseDown("left")
Sleep(250)
MouseMove($bsbloc[0], $bsbloc[1], 5)
MouseUp("left")
EndFunc
Func bsb()
MsgBox(0, "", "item in bsb")
$bsb=1
EndFunc
Func Heads()
MsgBox(0, "", "Click on what ur continuing")
$head=1
EndFunc
Func continue()
MouseMove($shaftloc[0], $shaftloc[1], 5)
MouseClick("left")
Sleep(100)
MouseMove($shaftloc[0], $shaftloc[1], 5)
MouseClick("right")
Sleep(1000)
$line = GetLine()
If IsArray($line) Then
Local $random2 = Random(200, 250, 1)
MouseMove($line[0], $line[1]+3*16-8, 5)
Sleep($random2-51)
MouseMove($line[0]+120, $line[1]+3*16-8, 5)
Sleep($random2+38)
MouseMove($line[0]+120, $line[1]+3*16-8+2*16, 5)
Sleep(500)
MouseMove($line[0]+200, $line[1]+3*16-8+2*16, 5)
Sleep($random2+161)
MouseMove($line[0]+200, $line[1]+3*16-8+2*16+44, 25)
Sleep($random2)
MouseClick("left")
EndIf
EndFunc
Func Start()
if $running==0 Then
$running=1
TrayTip("", "Macro started", 5)
ElseIf $running==1 Then
$running=0
TrayTip("", "Macro stopped", 5)
EndIf
EndFunc
Func GetLine()
$pos = MouseGetPos()
$samp = $pos
For $i = 0 To 48 Step 1
$samp[0] = $pos[0]+32
$samp[1] = $pos[1]+$i
$s0 = PixelGetColor($samp[0], $samp[1], $handle)
If $s0 == 0xFFFFFF Then
$s1 = PixelGetColor($samp[0]+1, $samp[1], $handle)
If $s1 == 0xFFFFFF Then
$s2 = PixelGetColor($samp[0]+2, $samp[1], $handle)
$s3 = PixelGetColor($samp[0]+3, $samp[1], $handle)
If $s2 == 0xFFFFFF AND $s3 == 0xFFFFFF Then
$line = $samp
ExitLoop
EndIf
EndIf
EndIf
$line = 0
Next
Return $line
EndFunc
While (1)
if _IsPressed("01") And $shaft==1 Then
$shaftloc = MouseGetPos()
$shaft=0
MsgBox(0, "", "shaft loc loaded")
endif
if _IsPressed("01") And $head==1 Then
$headloc = MouseGetPos()
$head=0
MsgBox(0, "", "head loc loaded")
EndIf
if _IsPressed("01") And $bsb==1 Then
$bsbloc = MouseGetPos()
$bsb=0
MsgBox(0, "", "bsb loc loaded")
EndIf
if $running==1 Then
Getfrombsb()
Local $random = Random(24000, 25000, 1)
continue()
Sleep($random)
sleep(500)
Drop()
sleep(2000)
Drop()
sleep(2000)
EndIf
Sleep(10)
WEnd
After watching exactly what it does and does not do, I can see that problem arrises with the section of code below it does everything up until; $line = GetLine()
$line = GetLine()
If IsArray($line) Then
Local $random2 = Random(200, 250, 1)
MouseMove($line[0], $line[1]+3*16-8, 5)
Sleep($random2-51)
MouseMove($line[0]+120, $line[1]+3*16-8, 5)
Sleep($random2+38)
MouseMove($line[0]+120, $line[1]+3*16-8+2*16, 5)
Sleep(500)
MouseMove($line[0]+200, $line[1]+3*16-8+2*16, 5)
Sleep($random2+161)
MouseMove($line[0]+200, $line[1]+3*16-8+2*16+44, 25)
Sleep($random2)
MouseClick("left")
EndIf
EndFunc
Any help would be appreciated. And although I am not familiar with code that much I do know how to use stack overflow well as my brother is a .net developer. I will mark the question that helps me and upvote and such.
Kind regards.

I know what your problem is.. I think. Try turning the output of PixelGetColor() into Hex.
Also, when it outputs, it doesnt include the "0x" at the beginning of the color tag.
So, you could say:
#Include <Misc.au3> ;for the _ispressed() function
Do
Until _IsPressed("01") ;wait for click
$mouse = MouseGetPos() ;Get cursor info
$color = Hex(PixelGetColor($mouse[0], $mouse[1]), 6) Get info on the pixel under the mouse.
;Lets just say the color is white
If $color == "FFFFFF" Then
MsgBox(0, "Success", "Colors match!")
EndIf
As for the ImageSearch not working, that could be a problem with AutoHotKey's compatability with Windows 8. Because of AutoIt not having a ImageSearch function, developers use AutoHotKey's ImageSearch function, and wrap it up in an AutoIt library. That may be where the problem is cominh

Related

Autoit HotKeySet bug

I have this code:
If $choixListAction == "ACTION1" Then
HotKeySet("{ENTER}", "_getPos")
EndIf
Func _getPos()
Global $posSouris = MouseGetPos()
$posX = MouseGetPos(0)
$posY = MouseGetPos(1)
Return $posX & ":" & $posY
EndFunc
I press ENTER but any action work.
Maybe your script isn't running anymore to process the hotkey. The following code works for me:
HotKeySet("{ENTER}", "_MyFunc")
While True
Sleep(150)
WEnd
Func _MyFunc()
MsgBox(0, "MyFunc", "Hello :)")
EndFunc ;==>_MyFunc

Create general purpose WinWaitActive in AutoIT

I'm thinking of using the WinWaitActive function to play a sound file every time the currently active program finished a task (ie. After Effect finished rendering, Word finished saving, etc.).
From what I know about WinWaitActive, I'll need to write a script for each internal process of each application. That's a huge amount of automation scripts. Is there any way to make a single script that will work with all programs and processes?
Try something like this:
#include<array.au3>
Global $window_Array[1]
$window = "dokument - wordpad"
checkWin()
;ConsoleWrite(_ArrayToString($window_Array, #CR))
Func checkWin()
Global $var = WinList()
For $i = 1 To $var[0][0]
If $var[$i][0] <> "" Then _ArrayAdd($window_Array, $var[$i][0])
Next
If _ArraySearch($window_Array, $window, 0, 0, 0) <> - 1 Then
MsgBox(0, "", "Found!")
Else
MsgBox(0, "", "Not Found!")
EndIf
EndFunc ;==>checkWin

Unable to save the file in specified location using Autoit

Followed the below steps to save a file in desired location:
Step1: Save As window getting opened(with the default downloads location, with file name as DOC)
Step2: entering the file name as "D:\temp\sample.pdf" (which is getting entered in the edit bar)
Step3: clicking the save button (button clicked, file downloaded in the default location rather than the "D:\temp" location)
I have created an .exe with the below .au3 script
WinWait("[CLASS:#32770]","",10)
Sleep(2000)
ControlSetText("Save As", "", "Edit1", $CmdLine[1])
Sleep(5000)
ControlClick("Save As", "", "Button1");
Sleep(5000)
On clicking save, it is getting saved in the default location rather than the specified location.
The below code, executing the script.
IO.popen('autoit_script.exe D:\temp') #Ruby Code
Is there a way to sort it out?
It depends on the software you are trying to automate but usually this happens because the software is not recognizing there is a change in the file save path box. The problem is in how ControlSetText works. Try using ControlSend with some error checking to make sure the file path you are try to set is getting put in right. Sometimes you have to play with a few different variations to see what works with the software you are automating. Here are two examples you can try:
Example one:
WinWait("[CLASS:#32770]", "", 10)
If Not #error Then ;make sure the window was found
$hWin = WinGetHandle("[CLASS:#32770]") ;get window handle
ControlSetText($hWin, "", "Edit1", $CmdLine[1]) ;set text
ControlFocus($hWin, "", "Edit1") ;just to make sure we have focus
ControlSend($hWin, "", "Edit1", "{ENTER}")) ;should work like click button 1 but you will have to check
;better then a sleep
$hTimer = TimerInit() ; Begin the timer and store the handle in a variable.
Do
Until WinExists($hWin) = 0 Or TimerDiff($hTimer) >= 10000
EndIf
Example two:
WinWait("[CLASS:#32770]", "", 10)
If Not #error Then ;make sure the window was found
$hWin = WinGetHandle("[CLASS:#32770]") ;get window handle
While 1
ControlSetText($hWin, "", "Edit1", "") ;just makes sure there is no text in the control text
ControlFocus($hWin, "", "Edit1") ;just to make sure we have focus
ControlSend($hWin, "", "Edit1", $CmdLine[1])) ;set text using ControlSend
If ControlGetText($hWin, "", "Edit1") = $CmdLine[1] Then ExitLoop ;makes sure that the control got ALL of the text before exiting loop
WEnd
ControlClick($hWin, "", "Button1");
;better then a sleep
$hTimer = TimerInit() ; Begin the timer and store the handle in a variable.
Do
Until WinExists($hWin) = 0 Or TimerDiff($hTimer) >= 10000
EndIf

AutoIt's ControlCommand does not pause while a button is grayed out

This script does not pause until the button is enabled:
While Not ControlCommand('Network config', '','QWidget1', 'IsEnabled', '')
Sleep(500)
WEnd
The button is grayed out initially.
Windows title: Network config
CLassnameNN: QWidget1
How can I fix this?
Local $cE = 0
AdlibRegister("enControl", 1000)
While 1
WEnd
Func enControl()
Local $wActive = WinActivate("Network config")
Local $isActive = WinActive($wActive)
If $isActive = 0 Then
ConsoleWrite("Could not make window active")
Return
EndIf
$cE = ControlEnable("Network config", ", "QWidget1")
If $cE = 0 Then
ConsoleWrite("Could not enable the control")
Else
ConsoleWrite("Succesfully enabled the control")
Sleep(500)
EndIf
EndFunc
Making sure the window is active and using ControlEnable function should help.

How to use _IEFormElementRadioSelect without finding a Form

I need this script to work, but without using _IEFormGetObjByName or _IEFormGetCollection, and while knowing only the Name of the radio buttons.
$oIE = _IE_Example ("form")
$oDoc = _IEDocGetObj($oIE)
$oArray = $oDoc.getElementsByTagName ("input")
For $element In $oArray
If $element.Name = "radioExample" Then
_IEFormElementRadioSelect ($oDoc,2, "radioExample", 1, "byIndex")
msgbox(0,"","Found it")
Endif
Next
_IEFormElementGetValue & _IEAction work great, just reference them to the $oElement, and search for an appropriate $element.Name, but I can't get the _IEFormElementRadioSelect to work.
The only difference between the _IEFormElementRadioSelect command from the example script found in the AutoIt helpfile is the reference to $oDoc. In the helpfile this is $oForm, which is found with a _IEFormGetObjByName, which I can't use (the site I'm automating doesn't return any forms).
Replace your _IEFormElementRadioSelect with _IEAction($element, "click")
Try this example; you can see the radio items being selected as the script runs:
#include <IE.au3>
$oIE = _IE_Example("form")
$oDoc = _IEDocGetObj($oIE)
$oArray = $oDoc.getElementsByTagName("input")
For $element In $oArray
If $element.Name = "radioExample" Then
_IEAction($element, "click")
Sleep(2000)
EndIf
Next