Python Forum

Full Version: convert autohotkey script to python / macro - press key when pixel get colour
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello!

Some time ago I switched from Windows to Mac.
So far I was using AutoHotkey to execute few simple scripts in 2D game called 'Tibia' on Windows, but AutoHotkey is not working on Mac.

Basically what I need is a macro which will watch pixel location on the screen while the game is on, and then if the pixel get specified colour it will press the key (F3 for example). However if the specified colour is keep being on the screen, the macro needs to keep pressing the key but with small pauses (0.5 sec for example).
I will appreciate it if someone could help me/give me some tips how to make it work on python

Below the AutoHotkey scripts for your reference. First one is checking the mouse location (x, y) and the colour ID. The other two work just as I describe it above.

Script1:

z::  ; Control+Alt+Z hotkey.
MouseGetPos, MouseX, MouseY
PixelGetColor, color, %MouseX%, %MouseY%
MsgBox The color at the current cursor position is %color% x= %MouseX% y= %MouseY% .
return
Script2:

Loop,
{        
    If WinActive("Tibia")
    {
        PixelGetColor, Check40, 1215, 219
        If (Check40 == 0x423F3C){
            SendInput {F3}
            Sleep, 200
        }
    }
    Sleep, 50
}
Script3:

#SingleInstance, Force
SetKeyDelay,0
x75 := 1299
HealthY := 286
Loop,
{
	If WinActive("Tibia")
	{
		PixelGetColor, Check75, %x75%, %HealthY%
		If (Check75 != 0x4F4FDB)
			Send, {F5}

	}
	Sleep, 400
}
Return
Thank you for your help!!
Maybe you can do it using https://pypi.org/project/PyAutoGUI/