My idea was to a command like "Sleep, 2000" in a variable or even several commands.
In this example you would type in the hotstring, then the program would wait 2 seconds and then the message box would pop up and tell you that you've slept for 2 seconds.
However, I'm getting an error message for the line with "SleepVar1": "This line doesn't contain a recognized action"
SleepVar1 = Sleep, 2000
:*:svar::
SleepVar1
msgbox, You slept 2 seconds
return
There must be a way to achieve this, right? Maybe not with variable but something else.
As the names suggest:
Commands are orders, tasks given to the OS.
A variable is a placeholder for a value. The value can change, nevertheless a variable can only hold one value at a time.
To return a given value of a variable within commands, you need to enclose the variable in
percent signs
SleepVar1 = 2000
:*:svar1::
Sleep, %SleepVar1%
msgbox, You slept 2 seconds
return
or a function:
; :X*:svar2::SleepVar(3000)
; or
:*:svar2::
SleepVar(3000)
return
SleepVar(value){
Sleep, %value%
msgbox, You slept %value% miliseconds
}
Related
Is there a way to put a time.sleep in a minecraft function for Minecraft bedrock like in python?
For example:
/say this is a test!
time.sleep(5)
/say This is executed after the time.sleep
Please specify what a minecraft function is.
I assume you are using Minecraft: Java edition, to add delays in java you can use java.util.concurrent.TimeUnit
TimeUnit.SECONDS.sleep(1); Sleeps for one second.
TimeUnit.MINUTE.sleep(1); Sleeps for one minute.
You can make a sleep function but not how you tried to do it. I made a video for you to explain what I mean.
Give yourself a command block:
/give #s command_block
Place it and put your command into the window.
Place a command block next to it and put your second command in the window.
Change the presets to repeating always active and conditional.
Put the tick value in the last box. 20 ticks are equal to 1 second.
Use hopper clocks for timings, works as a charm
I have an ahk script which types a series of keys. It works up until the last key. When it comes to the last key, the AHK script just seems to hold down the key until I press another key manually or exit the script (which I don't want to do).
#SingleInstance force
Sleep, 3000
Send {r}
Sleep, 100
Send {u}
Sleep, 100
Send {n}
Sleep, 100
Exit
I mean, its a straight forward script but instead of seeing "run" I get "runnnnnnnnnnnnnnn(... to infinity)". It should be noted that if I make the sleep command longer, each key will be held down for that amount of time. 100 seconds ensures I only get the character once (except the last key) before moving on to the next.
How can I guarantee that the script will only press each key once?
I see nothing wrong with your use of the method, but your keyboard, lag/latency, and the specific program you're sending keys to can effect the reliability of the Send method. Clearly, your keyboard is not releasing the key at all, since you have to trim the Sleep to 100ms to ensure a single press. I use this custom KeyPress() method to help ensure keypresses in finicky programs. It sends the "press" and "release" portions of the keypress on different ticks. Sleeping by 1 ms ensures at least 1 tick will pass between commands.
Note that for this to work, you must pass a literal string to the Keypress() method. Hence, you must send the key you wish to press enclosed in double quotation marks
#SingleInstance force
F10::
{
KeyPress("r")
KeyPress("u")
KeyPress("n")
}
KeyPress(Key)
{
Send, {%Key% down}
Sleep 1
Send, {%Key% up}
Sleep 1
}
Responding to the comment stating that the X of the XY Problem is that OP wants a script that will Delay 3 seconds before sending "run".
#SingleInstance force
Sleep, 3000
SendInput run ;SendInput is more reliable than Send when trying to send plaintext to programs
I'm trying to send the output of my code to an inactive application using Auto Hotkey on my computer so I don't have to be on the screen and can do other stuff. How would I go about implementing it?
F1::
stop := 0
Loop
{
Send, z
Sleep 500
}until Stop
return
F2::Stop := 1
This is the code I have down so far, any help?
ControlSending might work. It's basically a hit or miss. It'll work for some applications, and for some it wont.
It'll be worth a try for you though.
Also, you're going to want to use a timer as opposed to looping in a hotkey thread. Timer is intended just for something like this and what you were doing is kind of bad practice for various reasons.
;timer runs the user-defined function "SendZ" every 500ms
F1::SetTimer, SendZ, 500
F2::SetTimer, SendZ, Off
SendZ()
{
ControlSend, , z, % "ahk_exe notepad.exe"
}
As a bonus, we can even write a sweet one liner to toggle on/off that timer by using a ternary:
F1::SetTimer, SendZ, % (Toggle:=!Toggle) ? 500 : "Off"
If that doesn't make sense to you, and you're interested, you can read a lengthy previous explanation of mine about it here.
printf("* What is your age: xxx *)
scanf("%d", &age);
Is there a way I change the order the way it is executed. The xxx is the place i want the age to be inputed, but i want the * at the end to be printed before i am prompted to enter a number. Currently it asks for the number on the next line.
The output i would like to see is like the following:
What is your age: (Input required)
(Notice the * is already printed while i am prompted for an input in a field before the *)
Please can someone show me how to rewrite this?
Sorry if this is confusing.
There is a very easy way to do this with a small problem. You can use your printf function in normal way.
printf("* What is your age: xxx *");
Since at this point the cursor is right side of last asterisk, you need to move it left side 5 time to bring it where the first x is.
If you are on Linux, \033[<N>D can be used to move cursor once to left.
(#ref http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x361.html).
Once the cursor is on first x, you can use your scanf function to prompt for number. But there is probability that user enters more than 3 digits and that asterisk will be cleared which is a problem.
Okay, so I'm trying to have the program do three steps...
1: choose a number between (m,n) which are parameters being passed in (Set to variable "repeat")
2: choose a random number between 0 and the variable "repeat" from step one. (Set to variable "o")
3: subract "o" from "repeat" and set that result to variable "p"
thus I get a number (lets say 100)
then a random number from 0-100 (lets say 40)
and then I get the difference of 100-40 (60...)
I then want the program to run a for loop "o" (40) times and another for loop "p" (60) times...
the code for the for loops section looks like this (keep in mind there is more code before this... It just doesn't really pertain to this question:
def randomStars(pic,m,n):
repeat=random.randint(200,300)
o=random.randint(0,repeat)
p=repeat-o
for i in o:
star(pic,x,y)
for j in p:
largeStar(pic,x,y)
show(pic)
What's happening is I'm getting an error message on the line:
for i in o:
that says "iteration over non-sequence
inappropriate argument type
I've also added print statements after the 3 variables are set and they are working...
ex.1 repeat=230; o=103; p=127
ex.2 repeat=221; o=72; p=149
and then I immediately try to get the for loop to run "o"number of times and I get the above error message... I don't see how it is a non-sequence. But perhaps I'm simply not understanding the definition of a sequence
o and p are integers. For for loops you need something that is iterable. I thing you can change it to:
for i in range(o):
This is range() documentation for Python 2.x