Page 1 of 1

Autoit to AutoHotkey

Posted: 29 Dec 2018, 08:01
by M0TFF
Can someone please help me understand where I'm going wrong? I'm trying to convert an AutoIT script into AutoHotkey but it does not work.

Here is my original AutoIt script:

Code: Select all

$left = 350
$top = 140
$right = 1700
$bottom = 800
$shade = 5
$colour = 0xCF00FF
$colour2 = 0xBAACFF

HotKeySet("{F1}", "myExit")

While (1)
$pix = PixelSearch($left, $top, $right, $bottom, $colour2, $shade)

If Not (@error) Then
	If $pix\[0\] > 1260 Then
		$pix\[0\] = 1260
	ElseIf $pix\[0\] < 680 Then
		$pix\[0\] = 680
	ElseIf $pix\[1\] > 970 Then
		$pix\[0\] = 970
	ElseIf $pix\[1\] < 280 Then
		$pix\[0\] = 280
	EndIf

	MouseClick("right", $pix\[0\], $pix\[1\], 1, 3)
	Sleep(1000)

Else

	$pix2 = PixelSearch($left, $top, $right, $bottom, $colour, $shade)

	If Not (@error) Then
		If $pix2\[0\] > 1260 Then
			$pix2[0] = 1260
		ElseIf $pix2\[0\] < 680 Then
			$pix2[0] = 680
		ElseIf $pix2\[1\] > 970 Then
			$pix2[0] = 970
		ElseIf $pix2\[1\] < 280 Then
			$pix2[0] = 280
		EndIf

		MouseClick("right", $pix2\[0\], $pix2\[1\], 1, 3)
		Sleep(1000)

	EndIf

EndIf

WEnd

Func myExit()
Exit
EndFunc   ;==>myExit
Here is my conversion that does not work:

Code: Select all

#SingleInstance force

lefts = 350
tops = 140
rights = 1700
bottoms = 800
shade = 5
colour = 0xCF00FF
colour2 = 0xBAACFF

while(1)
{

PixelSearch, pixx, pixy, lefts, tops, rights, bottoms, colour2, shade

If (pixx != "")

{

	If pixx > 1260
		pixx = 1260
	Else If pixx < 680
		pixx = 680
	Else If pixy > 970
		pixx = 970
	Else If pixy < 280
		pixx = 280

		MouseClick, right, pixx, pixy, 1, 3
	Sleep, 1000

}	

Else

	PixelSearch, pix2x, pix2y, lefts, tops, rights, bottoms, colour, shade

If (pix2x != "")

{

	If pix2x > 1260
		pix2x = 1260
	Else If pix2x < 680		
		pix2x = 680
	Else If pix2y > 970
		pix2x = 970
	Else If pix2y < 280
		pix2x = 280

		MouseClick, right, pix2x, pix2y, 1, 3
	Sleep, 1000

}
}

Esc::ExitApp
^z::Pause
What have I missed, what am I doing wrong?

Thanks for any help.

Re: Autoit to AutoHotkey

Posted: 29 Dec 2018, 10:49
by just me
Is AutoIt using RGB colour values as default? The default for AHK is BGR.

Re: Autoit to AutoHotkey

Posted: 31 Dec 2018, 01:40
by Delta Pythagorean
MouseClick and PixelSearch parameters are not expression enabled. I.E. they must be in numbers or calling the variable like so:
MouseClick, Right, % PixX, % PixY, 1, 3

Re: Autoit to AutoHotkey

Posted: 31 Dec 2018, 15:20
by jugador
Need help to translate the AutoIT code to AutoHotkey

Code: Select all

;WinActivate($Title)
$hWnd = WinGetHandle($Title)
$hWatch = ControlGetHandle($hWnd, "", 1003)

Re: Autoit to AutoHotkey

Posted: 01 Jan 2019, 08:33
by just me
AutoIt:

Code: Select all

$hWnd = WinGetHandle($Title)
AHK:

Code: Select all

hWnd := WinExist(Title)

AutoIt:

Code: Select all

$hWatch = ControlGetHandle($hWnd, "", 1003)
AHK: 1003 seems to be the internal ID of the control (see ID). AHK does not have built-in support for these IDs. You should try to get the ClassNN of the control using AHK's Active Window Info / WindowSpy.

Code: Select all

ControlGet, hWatch, Hwnd, , ClassNN, ahk_id %hWnd%
Option:

Code: Select all

hWatch := DllCall("GetDlgItem", "Ptr", hWnd, "Int", 1003, "UPtr")

Re: Autoit to AutoHotkey

Posted: 01 Jan 2019, 09:15
by jugador
@just me Thank you for explaining the basic :)

Re: Autoit to AutoHotkey

Posted: 01 Jan 2019, 13:04
by jeeswg
Here's some code for getting control IDs, and converting control IDs to hWnds. Cheers.

Code: Select all

q:: ;controls - get IDs
WinGet, hWnd, ID, A
WinGet, vCtlList, ControlList, % "ahk_id " hWnd
vOutput := ""
Loop, Parse, vCtlList, `n
{
	vCtlClassNN := A_LoopField
	ControlGet, hCtl, Hwnd,, % vCtlClassNN, % "ahk_id " hWnd
	vCtlID := DllCall("user32\GetDlgCtrlID", Ptr,hCtl)
	vOutput .= vCtlID "`t" vCtlClassNN "`r`n"
}

Clipboard := vOutput
MsgBox, % vOutput
return

w:: ;notepad - control ID to hWnd
WinGet, hWnd, ID, A
vCtlID := 15 ;Edit control
vCtlID := 1025 ;status bar control
hCtl := DllCall("user32\GetDlgItem", Ptr,hWnd, Int,vCtlID, Ptr)
WinGetClass, vCtlClass, % "ahk_id " hCtl
MsgBox, % vCtlClass
return

Re: Autoit to AutoHotkey

Posted: 02 Jan 2019, 00:43
by jugador
Why thanks button missing :!:
Thanks @jeeswg :D

Re: Autoit to AutoHotkey

Posted: 02 Jan 2019, 09:51
by SOTE
You might be interested in various scripts done by nimdahk on GitHub. He had worked on some converter scripts for Autoit to AHK.

https://gist.github.com/nimdahk

AU3toAHK.ahk
AU3.ahk
Select.ahk
Switch.ahk