If i'm using:
SetTimer, T1, 5000
T1:
Send, {1 Down} {1 Up}
return
..it runs 1st iterration after 5 seconds.
Is there a way to start 1st iterration immediately?
No, but you can just Gosub(docs) to the label right before (or after) launching the timer:
Gosub, T1
SetTimer, T1, 5000
T1:
Send, {1 Down} {1 Up}
return
Or if you want to ditch the legacy AHK and use a function, you can just call the function first:
T1()
SetTimer, T1, 5000
T1()
{
Send, {1 Down} {1 Up}
}
Or even call it inline:
SetTimer, % ("T1", T1()), 5000
To add on to #0x464e 's answer, you can do the following to run it just once but immediately in a pseudo-thread.
SetTimer, T1, -1
or
SetTimer, T1, -0 ; this works, but I don't recommended it as it's not documented.
You can read more about AutoHotkey threading here:
https://www.autohotkey.com/docs/misc/Threads.htm
Related
I am referring the SAS documentation page to understand the difference between DO while and DO until loops in SAS. While referring this document, I came to a conclusion that whenever I used DO while loop, the inequality of while statement should always less than (or less than or equal). The inequality cannot be greater than (or greater than or equal).
The reason is follows. When I ran this code:
data _null_;
n=0;
do while(n<5);
put n=;
n+1;
end;
run;
I got the output as 0,1,2,3,4.
But When I ran this code, I got nothing.
data _null_;
n=0;
do while(n>5);
put n=;
n+1;
end;
run;
Is my conclusion correct, or am I missing something?
Thank you
1:
It is not really whether you use > or <. But the logic of what to test is reversed. With DO WHILE() you execute the loop when the condition is TRUE. With DO UNTIL() you continue executing when the condition is FALSE.
11 data _null_;
12 do while(n<5);
13 put n #;
14 n+1;
15 end;
16 run;
0 1 2 3 4
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
17 data _null_;
18 do until(n>=5);
19 put n #;
20 n+1;
21 end;
22 run;
0 1 2 3 4
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
The other big difference is when the test is made. With DO WHILE() the test is before the loop starts. With DO UNTIL() it is after the loop finishes. So with DO UNTIL() the code always executes at least once.
Note your example is more easily done using an iterative DO loop instead.
6 data _null_;
7 do n=0 to 4;
8 put n #;
9 end;
10 run;
0 1 2 3 4
This question already has answers here:
How to escape the % (percent) sign in C's printf
(13 answers)
Closed 1 year ago.
fprintf(fptr, "#NoEnv SetWorkingDir %A_ScriptDir% CoordMode, Mouse, Window SendMode Input #SingleInstance Force SetTitleMatchMode 2 #WinActivateForce SetControlDelay 1 SetWinDelay 0 SetKeyDelay -1 SetMouseDelay -1 SetBatchLines -1 Loop { Sleep, 10 CoordMode, Pixel, Screen PixelSearch, FoundX, FoundY, 1324, 589, 1324, 589, 0x00786A, 0, RGB If ErrorLevel = 0 { Sleep, 1000 Click, 696, 728 Left, 1 Sleep, 10 Sleep, 300 Click, 775, 726 Left, 1 Sleep, 10 Sleep, 300 Click, 1273, 590 Left, 1 Sleep, 10 Return } else { sleep, 4000 Send {f5} sleep, 3000 Click, 1324, 589, 0 sleep, 10 }} Return")"");
Here is my code, not sure if it would work for what I'm doing, but it believes that the % and other stuff in the quotations are meant to be variables or whatever, how do I make it so it ignores all of that and just prints it?
fprintf stands for File Print Formatted.
In order to print unformatted, consider using fputs
You need to escape the %. You can do this by writing %% instead of %.
I've just started learning Java a few days ago.
I was trying to create a method with two parameters that prints the products of the two numbers, until the product is less than or equal to 200.
For example: the inputs are 5.0 and 0.5. I want this operation: 5.0 * 0.5, print the result (2.5), then I want the update to be increased by 0.1, so from 0.5 to 0.6. Make the operation again 5.0 * 0.6, print the result, increase the update to 0.7 and so on, until the result of the operation n*n is <=200.
Just like this:
inputs: 5.0, 0.5
print:
2,5
3
3,5
...
200
I don't understand why the loop is infinite, I guess the condition is ignored. What is the problem?
Here are some variations on the code I wrote
void ration(double lbs, double increment) {
for(double product=(lbs*increment); product <= 200.0; increment+=0.1){
System.out.println(lbs*increment);
}
}
this prints an infinite loop of the results between n*n (let's say 5 10 15 20 25..)
void ration(double lbs, double increment) {
for(double product=(lbs*increment); product <= 200.0; increment+=0.1){
System.out.println(product);
}
}
This prints the first result of n * n forver... (let's say 5 5 5 5 5 5..)
What am I doing wrong? Any advice would be greately appreciated.
Thank you
I made this code to copy and paste some data with autohotkey and according to the documentation I have done it correctly but the mouse click start from y=0 rather than the number i sat it before. the loop works fine it increments by 30px each time but I need to make it start from the number specified.
^j::
x_increment := 100
y_increment := 30
Loop, 15
{
clipboard := "" ; Start off empty to allow ClipWait to detect when the text has arrived.
y:= 175
y=y_offset
x:= 173
WinActivate, ahk_exe GoogleMapExtractor.exe
sleep 500
WinMaximize, ahk_exe GoogleMapExtractor.exe
Sleep, 500
MouseClick, left, x, y_offset, 1, 0, ,
Sleep, 100
MouseClick, left, x, y_offset, 1, 0, ,
Sleep, 100
MouseClick, left, x, y_offset, 1, 0, ,
Sleep, 500
Send ^a
sleep 500
Send ^c
sleep 500
;;;;;;;;;;;;;; EXCEL;;;;;;;;;;;;;;;;
WinActivate, ahk_exe Excel.exe
WinWaitActive, ahk_exe Excel.exe
Sleep 500
Send ^v
sleep 500
Send {Down}
sleep 500
y_offset+=y_increment
}
Return
The problem is with this line:
y=y_offset
Perhaps you meant to do this?
y += y_offset
I have a matlab/octave for loop which gives me an inf error messages along with the incorrect data
I'm trying to get 240,120,60,30,15... every number is divided by two then that number is also divided by two
but the code below gives me the wrong value when the number hits 30 and 5 and a couple of others it doesn't divide by two.
ang=240;
for aa=2:2:10
ang=[ang;ang/aa];
end
240
120
60
30
40
20
10
5
30
15
7.5
3.75
5
2.5
1.25
0.625
24
12
6
3
4
2
1
0.5
3
1.5
0.75
0.375
0.5
0.25
0.125
0.0625
PS: I will be accessing these values from different arrays, that's why I used a for loop so I can access the values using their indexes
In addition to the divide-by-zero error you were starting with (fixed in the edit), the approach you're taking isn't actually doing what you think it is. if you print out each step, you'll see why.
Instead of that approach, I suggest taking more of a "matlab way": avoid the loop by making use of vectorized operations.
orig = 240;
divisor = 2.^(0:5); #% vector of 2 to the power of [0 1 2 3 4 5]
ans = orig./divisor;
output:
ans = [240 120 60 30 15 7.5]
Try the following:
ang=240;
for aa=1:5
% sz=size(ang,1);
% ang=[ang;ang(sz)/2];
ang=[ang;ang(end)/2];
end
You should be getting warning: division by zero if you're running it in Octave. That says pretty much everything.
When you divide by zero, you get Inf. Because of your recursion... you see the problem.
You can simultaneously generalise and vectorise by using logic:
ang=240; %Replace 240 with any positive integer you like
ang=ang*2.^-(0:log2(ang));
ang=ang(1:sum(ang==floor(ang)));
This will work for any positive integer (to make it work for negatives as well, replace log2(ang) with log2(abs(ang))), and will produce the vector down to the point at which it goes odd, at which point the vector ends. It's also faster than jitendra's solution:
octave:26> tic; for i=1:100000 ang=240; ang=ang*2.^-(0:log2(ang)); ang=ang(1:sum(ang==floor(ang))); end; toc;
Elapsed time is 3.308 seconds.
octave:27> tic; for i=1:100000 ang=240; for aa=1:5 ang=[ang;ang(end)/2]; end; end; toc;
Elapsed time is 5.818 seconds.