Autoclick script cannot run even though no errors be found - autoit

I have construct a script for autoclick when I press F7, but by somehow the script cannot start. Can someone point out for me what I have wrong?
HotKeySet("{f7}","LoopFlagSwitch")
$loopflag = 0
Func autoclick()
While $loopflag = 1
MouseClick("left",1171,444,1,5)
Sleep(400)
MouseClick("left",666,477,1,5)
Sleep(400)
MouseClick("left",1171,499,1,5)
Sleep(400)
MouseClick("left",666,477,1,5)
Sleep(400)
MouseClick("left",1171,604,1,5)
Sleep(400)
MouseClick("left",666,477,1,5)
Sleep(400)
MouseClick("left",1113,680,1,5)
Sleep(700)
WEnd
EndFunc
Func LoopFlagSwitch()
If $loopflag == 0 Then
$loopflag = 1
autoclick()
Else
$loopflag = 0
EndIf
EndFunc

Your script ends before you are able to press the hotkey. You need to keep the script running, for example with an infinite loop as "main code":
HotKeySet("{f7}","LoopFlagSwitch")
$loopflag = 0
While True
Sleep(100)
WEnd
Func autoclick()
...
EndFunc
Func LoopFlagSwitch()
...
EndFunc

Related

How to resolve "UndefVarError: consume not defined" in JULIA

When I call consume(generator) I get this error. Is this a version problem?
function fib()
a = 0
produce(a)
b = 1
produce(b)
while true
a , b = b , a+b
produce(b)
end
end
generator = Task(fib)
consume(generator)
Here a way to do something similar using a Channel
global channel = Channel{Int}(1)
function fib()
# global here is not needed because we aren't modifying the channel handle, just the contents
# global channel
a = 0
put!(channel, a)
b = 1
put!(channel, b)
while true
a , b = b , a+b
put!(channel,b)
sleep(1)
end
end
#async while true; item = take!(channel); println("item: $item"); end
#async fib()
Note that #async will hide errors, so you may want to do a try catch with showerror(stderr, e, catch_backtrace()) if things are not running.
Each #async produces a Task handle.
Also the put! and take! will block when the channel if filled up. You may want to expand the channel size to handle a larger buffer.

Exception handling in a #testset in Julia

what is the prefered way to investigate or print out further detail (print input variable of a function, iteration number, etc.) of a failed #test inside a #testset?
I tried to wrap a try-catch-block around it. However, it doesn't seem to fire.
Here is a made-up example:
using Base.Test
rng = MersenneTwister(3231);
# define function that works different than expected
function compare(a,b)
if a == 3 && b == 3
return false
else
return a == b
end
end
# test function in a test set
#testset "Test Compare Function" begin
for iii = 1:10
number = rand(rng,1:10)
try
#test compare(number,number) == true
catch
#show(number)
end
end
end
Thank you very much!
You need to make sure it tests after the printing.
#testset "Test Compare Function" begin
for iii = 1:10
number = rand(rng,1:10)
#test begin
res = compare(number,number) == true
if !res
#show number
flush(STDOUT)
end
res
end
end
end

HTTP parser for Lua

