Repeating codes
Repeating codes
Hello again. Can someone pls teach me how to do this? I want to set a hot key like control h to show me an input box where numbers are only allowed to 1000, then it will repeat this code enter down space based on the user's input. Pls help me. Example i will put 100 in the input box and what will it do is to execute enter down space a hundred times. Thank you for those who'll care.
Re: Repeating codes
Try this:
I hope that helps.
Code: Select all
While (Count < 1) or (Count > 1000)
{
InputBox, Count, Repetitions, Enter a number from 1 to 1000:
IfEqual, ErrorLevel, 1, ExitApp ; Cancel button pressed
}
Loop, %Count%
Send, {Enter}{Down}{Space
- Almost_there
- Posts: 404
- Joined: 30 Sep 2014, 10:32
Re: Repeating codes
Or try this - takes into consideration dumb users that fills in non-numeric values:
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
defaultValue := 1
timeOutSeconds := 5
; Ctrl+H
^h::
InputBox, userInput, Enter a number, Enter a number between 1 and 1000, , 400, Height, , , , timeOutSeconds, 100
If (errorlevel = 2) {
MsgBox, Time out - you failed to decide for a number....
Return
}
; Check if text is a valid number
userInput := 0 + userInput
if not userInput is number
{
MsgBox, %userInput% is a valid number
Return
}
; Check if number is between the limits
If (userInput > 1000)
{
MsgBox, %userInput% bigger than thousand.
Return
}
Loop {
Send, {Enter}
Send, {Down}
Send, % " "
} Until A_index = userInput
Return
Re: Repeating codes
After testing the two scripts above, i felt that the second one better suits my need. Thanks for the care both of you guys. But, there is one thing, the cancel button executes the same execution as Ok button in the second script. How to fix that?
Re: Repeating codes
I had used a hotkey to this. But whenever i pressed the control m again. There's no input box appears. It will execute the loop instantly.wolf_II wrote:Try this:I hope that helps.Code: Select all
While (Count < 1) or (Count > 1000) { InputBox, Count, Repetitions, Enter a number from 1 to 1000: IfEqual, ErrorLevel, 1, ExitApp ; Cancel button pressed } Loop, %Count% Send, {Enter}{Down}{Space
Re: Repeating codes
Try this: (can deal with non-numeric input)
I hope that helps.
Code: Select all
^m:: ; hotkey
Count := 0
While (Count < 1) or (Count > 1000)
{
InputBox, Count, Repetitions, Enter a number from 1 to 1000:
IfEqual, ErrorLevel, 1, Return ; Cancel button pressed
}
Loop, %Count%
Send, {Enter}{Down}{Space}
Return
- Almost_there
- Posts: 404
- Joined: 30 Sep 2014, 10:32
Re: Repeating codes
InputBox sets errorlevel = 1 when Cancel button was pressed, so:
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
defaultValue := 1
timeOutSeconds := 5
; Ctrl+H
^h::
InputBox, userInput, Enter a number, Enter a number between 1 and 1000, , 400, Height, , , , timeOutSeconds, 100
If (errorlevel = 2) {
MsgBox, Time out - you failed to decide for a number....
Return
} else If (errorlevel) {
MsgBox, Canceled by user.
Return
}
; Check if text is a valid number
userInput := 0 + userInput
if not userInput is number
{
MsgBox, %userInput% is a valid number
Return
}
; Check if number is between the limits
If (userInput > 1000)
{
MsgBox, %userInput% bigger than thousand.
Return
}
Loop {
Send, {Enter}
Send, {Down}
Send, % " "
} Until A_index = userInput
Return
Re: Repeating codes
I love it! Works perfectly as i wanted. My only problem now is i can't stop the process when i suddenly know that i'm pasting a wrong word. I have to wait for the process to end, i want an interruption key. Now, what i want to do is to stop the loop when i press space bar or enter. Pls help me. Can i put that addition codes inside the existing block because i only pasted this whole script inside my existing script and i'm worried if the additional codes might affect my other script.Almost_there wrote:InputBox sets errorlevel = 1 when Cancel button was pressed, so:
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. SendMode Input ; Recommended for new scripts due to its superior speed and reliability. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. defaultValue := 1 timeOutSeconds := 5 ; Ctrl+H ^h:: InputBox, userInput, Enter a number, Enter a number between 1 and 1000, , 400, Height, , , , timeOutSeconds, 100 If (errorlevel = 2) { MsgBox, Time out - you failed to decide for a number.... Return } else If (errorlevel) { MsgBox, Canceled by user. Return } ; Check if text is a valid number userInput := 0 + userInput if not userInput is number { MsgBox, %userInput% is a valid number Return } ; Check if number is between the limits If (userInput > 1000) { MsgBox, %userInput% bigger than thousand. Return } Loop { Send, {Enter} Send, {Down} Send, % " " } Until A_index = userInput Return
Re: Repeating codes
Sounds like you just explained the macro to build, a key that ends the process and enables another w/o the loops?neosickle wrote: I love it! Works perfectly as i wanted. My only problem now is i can't stop the process when i suddenly know that i'm pasting a wrong word. I have to wait for the process to end, i want an interruption key. Now, what i want to do is to stop the loop when i press space bar or enter. Pls help me. Can i put that addition codes inside the existing block because i only pasted this whole script inside my existing script and i'm worried if the additional codes might affect my other script.
Re: Repeating codes
Nope buddy, just a key to stop the process when space bar or enter key was pressed.
Re: Repeating codes
Loop {
Send, {Enter}
Send, {Down}
Send, % " "
}
How can i add space bar to break the process inside the block? I used if {Space} break but don't work. Pls help me.
Send, {Enter}
Send, {Down}
Send, % " "
}
How can i add space bar to break the process inside the block? I used if {Space} break but don't work. Pls help me.
- Almost_there
- Posts: 404
- Joined: 30 Sep 2014, 10:32
Re: Repeating codes
Like this (untested)
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
defaultValue := 1
timeOutSeconds := 5
; Ctrl+H
^h::
InputBox, userInput, Enter a number, Enter a number between 1 and 1000, , 400, Height, , , , timeOutSeconds, 100
If (errorlevel = 2) {
MsgBox, Time out - you failed to decide for a number....
Return
} else If (errorlevel) {
MsgBox, Canceled by user.
Return
}
; Check if text is a valid number
userInput := 0 + userInput
if not userInput is number
{
MsgBox, %userInput% is a valid number
Return
}
; Check if number is between the limits
If (userInput > 1000)
{
MsgBox, %userInput% bigger than thousand.
Return
}
Loop {
If GetKeyState("Space")
Return
Send, {Enter}
Send, {Down}
Send, % " "
} Until A_index = userInput
Return
Re: Repeating codes
Perfect! Solved my problem. Thank you very much!Almost_there wrote:Like this (untested)
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. SendMode Input ; Recommended for new scripts due to its superior speed and reliability. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. defaultValue := 1 timeOutSeconds := 5 ; Ctrl+H ^h:: InputBox, userInput, Enter a number, Enter a number between 1 and 1000, , 400, Height, , , , timeOutSeconds, 100 If (errorlevel = 2) { MsgBox, Time out - you failed to decide for a number.... Return } else If (errorlevel) { MsgBox, Canceled by user. Return } ; Check if text is a valid number userInput := 0 + userInput if not userInput is number { MsgBox, %userInput% is a valid number Return } ; Check if number is between the limits If (userInput > 1000) { MsgBox, %userInput% bigger than thousand. Return } Loop { If GetKeyState("Space") Return Send, {Enter} Send, {Down} Send, % " " } Until A_index = userInput Return