Prompt User to input Integers between 30 and 100, press 0 to exit from loop, When user presses 0, display message 'press spacebar' - mit-scratch

Create a list called Numbers
Prompt the user to enter Integer number between (30-100)numbers to
the list
Keep asking the user to enter the numbers until he enter 0 to exit
from the loop Once the user press 0 “Display a message for the user
to “press a space bar” to print all numbers above 50
Once you print and all, then display a message said “Thank you ”
Now I have written the code, but it doesn't work after i press space bar

So you forgot to increment the new variable, and that loop that says the numbers actually loops 3 times instead of 4 on a 4-item list. So here is the working code:CLICK HERE

Try using a if-loop instead of a wait for space key...

There are three errors in the code:
Showing numbers should be outside repeat until answer = 0.
At the beginning NewVariable must be set to 1, not 0.
NewVariable must be incremented by one during showing numbers.
Here is corrected script.

Related

Trying to make a script that takes first word from a txt file, writes it, repeat till all words written

I have a text file, it has several lines. 1 line = 1 word
Now I want a script, if I press a specific button it will write the first word (first line). If I press the button again, the next word will be written, it goes like that till all words are written. I have tried to code it but it will only write the first word and will keep writing it.. It won't take next word and I don't know why because actually I have made a variable that increases...
Here is my code:
F11::
Index = 1
Array := Object()
Loop, Read, C:\Users\Emilia\Desktop\list.txt
{
Array.Push(A_LoopReadLine)
}
Send % Array[Index]
Index++
Use FileReadLine with a line number parameter
Keep the index variable outside in the global context so it doesn't get reset to 1 each time
Use SendPlay to send the word at once, not character-by-character.
You can switch the default send mode with SendMode play command.
Send Enter key at the end by adding {Enter} in the send command.
index = 1
F11::
FileReadLine line, C:\Users\Emilia\Desktop\list.txt, index
SendPlay %line%{Enter}
index++
Return

Autohotkey Input Times Out Because MatchList Isn't Matched

Here's my AHK script
:*:if ::
SendInput IF{Space}
Input cond, I V T5,, then
msgbox %ErrorLevel%
msgbox %cond%
if (ErrorLevel = "Match")
{
SendInput {Enter}End If{Space}'%cond%
}
Return
When I type If x = 1 then I get an ErrorLevel of 'Timeout' and a cond of 'x = 1 then'
My understanding is that when I type then it's supposed to stop the Input and set the ErrorLevel to Match.
I've tried putting it in quotes, using single letters in the MatchList, and including and end key, but none of works. The few examples I could find of using MathList look just like mine.
Input cond, I V T5 *,,% " then"
Without the asterisk option, an item in MatchList needs to be the next thing typed. So If Then would match then in the MatchList. But If anything then doesn't match then in the MatchList because it's trying to match anything then, not just then.
With the asterisk option, if anything then is matched because the next thing typed after If contained then. That causes problems if you type if heathen then because the then in heathen triggers it. The space before then should fix that, but it doesn't.
AHK help says that the MatchList respects spaces, but it doesn't seem to do that when the space is before the first (or only) item in MatchList. The two ways around that are to include a dummy word at the beginning or to use the % thingy to quote the MathList item and include the space.
See also http://ahkscript.org/boards/viewtopic.php?f=5&t=3979
I strongly recommend using RegEx powered hotstrings for this purpose:
#Include <Hotstrings>
hotstrings("if (.*?) then", "If %$1% then``nEnd If%A_SPACE%")
The definition of "T" in the AutoHotkey Help File states this:
T: Timeout (e.g. T3). The number of seconds to wait before terminating the
Input and setting ErrorLevel to the word Timeout. If the Input times out,
OutputVar will be set to whatever text the user had time to enter.
Basically, this is saying exactly what is to be expected (and what is actually happening) with your script. So, for me when I type "if x = 1 then" my "if" is immediately replaced with the caps lock IF and a space.
After 5 seconds, the first MsgBox appears with "Timeout" as the text (again, expected since ErrorLevel is set to the word "Timeout" when the "T" option is present). Once that MsgBox is dismissed, I receive the second MsgBox which (according to the help file) contains OutputVar which is what I (the user) had time to enter in before the Timeout.

Autohotkey: modify text file without ever opening