I'm trying to parse http POST requests in Lua. My implementation works, but eats a hell lot of CPU load. This is critical, hence it is on an embedded platform.
I've looked on other implementations, but they can't fit, because my image is hardly fit in the memory, so I wouldn't use another library. I rolled my own parser, but it uses too much of system resource. Question is how could I optimize this to have lower CPU load.
This is an OpenWRT based system, so I only have Lua 5.1. This is the core function that looks for the boundary (in str variable). It reads the input block by block, and seeks for it.
The other solution would be to use LUCI libraries to do the heavy lifting, but I don't want my code to be integrated in LUCI.
--look for a pattern (str) and copy input until it is found to the output.
local function writeuntil(in_fp, str, out_fp)
local buff = ""
local ret = false
local bs = 4096 --Block size. The amount of data to read at once
local c = in_fp:read(bs)
local strStartPos = 1
while c do
local blockLen = string.len(c) --Not sure that a whole block is read, so get the size of the actual block.
local found = string.find(c, str, 1, true) --Try to locate str, so we don't have much work.
if (found ~= nil) then
if found > 2 then
out_fp:write(string.sub(c, 1, found - 1))
end
ret = true
break --we are done
else --Try to mach str till the end of the block
local strPos = string.find(c, string.sub(str, strStartPos, strStartPos), 1, true) --try to locate the first character
if strPos then --There is a starting character in the block
if (strPos > 1) then
out_fp:write(string.sub(c, 1, strPos - 1))
end
for i = strPos, blockLen do --iterate through the block
local ch = string.sub(c, i, i)
if ch == string.sub(str, strStartPos, strStartPos) then
buff = buff .. ch
if string.len(buff) == string.len(str) then
ret = true
break --We're done
end
strStartPos = strStartPos + 1
else --Lost track. Output.
if string.len(buff) > 0 then
out_fp:write(buff)
buff = ""
end
out_fp:write(ch)
strStartPos = 1
end
end
else
out_fp:write(c)
end
end
if ret then
break
end
c = in_fp:read(bs) --read next block
end
return ret
end
Egor, you were right, but I ended up this solution. It is now uses much less CPU. This not perfect hence scp is faster (although that is implemented in C).
--look for a pattern (str) and copy input until it is found to the output.
local function writeuntil(in_fp, str, out_fp)
local buff = ""
local ret = false
local bs = 4096 --Block size. The amount of data to read at once
local c = in_fp:read(bs)
local strStartPos = 1
local lastStrPos = 1
local needData = true
while c do
local blockLen = string.len(c) --Not sure that a whole block is read, so get the size of the actual block.
local found = string.find(c, str, 1, true) --Try to locate str, so we don't have much work.
if (found ~= nil) then
if found > 1 then
if #buff > 0 then
out_fp:write(buff)
end
out_fp:write(string.sub(c, 1, found - 1))
end
ret = true
break --we are done
else --Try to mach str till the end of the block
local strPos = string.find(c, string.sub(str, strStartPos, strStartPos), lastStrPos, true) --try to locate the first character
if strPos then --There is a starting character in the block
out_fp:write(string.sub(c, lastStrPos, strPos - 1))
for i = strPos, blockLen do --iterate through the block
local ch = string.sub(c, i, i)
if ch == string.sub(str, strStartPos, strStartPos) then
buff = buff .. ch
if string.len(buff) == string.len(str) then
ret = true
break --We're done
end
strStartPos = strStartPos + 1
lastStrPos = i + 1
else --Lost track. Output.
if string.len(buff) > 0 then
out_fp:write(buff)
buff = ""
end
out_fp:write(ch)
strStartPos = 1
if i == blockLen then
needData = true
else
lastStrPos = i + 1
needData = false
end
break
end
end
else
if ret == false then
if string.len(buff) > 0 then
out_fp:write(buff)
buff = ""
end
out_fp:write(string.sub(c, lastStrPos))
lastStrPos = 1
needData = true
else
break
end
end
end
if ret then
break
end
if needData then
c = in_fp:read(bs) --read next block
lastStrPos = 1
end
end
return ret
end

mpi understanding isend and irecv

