Script dejo de funcionar.

Esta sección es para preguntas sobre programación/scripting usando AutoHotkey.

Moderator: Flipeador

lamgred
Posts: 8
Joined: 13 Aug 2021, 10:21

Script dejo de funcionar.

13 Aug 2021, 10:31

Hola, soy nuevo en esto, tengo el sgte codigo, me funcionaba bien:

Code: Select all

^a::
WinWait, ahk_exe SerialMonitor.exe
If WinExist("ahk_exe SerialMonitor.exe")
{
	WinActivate, ahk_exe SerialMonitor.exe
	If  WinActive("ahk_exe SerialMonitor.exe")
	{
	BlockInput On
	Send {LAlt down}V{LAlt up}
	Send {Down}{Down}{Down}
	send {Enter}
	Send {Down}{Down}
	send {Enter}
	BlockInput Off
	}
}
return

***
pero quise quitar ^a, y volverlo ejecutable, y al agregarle reload ExitApp antes de return dejo de funcionar mi script, el mismo lo pruebo con Notepad, y funciona, pero no con SerialMonitor, y antes si funcionaba, alguna ayuda, tendria que mejorar mi codigo, utilice esa forma porque WinMenuSelectItem no me funciona con SerialMonitor,
w0z
Posts: 230
Joined: 19 Jun 2014, 08:21

Re: Script dejo de funcionar.

13 Aug 2021, 18:18

Prueba de esta manera:

Code: Select all

^a::
WinWait, ahk_exe SerialMonitor.exe
If WinExist("ahk_exe SerialMonitor.exe")
{
	WinActivate
	If  WinActive("ahk_exe SerialMonitor.exe")
	{
		BlockInput On
		Send {LAlt down}V{LAlt up}
		Sleep, 500
		Send {Down 3}
		Sleep, 500
		send {Enter}
		Sleep, 500
		Send {Down 2}
		Sleep, 500
		send {Enter}
		BlockInput Off
	}
}
return

Podrias mostrar el codigo donde le pones el RELOAD que mencionas para ver donde podria estar el problema?
If I was helpful consider Donate me. :beer: , plz :D
lamgred
Posts: 8
Joined: 13 Aug 2021, 10:21

Re: Script dejo de funcionar.

14 Aug 2021, 08:14

no use los sleep ahi los probare, y mi problema fue cuando quise volverlo ejecutable asi que lo corri asi y autohotkey se ejecuto sin parar y tuve que reiniciar mi pc.

Code: Select all

#NoEnv
SendMode Input  
SetWorkingDir %A_ScriptDir%
#SingleInstance force
BlockInput On
#ErrorStdOut

WinWait, ahk_exe SerialMonitor.exe
If WinExist("ahk_exe SerialMonitor.exe")
{
	WinActivate, ahk_exe SerialMonitor.exe
	If  WinActive("ahk_exe SerialMonitor.exe")
	{
	BlockInput On
	Send {LAlt down}V{LAlt up}
	Send {Down}{Down}{Down}
	send {Enter}
	Send {Down}{Down}
	send {Enter}
	BlockInput Off
	}
}

Reload 

ESC::ExitApp

return

w0z
Posts: 230
Joined: 19 Jun 2014, 08:21

Re: Script dejo de funcionar.

14 Aug 2021, 11:44

lamgred wrote:
14 Aug 2021, 08:14
no use los sleep ahi los probare, y mi problema fue cuando quise volverlo ejecutable asi que lo corri asi y autohotkey se ejecuto sin parar y tuve que reiniciar mi pc.

Code: Select all

#NoEnv
SendMode Input  
SetWorkingDir %A_ScriptDir%
#SingleInstance force
BlockInput On
#ErrorStdOut

