First script to work ,

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
MaxAstro
Posts: 557
Joined: 05 Oct 2016, 13:00

Re: First script to work ,

19 Feb 2018, 13:38

Oh wow that formatting is so bad I can barely parse your script. Lots of duplicated code, too. Let's see if we can clean that up a bit...

Code: Select all

#NoEnv
SetWorkingDir %A_ScriptDir%
CoordMode, Mouse, Window
SendMode Input
#SingleInstance Force
SetTitleMatchMode 2
#WinActivateForce
SetControlDelay 0
SetWinDelay 0
SetKeyDelay 0
SetMouseDelay 0
SetBatchLines -1

; These global variables make it easier to change things like directory locations
DupaTxt = C:\Users\dellpcwik9\Desktop\dupa.txt
Dupa2Txt = C:\Users\dellpcwik9\Desktop\dupa2.txt
Dupa2Bat = C:\Users\dellpcwik9\Desktop\dupa2.bat

F2::

Click, 1121, 366 Left, ,
Click, 1121, 366 Left, , ;   here will mark a number at first
Click, 1121, 366 Left, ,
Sleep, 50

send ^c       ; send i to clipboard 
Sleep, 20

If clipboard contains +49,0049,+49 , 0049 ,+32,0032,+32 ,0032 ,+33,0033,+33 ,0033 ,+352,00352,+352 ,00352 ,+41,0041,+41 ,0041 ,0039 ,+39,0039,+39 ,+31,0031,+31 ,0031 ,+43,0043,+43 ,0043 ,+44,0044,+44 ,0044 ,+420,00420,+420 ,00420 ,+45,0045,+45 ,0045 ,+47,0047,+47 ,0047 ,+352,00352,+352 ,00352 ,
	Send !^s    ;if number will contain the above-metioned numbers then will call imidiately by "frecall using number from clipboard
else
{
	FileDelete, %DupaTxt%
	Fileappend, %Clipboard%, %DupaTxt%          ; if dont have 0049/+49 etc...will copy number to doc.txt and deleting spacebars if are
	file := FileOpen(DupaTxt, "r")
	Haystack := file.Read()
	file.Close()
	Searchtext := A_Space
	ReplaceText := "-"
	NewNumber := StrReplace(Haystack, Searchtext, ReplaceText)
	FileDelete, %DupaTxt%
	Fileappend, %NewNumber%, %DupaTxt%

	Sleep, 20
	Sleep, 50
	
	Click, 335, 349 Left, ,   ;here will mark country for example "DE"
	Click, 335, 349 Left, ,
	Sleep, 50
	send ^c    ; here will add country to clipboard
	Sleep, 50

	If clipboard contains DE, DE ,
	{
		FileAppend, `n, %DupaTxt%                                
		FileAppend, start "C:\Program Files (x86)\FreeCall.com\FreeCall\FreeCall.exe" Callto:0049, %DupaTxt%  ;here will add number and directional of number
		Goto, DoCall
	}
	If clipboard contains AT, AT ,
	{
		FileAppend, `n, %DupaTxt%
		FileAppend, start "C:\Program Files (x86)\FreeCall.com\FreeCall\FreeCall.exe" Callto:0043, %DupaTxt%
		Goto, DoCall
	}
	If clipboard contains CZ, CZ ,
	{
		FileAppend, `n, %DupaTxt%
		FileAppend, start "C:\Program Files (x86)\FreeCall.com\FreeCall\FreeCall.exe" Callto:00420, %DupaTxt%
		Goto, DoCall
	}
	If clipboard contains FR, FR ,
	{
		FileAppend, `n, %DupaTxt%
		FileAppend, start "C:\Program Files (x86)\FreeCall.com\FreeCall\FreeCall.exe" Callto:0033, %DupaTxt%
		Goto, DoCall
	}
	If clipboard contains NL, NL ,
	{
		FileAppend, `n, %DupaTxt%
		FileAppend, start "C:\Program Files (x86)\FreeCall.com\FreeCall\FreeCall.exe" Callto:0031, %DupaTxt%
		Goto, DoCall
	}
	If clipboard contains BE
	{
		FileAppend, `n, %DupaTxt%
		FileAppend, start "C:\Program Files (x86)\FreeCall.com\FreeCall\FreeCall.exe" Callto:0032, %DupaTxt%
		Goto, DoCall
	}
	If clipboard contains GB
	{
		FileAppend, `n, %DupaTxt%
		FileAppend, start "C:\Program Files (x86)\FreeCall.com\FreeCall\FreeCall.exe" Callto:0044, %DupaTxt%
		Goto, DoCall
	}
	If clipboard contains DK
	{
		FileAppend, `n, %DupaTxt%
		FileAppend, start "C:\Program Files (x86)\FreeCall.com\FreeCall\FreeCall.exe" Callto:0045, %DupaTxt%
		Goto, DoCall
	}
	If clipboard contains IT
	{
		FileAppend, `n, %DupaTxt%
		FileAppend, start "C:\Program Files (x86)\FreeCall.com\FreeCall\FreeCall.exe" Callto:0039, %DupaTxt%
		Goto, DoCall
	}
	If clipboard contains LU
	{
		FileAppend, `n, %DupaTxt%
		FileAppend, start "C:\Program Files (x86)\FreeCall.com\FreeCall\FreeCall.exe" Callto:00352, %DupaTxt%
		Goto, DoCall
	}
	If clipboard contains HU, HU ,
		Goto, DontCall
	If clipboard contains BG, BG ,  ;change side will not call
		Goto, DontCall
	If clipboard contains RO
		Goto, DontCall
	If clipboard contains SI
		Goto, DontCall
	If clipboard contains LV
		Goto, DontCall
	If clipboard contains RS
		Goto, DontCall
	If clipboard contains SK
		Goto, DontCall
	If clipboard contains HR
		Goto, DontCall
	If clipboard contains BA
		Goto, DontCall
	If clipboard contains MD
		Goto, DontCall
	If clipboard contains PT
		Goto, DontCall
}
return

