Autoit to AutoHotkey

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
M0TFF
Posts: 1
Joined: 29 Dec 2018, 07:52

Autoit to AutoHotkey

29 Dec 2018, 08:01

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.
just me
Posts: 9442
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Autoit to AutoHotkey

29 Dec 2018, 10:49

Is AutoIt using RGB colour values as default? The default for AHK is BGR.
User avatar
Delta Pythagorean
Posts: 627
Joined: 13 Feb 2017, 13:44
Location: Somewhere in the US
Contact:

Re: Autoit to AutoHotkey

31 Dec 2018, 01:40

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

[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat

jugador
Posts: 5
Joined: 31 Dec 2018, 15:10

Re: Autoit to AutoHotkey

31 Dec 2018, 15:20

Need help to translate the AutoIT code to AutoHotkey

Code: Select all

;WinActivate($Title)
$hWnd = WinGetHandle($Title)
$hWatch = ControlGetHandle($hWnd, "", 1003)
just me
Posts: 9442
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Autoit to AutoHotkey

01 Jan 2019, 08:33

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")
jugador
Posts: 5
Joined: 31 Dec 2018, 15:10

Re: Autoit to AutoHotkey

01 Jan 2019, 09:15

@just me Thank you for explaining the basic :)
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Autoit to AutoHotkey

01 Jan 2019, 13:04

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
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
jugador
Posts: 5
Joined: 31 Dec 2018, 15:10

Re: Autoit to AutoHotkey

02 Jan 2019, 00:43

Why thanks button missing :!:
Thanks @jeeswg :D
SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: Autoit to AutoHotkey

02 Jan 2019, 09:51

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

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada, Google [Bot], Haris00911, RussF and 305 guests