WinWait, ahk_exe SerialMonitor.exe
If WinExist("ahk_exe SerialMonitor.exe")
{
	WinActivate, ahk_exe SerialMonitor.exe
	If  WinActive("ahk_exe SerialMonitor.exe")
	{
	BlockInput On
	Send {LAlt down}V{LAlt up}
	Send {Down}{Down}{Down}
	send {Enter}
	Send {Down}{Down}
	send {Enter}
	BlockInput Off
	}
}

Reload 

ESC::ExitApp

return

Efectivamente el script se comportara como un loop infinito, cuando llega a la parte del Reload lo que hace es como si abriera el archivo por primera vez y se ejecuta todo el codigo hasta llegar al reload y vuelve a empezar infinitamente.

Entonces que es lo que quieres lograr que el script solo se ejecute un sola vez?.
O que este obedezca cuando presionas una combinacion de teclas cuando el SerialMonitor.exe este ejecutado? si esto es lo que quieres puede ser de la siguiente manera:

Code: Select all

#SingleInstance, force

#IfWinActive, ahk_exe SerialMonitor.exe
^a::
WinWait, ahk_exe SerialMonitor.exe
If WinExist("ahk_exe SerialMonitor.exe")
{
	WinActivate
	If WinActive("ahk_exe SerialMonitor.exe")
	{
		BlockInput On
		Send {LAlt down}v{LAlt up}
		Sleep, 500
		Send {Down 3}
		Sleep, 500
		send {Enter}
		Sleep, 500
		Send {Down 2}
		Sleep, 500
		send {Enter}
		BlockInput Off
	}
}
Return

ESC::ExitApp
#IfWinActive
If I was helpful consider Donate me. :beer: , plz :D
lamgred
Posts: 8
Joined: 13 Aug 2021, 10:21

Re: Script dejo de funcionar.

16 Aug 2021, 07:58

hola, gracias por la descripción de mi error, ya veo que por eso me fallaba, lo quiero es que el script se ejecute cada vez que presione un botón desde una pagina web o también crear algún botón gui en la pantalla por que ya lo hice para que funcione pero usando el teclado y al realizar el sgte codigo no me funciona correctamente se salta.

Code: Select all

#SingleInstance, Force

; GUI Layout
;-------------------------------------
Gui, Font, cWhite

Gui, Add, Text, x10 y10, Press the Button

Gui, Add, Button, x150 y150 w200 h30 gOur_First_Button, Press Me!

Gui, Add, Button, x200 y200 w100 h30 gOur_Second_Button, Abierto!

Gui, Add, Button, x200 y250 w100 h30 gOur_Third_Button, Exportar a Texto!

Gui, +AlwaysOnTop
Gui, Color, Black
Gui, Show, x800 y50 w500 h500, The Gui
return

; Lables
;-------------------------------------

GuiClose:
	;MsgBox, it´s me
	ExitApp
	return

Our_First_Button:
	a := 5
	b := 8	
	c := Add(a,b)
	MsgBox, a + b = %c% 
	return

Our_Second_Button:
	d := abierto()
	MsgBox, %d% 
	return
	
Our_Third_Button:
	abrir()
	return	
	
; Functions
;-------------------------------------	

Add(x,y){
	return x + y
}

abierto()
{
	if WinExist("ahk_exe SerialMonitor.exe") 
		return 1
	else
		return 0
}