DontCall:
Click, 172, 229,
Sleep, 1000
Click, 356, 290,
return

DoCall:
FileDelete, %Dupa2Bat%

FileReadLine, r1, %DupaTxt%, 1 
FileReadLine, r2, %DupaTxt%, 2 
StringTrimLeft, r1, r1, 1
ifnotexist, %Dupa2Txt%
{
	Fileappend, %r2%%r1%, %Dupa2Txt%
	FileMove, %Dupa2Txt%, %Dupa2Bat%
	run, %Dupa2Bat%
}
return
Without having access to the exact program you are using, it's hard to say if I got that all right or if I messed anything up cleaning it up. I did find what looked like some incorrect brackets on some of the ifnotexist blocks. Is the whole fileappend/filemove/run supposed to be in the ifnotexist block, or just fileappend?

In any case, see if the cleaned up code still has the problem you are describing and get back to me.
MaxAstro
Posts: 557
Joined: 05 Oct 2016, 13:00

Re: First script to work ,

19 Feb 2018, 16:11

Honestly I don't know how fast if var contains is, I haven't used it much. I do know that checking the clipboard directly repeatedly can be slow, though. You might be able to make it faster by putting the line ClipSave = %clipboard% after you copy the number, and then replace each clipboard with ClipSave. That way the script only checks the clipboard once, which should be faster. So the first bit would look like this:

Code: Select all

send ^c       ; send i to clipboard 
Sleep, 20
ClipSave = %clipboard%

If ClipSave contains +49,0049,+49 , 0049 ,+32,0032,+32 ,0032 ,+33,0033,+33 ,0033 ,+352,00352,+352 ,00352 ,+41,0041,+41 ,0041 ,0039 ,+39,0039,+39 ,+31,0031,+31 ,0031 ,+43,0043,+43 ,0043 ,+44,0044,+44 ,0044 ,+420,00420,+420 ,00420 ,+45,0045,+45 ,0045 ,+47,0047,+47 ,0047 ,+352,00352,+352 ,00352 ,
	Send !^s    ;if number will contain the above-metioned numbers then will call imidiately by "frecall using number from clipboard
else
{
	FileDelete, %DupaTxt%
	Fileappend, %ClipSave%, %DupaTxt%          ; if dont have 0049/+49 etc...will copy number to doc.txt and deleting spacebars if are
	file := FileOpen(DupaTxt, "r")
	Haystack := file.Read()
	file.Close()
	Searchtext := A_Space
	ReplaceText := "-"
	NewNumber := StrReplace(Haystack, Searchtext, ReplaceText)
	FileDelete, %DupaTxt%
	Fileappend, %NewNumber%, %DupaTxt%

	Sleep, 20
	Sleep, 50
	
	Click, 335, 349 Left, ,   ;here will mark country for example "DE"
	Click, 335, 349 Left, ,
	Sleep, 50
	send ^c    ; here will add country to clipboard
	Sleep, 50
	ClipSave = %clipboard%

	If ClipSave contains DE, DE ,
	{
		FileAppend, `n, %DupaTxt%                                
		FileAppend, start "C:\Program Files (x86)\FreeCall.com\FreeCall\FreeCall.exe" Callto:0049, %DupaTxt%  ;here will add number and directional of number
		Goto, DoCall
	}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada, inseption86, jaka1 and 444 guests