I'll start off by saying that I've sat around trying to figure out this for a good 8hrs and now I'm coming here to ask for help.
I want to be able to have a text file that starts at 0 and will increase by 1 every time I press the hotkey. I want this to happen without having the file open. This will be used as a counter.
Ken made a point with regard to knowing the initial value. If you want to ADD a number at the bottom you can use:
fileappend, %Counter%`n, C:\Temp\Counter.txt
Or if you want to JUST have that one number:
filedelete, C:\Temp\Counter.txt
fileappend, %Counter%, C:\Temp\Counter.txt
If you want to store a variable, you can use the .ini files to store various variables.
IniWrite, %TextCounter%, %A_ScriptDir%\Counter.ini, Counter, Nr
IniRead, TextCounter, %A_ScriptDir%\Counter.ini, Counter, Nr
I see this is an old question but it never got answered correctly. If you want to store a single number in a file and then increment that number with a hotkey here is a simplified version of the process:
FileRead to store the current number from the file into a variable
FileDelete to delete the old file (if you don't delete the file each time, step 4 will turn the file into a list of numbers.
add 1 to the variable.
FileAppend to store the updated variable back in the file.

Is it possible to create a macro like that with AHK?

I'm something like a GM in a MMORPG game. Our job is reporting people who using cheat and sending them to jail. But leaving that jail zone is not really hard so we have to send them again and again. I have a loooong nickname list (I have about 400 nicknames to report repeatly) so It's really boring.
What i wanna ask is, I don't know anything about AHK. If that kind of macro is possible, I'll do a loooong research to create that macro. But if It's not possible, I'm not even gonna try.
What i need is; The Macro will press "enter" to activate chat mode. Then will write "/report -cheater nickname-" and remember there's 400+ nicknames exist so I need to repeat the macro for different nicknames. After it write "/report -cheater nickname-" Macro will press enter. Then a little chat box will pop-up. Macro will click to the box, will write the report reason, then click confirm. then another chat box will pop-up to say something like "your report is received." And macro will click to confirm for that too. And will do it for 400+ nicknames with 400+ different reasons. Is that actually possible to do? Just wondering that. Not asking you to creating this macro. If you answer that, I'll try to make it myself :D
Thanks.
This script is to perform a series of searches on Google. The search strings are stored in a text file and read into an array, they are then executed one by one, based on hitting the {Tab} key (you can make this repeat automatically).
When the script is interrupted, you can start it again and give it a (new) starting number, or tell it to start from 1 again.
Not exactly what you were looking for, but it gives you a lot of starting points.
#Persistent
#SingleInstance Force
#installKeybdHook
SetWorkingDir %A_ScriptDir%
TempDir = C:\Temp
Menu, Tray, Icon , %A_AhkPath%, 2, 1
TrayTip, JobSearch, Started, 1
SetTitleMatchMode, 2
TextCounter = 0
Return
+Launch_App1::
Run, Notepad %TempDir%\Google.txt
Return
Launch_App1:: ; vacatures Job Search
+CapsLock::
Restart:
MouseGetPos, XPos2, YPos2
XPos3 := 50
YPos3 := 100
IniRead, TextCounter, %TempDir%\GoogleCounter.ini, Counter, Nr
ArrayCount = 0
Loop, Read, %TempDir%\Google.txt ; This loop retrieves each line from the file, one at a time.
{
ArrayCount += 1 ; Keep track of how many items are in the array.
Array%ArrayCount% := A_LoopReadLine ; Store this line in the next array element.
}
MaxSearchCount = %ArrayCount%
TextCounter += 1
If (TextCounter > 1)
InputBox, TextCounter , Start, Number (1..%MaxSearchCount%),,,,,,,10,%TextCounter% ; InputBox, OutputVar [, Title, Prompt, HIDE, Width, Height, X, Y, Font, Timeout, Default]
TextCounter += 0
IniWrite, %TextCounter%, %TempDir%\GoogleCounter.ini, Counter, Nr
SearchText:=Array%TextCounter%
MouseClick, left
gosub, SendNewSearch
Return
;=======================================================================================================================================
Browser_Favorites:: ; Search for next Vacature string (Vacatures)
CapsLock::
If (TextCounter = 0) ; Restart with previous script if Textcounter is set to 0
{
GoSub, Restart
Exit
}
IniRead, TextCounter, %TempDir%\GoogleCounter.ini, Counter, Nr
TextCounter += 1
IniWrite, %TextCounter%, %TempDir%\GoogleCounter.ini, Counter, Nr
SearchText:=Array%TextCounter%
If (SearchText = "")
{
TextCounter := 0
IniWrite, %TextCounter%, %TempDir%\GoogleCounter.ini, Counter, Nr
Send, ^{F4}
SplashTextOff
ExitApp
}
Sleep, 200
Send, {Home 2}
Sleep, 700
Send, {WheelUp 10}
Sleep, 400
gosub, SendNewSearch
Exit
SendNewSearch:
MouseGetPos, XPos3 ,YPos3
SetTitleMatchMode, 2
IfWinActive, Chrome
{
while (A_Cursor = "AppStarting")
Sleep, 200 ; Continue
Sleep, 100
SplashTextOff
MouseClick, left, %XPos2%,%YPos2%
WinGetTitle, this_title, A
IfInString, this_title, Google
{
Send, {Home}+{End}{DEL}%SearchText%{Enter}
}
ToolTip, Waiting....
DisplayText = Nr%TextCounter% %SearchText%
Sleep, 500
SplashTextOn, 200, 0,%DisplayText%
WinMove, %DisplayText%, , 800, 25
ToolTip
;MouseMove,(50),(500)
MouseMove,%XPos3%,%YPos3%
ClipBoard = %SearchText%
}
Exit
Exit
+Browser_Favorites::
run, %TempDir%\Google.txt
Return
It is possible to do. You can create two txt files which have list of +400 user names and +400 different reasons. Macro can read lines one by one and can makes all things, what you want, more than 400 times.
You will need this loop for writing lines from txt file to an array, a loop in a function for checking expected color at the specified pixel with PixelGetColor (http://www.autohotkey.com/docs/commands/PixelGetColor.htm) for detecting buttons. You may also use PixelGetColor command or AutoIt3 Window Spy, which will be installed with autohotkey, to see colors of buttons. Finally you can start to code from here (http://www.autohotkey.com/docs/).
PS. Sorry, site did not allow me to use more than 2 hyperlinks.
Basically you are trying to write a script that types enter, then a list of characters then enter again?
Something quite simple you could do would be to create a .txt file that includes everything you want it to type (excluding enters, except between lines), and create a macro like this:
#n::
Loop, Read, inputFile.txt
{
Send {Enter}%A_LoopReadLine%{Enter}
}
return
Basically you run the macro and open the game to the point that you can start typing enter, character information, enter, but press the windows key and the 'n' key. The macro would then loop through each line of 'inputFile.txt' and stimulate typing an enter, the line, and then an enter.

Question about complex loops

I'm writing a script in AutoHotKey, and I've stumbled upon an impasse. Right now I have a working GUI that involves checkboxes and dropdown lists. The program is a macro script for gaming-- the user checks which macros he wants running in the background, submits his options, and the program constantly evaluates various conditions and executes commands based on whether or not those conditions are satisfied.
The template of each one of the macros is this:
Loop:
PixelGetColor, color, 488, 778 ;gets pixel color of specific coordinate
if thecolor = 0x000000 ; if the color is black
{
SendInput {Raw}f ;sends the f command to use item
}
else sleep 20
goto, Loop
So the macro loops, evaluating a pixel each 2 miliseconds, and sending input if the if statement is fulfilled.
Here is the problem:
For each one of the macros that the user can check to run in the background, there is a different pixel color pinpointed, a different input sent, and a different coordinate to evaluate. How can I make an all-encompassing loop that takes into account the users check-box choices?
For example, if the checkBox = 1 (selected), I could be like:
if(%Box1%=1)
{
Run above code
}
But if the user checks 1 and 2, I'll have to evaluate other coordinates, too. Like thus:
if(%Box1%=1 & %Box2%=2)
{
Run above code
+
PixelGetColor, color2, 510, 778
if thecolor = 0x000000
{
Send 1
Sleep 20000
goto, start
}
else, sleep 20
I don't want to have multiple different loops that run one after another because it would too slow, and I don't want to have to do a huge branch of all the possible 'if' permutations.
Does anybody know what to do?
and I don't want to have to do a huge
branch of all the possible 'if'
permutations
The problem my friend is that that is the only solution.
You have to check the status of each checkbox, so there is no jumping that part.
If I could see your code I could send you an amendment for it, but you cannot paste the full code here. Try autohotkey.net/paste, and I will hopefully be able to help you.