Python Forum
convert autohotkey script to python / macro - press key when pixel get colour
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
convert autohotkey script to python / macro - press key when pixel get colour
#1
Question 
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!!
Reply
#2
Maybe you can do it using https://pypi.org/project/PyAutoGUI/
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Voxel to pixel graphics voicemail 3 585 Nov-19-2023, 09:45 AM
Last Post: paul18fr
  [Python 2.7] Why can't I press [ESC] a fourth time? Ashwood 3 661 Aug-27-2023, 02:01 PM
Last Post: deanhystad
  Is there a *.bat DOS batch script to *.py Python Script converter? pstein 3 3,266 Jun-29-2023, 11:57 AM
Last Post: gologica
  Python Script to convert Json to CSV file chvsnarayana 8 2,534 Apr-26-2023, 10:31 PM
Last Post: DeaD_EyE
  Pixel color and action Sartre 4 2,099 Apr-13-2023, 03:26 AM
Last Post: Sartre
  Dynamic pixel display jerryf 2 731 Mar-17-2023, 07:26 PM
Last Post: jerryf
  Auto-populate Macro variables Spartan314 3 2,673 Mar-08-2021, 12:36 AM
Last Post: Spartan314
  How do I reduce the time to Invoke Macro via Python? JaneTan 1 2,137 Dec-28-2020, 06:46 AM
Last Post: buran
  Plotting Pixel Intensity Doev 0 1,728 Oct-21-2020, 10:56 PM
Last Post: Doev
  Convert .py script to dll file and .exe srikanthpython 0 3,137 Aug-20-2020, 06:01 PM
Last Post: srikanthpython

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020