abrir()
{
	WinWait, ahk_exe SerialMonitor.exe
	If WinExist("ahk_exe SerialMonitor.exe")
	{
		WinActivate, ahk_exe SerialMonitor.exe
		If  WinActive("ahk_exe SerialMonitor.exe")
		{
		BlockInput On
		Send {LAlt down}V{LAlt up}
		Sleep, 500
		Send {Down}{Down}{Down}
		Sleep, 500
		send {Enter}
		Sleep, 500
		Send {Down}{Down}
		Sleep, 500
		send {Enter}
		BlockInput Off
		}
	}

	Sleep, 200
	Clipboard:=	
	ClipSaved := ClipboardAll
	clipboard := "C:\xampp\htdocs\Archivos\"
	Send ^v
	sleep 500
	Clipboard := ClipSaved

	Sleep, 100
	ControlClick,Edit1,ahk_exe SerialMonitor.exe,,Right,1,D
	Sleep, 200
	ControlSend,Edit1,%Clipboard%,ahk_exe SerialMonitor.exe
	Send {Enter}
	Clipboard:=
	Clipboard:="prueba03"
	Sleep, 500
	Send {Escape}
	Sleep, 500
	ControlClick,Edit1,ahk_exe SerialMonitor.exe,,Right,1,D
	Sleep, 500
	ControlSend,Edit1,%Clipboard%,ahk_exe SerialMonitor.exe
	Sleep, 500

	Send {Tab}
	ControlClick, ComboBox2, ahk_exe SerialMonitor.exe
	Sleep, 200
	send {Home}
	Sleep, 200
	send {Down}

	Sleep, 1000	
	ControlClick, Button2, Guardar como
	Sleep, 1000

; Desde aquí salta , a veces lo realiza otras veces no.
	WinWait, ahk_exe SerialMonitor.exe
	Sleep, 500
	If WinExist("ahk_exe SerialMonitor.exe")
	{
		Sleep, 200
		WinActivate, ahk_exe SerialMonitor.exe
		If  WinActive("ahk_exe SerialMonitor.exe")
		{
		BlockInput On
		Send {LAlt down}S{LAlt up}
		Sleep, 500
		send {Right}
		BlockInput Off
		}
	}

	send {Escape}
	Sleep, 500
	WinWait, ahk_exe SerialMonitor.exe
	If WinExist("ahk_exe SerialMonitor.exe")
	{
		WinActivate, ahk_exe SerialMonitor.exe
		If  WinActive("ahk_exe SerialMonitor.exe")
		{
		BlockInput On
		Send {LAlt down}E{LAlt up}
		Sleep, 1000
		Send {Down}{Down}{Down}{Down}{Down}{Down}
		Sleep, 1000
		send {Enter}
		BlockInput Off
		}
	}

	return

}

w0z
Posts: 230
Joined: 19 Jun 2014, 08:21

Re: Script dejo de funcionar.

17 Aug 2021, 12:52

El programa SerialMonitor.exe donde se puede conseguir para probar.

Talvez en la parte donde pones ; Desde aquí salta , a veces lo realiza otras veces no. se abre otro tipo de ventana talvez la de guardar de windows explorer.
If I was helpful consider Donate me. :beer: , plz :D
w0z
Posts: 230
Joined: 19 Jun 2014, 08:21

Re: Script dejo de funcionar.

18 Aug 2021, 08:35

Baje el demo del SerialMonitor pero me lo instalo en la version SerialMonitorx64.exe.
este link https://www.mediafire.com/file/2tuchs367jmkjf9/serial_port.rar/file ya no tiene el archivo lo borro el host
serialmon.jpg
serialmon.jpg (126.94 KiB) Viewed 1982 times
que es lo quieres lograr en la parte que no funciona de tu codigo?
Podrías describir como lo harías normalmente? para darme una idea como se podría arreglar tu código.
If I was helpful consider Donate me. :beer: , plz :D
lamgred
Posts: 8
Joined: 13 Aug 2021, 10:21

Re: Script dejo de funcionar.

18 Aug 2021, 11:19

Lo que intento hacer es:
Cada Vez que se genera una acción el Equipo de Medición, que tiene puerto seria y esta conectado a una pc, se guarde las medidas generadas en Seria Monitor, guardarlo en una determinada direccion, en extencion ANSI txt, y que si encuentre repetido lo reemplace (ahi tengo problemas se salta ese paso), luego limpie toda la pantalla para que empiece de nuevo con una nueva medición.

Return to “Pedir Ayuda”

Who is online

Users browsing this forum: No registered users and 5 guests