I have 2 processes (0 and 1), 0 gets a random number, if not MOD(number,2)==0 and if it is bigger than the previous ones, then it sends (ISEND) to process 1.
Process 1 recives the number (RECV) and has to calculate if it is a prime number. If it is a prime number, then process 1 sends (ISEND) it to the process 0. Process 0 saves it as the highest prime number (not the final prime number, he generates an amount of random numbers that have to be checked).
So in the meanwhile process 1 is checking if the number received is a prime number, process 0 is already on another random number.
The point is that process 0 may overwrite the data in ISEND because process 1 is on its own work and not receiving. And I want this.
PROGRAM mpi_NonBlocking
USE MPI
IMPLICIT NONE
INTEGER :: ierr, myid ,npe, istatus(MPI_STATUS_SIZE), num, num_copy, best_prime=1, resto, i, n, now(3), req11
integer,parameter :: seed = 86456, numbers=200
INTEGER :: req1(numbers), req2(numbers)
LOGICAL :: flag, res
CALL MPI_INIT(ierr)
CALL MPI_COMM_RANK(MPI_COMM_WORLD,myid,ierr)
CALL MPI_COMM_SIZE(MPI_COMM_WORLD,npe,ierr)
IF (npe/=2) THEN
WRITE(*,*)'avviare il programma con 2 processi (-np 2 ./mpi_NonBlocking)'
ELSE
IF (myid == 0) THEN
OPEN(22,FILE='uomo_0.txt', STATUS="UNKNOWN", FORM= "FORMATTED")
OPEN(24,FILE='uomo_00.txt', STATUS="UNKNOWN", FORM= "FORMATTED")
CALL ITIME(now)
WRITE(*,*)
CALL SRAND(now(3))
DO n=1, numbers
req1(n)=0
req2(n)=0
num=IRAND()
WRITE(24,*)'random number',num
IF (num>best_prime) THEN
resto=MOD(num,2)
IF (resto==0 .and. num/=2) THEN
WRITE(24,*)'CYCLE'
CYCLE
END IF
END IF
WRITE(22,*)'uomo 0 SEND',num,'non-blocking'
WRITE(24,*)'uomo 0 SEND',num,'non-blocking'
CALL MPI_ISEND(num,1,MPI_INTEGER,1,1,MPI_COMM_WORLD,req1(n),ierr)
WRITE(24,*)num,req1(n)
CALL MPI_IRECV(best_prime,1,MPI_INTEGER,1,0,MPI_COMM_WORLD,req2(n),ierr)
END DO
CLOSE(22)
CALL MPI_SEND(-1,1,MPI_INTEGER,1,1,MPI_COMM_WORLD,ierr)
PRINT *,'best_prime is',best_prime
!DO i=1, numbers
!WRITE(24,*)'TEST isend',i,'flag value',req2(i)
!CALL MPI_TEST(req2(i),flag,istatus,ierr)
!IF (flag .eqv. .false.) THEN
!WRITE(24,*)'uomo 0 RECV',i,'non-blocking FAIL'
!ELSE IF (flag .eqv. .true.) THEN
!WRITE(24,*)'uomo 0 RECV',i,'non-blocking SUCCESS'
!END IF
!END DO
CLOSE(24)
ELSE
OPEN(23,FILE='uomo_1.txt', STATUS="UNKNOWN", FORM= "FORMATTED")
OPEN(25,FILE='uomo_11.txt', STATUS="UNKNOWN", FORM= "FORMATTED")
DO n=1, numbers
CALL MPI_RECV(num,1,MPI_INTEGER,0,myid,MPI_COMM_WORLD,istatus,ierr)
WRITE(23,*)'uomo 1 RECV',num
WRITE(25,*)'uomo 1 RECV',num
IF (num==-1) THEN
WRITE(23,*)'ABORT'
WRITE(25,*)'ABORT'
CALL EXIT(0)
END IF
res=.true.
num_copy=NINT(SQRT(REAL(num)))
WRITE(25,*)'sqrt',num_copy,'di num',num
DO i=3, num_copy, +2
resto=MOD(num,i)
IF (resto==0) THEN
res= .false.
WRITE(25,*)'num',num,'no numero primo'
EXIT !not numero primo
END IF
END DO
IF (res .eqv. .true.) THEN
WRITE(25,*)'num',num,'PRIMO'
WRITE(25,*)'uomo 1 SEND',num,'non-blocking'
CALL MPI_ISEND(num,1,MPI_INTEGER,0,0,MPI_COMM_WORLD,req11,ierr)
END IF
END DO
CLOSE(23)
CLOSE(25)
END IF
END IF
CALL MPI_FINALIZE(ierr)
END PROGRAM
The problem is, the overwite happens, but process 1 continues to receive the last number, sent from process 0, multiple times: it continues to receive exactly until he reaches the number of the isend calls of process 0.
105) uomo 0 SEND 1310474405 non-blocking
106) uomo 0 SEND 551041203 non-blocking
107) uomo 0 SEND 1400012957 non-blocking
108) uomo 0 SEND 907501537 non-blocking
109) uomo 0 SEND 949471365 non-blocking
61) uomo 1 RECV 792320847
62) uomo 1 RECV 2137864129
63) uomo 1 RECV 1888232175
64) uomo 1 RECV 4829859
65) uomo 1 RECV 2082851615
66) uomo 1 RECV 949471365
67) uomo 1 RECV 949471365
68-109) uomo 1 RECV 949471365
110) uomo1 RECV -1
111) ABORT

Pixel search in defined area

I want to pixel search a defined area. Application is Bluestacks App Player:
Blue rectangle is BlueStacks (its position may change). I get the position using ControlGetPos(). I only want to pixel search in red rectangle inside the app. Position of red rectangle is 307,628,355,675 based on window info with windows coordinate mode. But It's not working. Here's my code :
HotKeySet("{F2}", "mulai")
HotKeySet("{F3}", "berhenti")
Global $lokasi[2]
Global $warna
Global $penghitung
Global $nyala
Global $title = "BlueStacks App Player"
Global $hwnd = WinGetHandle($title)
Global $BSpos
Func berhenti()
Exit
EndFunc ;==>berhenti
Func getPos()
$aPos = ControlGetPos($title, "", "[CLASS:BlueStacksApp; INSTANCE:1]")
$tPoint = DllStructCreate("int X;int Y")
DllStructSetData($tPoint, "X", $aPos[0])
DllStructSetData($tPoint, "Y", $aPos[1])
_WinAPI_ClientToScreen(WinGetHandle(WinGetTitle($title)), $tPoint)
$BSpos[0] = DllStructGetData($tPoint, "X")
$BSpos[1] = DllStructGetData($tPoint, "Y")
EndFunc ;==>getPos
Func mulai()
$nyala = 1
While $nyala = 1
$pos = WinGetPos($hwnd)
WinActivate($hwnd)
$lokasi = PixelSearch($BSpos[0] , $BSpos[1], $BSpos[0] + $BSpos[2], $BSpos[1] + $BSpos[3], 0x0185B3)
MouseMove($lokasi[0], $lokasi[1], 0)
Sleep(200)
If #error Then
$penghitung = $penghitung + 1
EndIf
If $penghitung > 5 Then
$nyala = 0
EndIf
WEnd
EndFunc ;==>mulai
While 1
Sleep(200)
WEnd
It seems there's nothing wrong with the imagesearch library, the problem is I running windows 10 using x64bit. So compiling it using x64 compiler (while it really suggest to use x86 compiler) with administrator previllige solved the problem.

Resources