Hotkey Injput

Tire suas dúvidas sobre programação em AutoHotkey

Moderator: Gio

aedes
Posts: 7
Joined: 23 Apr 2021, 13:02

Hotkey Injput

Post by aedes » 26 Apr 2021, 18:14

Boa noite pessoal,

Estou apanhando para fazer um script que receba a hotkey do usuário e pause apenas uma rotina, no programa terão varias rotinas no mesmo script como esta da foto abaixo:
https://prnt.sc/12411dk

Onde está On/Off, seria a escolha do usuario para pausar ou iniciar a função do bot, sendo que dentro deste programa haverá mais funções parecidas.
Consegui fazer um script funcional, porem me rotona muitos erros ao escolher hotkey e ao abrir:

Quando executo
https://prnt.sc/1241703

Quando tento colocar a tecla Delete ou Backspace como hotkey.
https://prnt.sc/12418zd

Abaixo o Codigo de teste:

Code: Select all

#NoEnv
#Persistent
#SingleInstance Ignore
#KeyHistory 0
#MaxHotkeysPerInterval 99000000
#HotkeyInterval 99000000
SendMode Input
CoordMode, Pixel, Screen
CoordMode, Mouse, Screen
ListLines Off
SendMode Input
SetTitleMatchMode 2
SetTitleMatchMode Fast
CoordMode, Tooltipe
SetBatchLines, -1
Process, Priority, , A
SetKeyDelay, -1, -1, Play
SetMouseDelay, -1
SetWinDelay, 10
SetControlDelay, 0
SetDefaultMouseSpeed, 0
Gui,+AlwaysOnTop

start:
WinActivate, Projetor em janela (fonte) - Tibia
Sleep, 200
WinActivate, Tibia
;============ CHECKERS
{
ImageSearch,x_hp, y_hp, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, *20 img\imgbot\hp.png ; checa barra de vida
if (ErrorLevel = 0)
{
x_hp_superior = %x_hp%
y_hp_superior = %y_hp%
global x_hp_superior
global y_hp_superior -= 5
x_hp_inferior = %x_hp%
y_hp_inferior = %y_hp%
global x_hp_inferior += 110
global y_hp_inferior += 23
}
else
{
MsgBox, Abre Direito
goto start
}
}

Gui, Add, Hotkey, x142 y19 w60 h20 vonoffheal gonoffheal,
Gui, Add, Text, x212 y19 w50 h20 , On/Off
Gui, Font, S8 CDefault, Verdana
Gui, Add, Text, x32 y49 w50 h20 , [Hotkey]
Gui, Add, Text, x122 y49 w50 h20 , [HP`%]
Gui, Font, S10 CDefault, Verdana
Gui, Add, Hotkey, x32 y69 w60 h20 vhkheal1 ghkheal1, 
Gui, Add, DropDownList, x112 y69 w60 h300 vpcheal1 gpcheal1 , 99|90|80|70|60|50|40|30|20|10
Gui, Add, CheckBox, x192 y69 w20 h20 vligaheal1 gligaheal1, 
Gui, Add, Text, x12 y69 w20 h20 , 1.
Gui, Add, Hotkey, x32 y99 w60 h20 vhkheal2 ghkheal2, 
Gui, Add, DropDownList, x112 y99 w60 h300 vpcheal2 gpcheal2,99|90|80|70|60|50|40|30|20|10
Gui, Add, CheckBox, x192 y99 w20 h20 , 
Gui, Add, Text, x12 y99 w20 h20 , 2.
Gui, Add, Hotkey, x32 y129 w60 h20 vhkheal3 ghkheal3, 
Gui, Add, DropDownList, x112 y129 w60 h300 vpcheal3 gpcheal3, 99|90|80|70|60|50|40|30|20|10
Gui, Add, CheckBox, x192 y129 w20 h20 , 
Gui, Add, Text, x12 y129 w20 h20 , 3.
Gui, Show

; ============= HEAL SCRIPT
hkheal1:
hkheal2:
hkheal3:
ligaheal1:
ligaheal2:
ligaheal3:
pcheal1:
pcheal2:
pcheal3:

onoffheal:
Gui, Submit, nohide
Hotkey, %onoffheal%, zheal, On
return

zheal:
Gui, Submit
SetTimer, zcmdloop, % (toggle := !toggle) ? 0 : "Off"
return

zcmdloop:
{
GuiControlGet, hkheal1
GuiControlGet, hkheal2
GuiControlGet, hkheal3
GuiControlGet, pcheal1
GuiControlGet, pcheal2
GuiControlGet, pcheal3
if (ligaheal1 = 1)
{
IfWinActive, Tibia
{
ImageSearch,x_hp, y_hp, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, *20 img\imgbot\hp.png ; checa barra de vida
if (ErrorLevel = 0)
{
    ImageSearch, x, y, %x_hp_superior%, %y_hp_superior%, %x_hp_inferior%, %y_hp_inferior%, img\imghealth\%pcheal1%.png		;Cura com 90% da vida
    if (ErrorLevel = 1)
     {
        Send, {%hkheal1%}
    }
}
}
}
if (ligaheal2 = 1)
{
ImageSearch,x_hp, y_hp, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, *20 img\imgbot\hp.png ; checa barra de vida
if (ErrorLevel = 0)
{
    ImageSearch, x, y, %x_hp_superior%, %y_hp_superior%, %x_hp_inferior%, %y_hp_inferior%, img\imghealth\%pcheal2%.png		;Cura com 90% da vida
    if (ErrorLevel = 1)
     {
        Send, {%hkheal2%}
    }
}
}
if (ligaheal3 = 1)
{
ImageSearch,x_hp, y_hp, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, *20 img\imgbot\hp.png ; checa barra de vida
if (ErrorLevel = 0)
{
    ImageSearch, x, y, %x_hp_superior%, %y_hp_superior%, %x_hp_inferior%, %y_hp_inferior%, img\imghealth\%pchea3%.png		;Cura com 90% da vida
    if (ErrorLevel = 1)
     {
        Send, {%hkheal3%}
    }
}

}
}

GuiClose:
ExitApp

aedes
Posts: 7
Joined: 23 Apr 2021, 13:02

Re: Hotkey Injput

Post by aedes » 26 Apr 2021, 22:34

Resolvi pessoal, faltava apenas o detalhe o UseErrorLevel, para sumirem as mensagens de erro!

Code: Select all

Hotkey, %onoffheal%, zheal, On UseErrorLevel
Agora estou com uma questão de saber o status da Key On e Off, sendo que ela sempre inicia Off, alguém sabe como poderia informar ao usuario se está on ou off?

Post Reply

Return to “Ajuda e Suporte Geral”