My first script help

Get help with using AutoHotkey and its commands and hotkeys
michael ceepo
Posts: 1
Joined: 22 May 2016, 21:10
Google: mike ceepo

My first script help

22 May 2016, 21:16

Here is my first script i wrote. Its a math test, very simple and basic, I wanted to know if any one had any tips to shorten the length of code and make it look better. Thanks :D


MsgBox, 4, , Want to Take a Test?
IfMsgBox, no
return
InputBox, OutputVar, MsgBox, First Whats Your Name?
if (OutputVar = Michael)
MsgBox Nice name %OutputVar%, Now lets take the test!!
else
MsgBox OK %OutputVar% lets go!!
Run, Notepad.exe
winactivate, Untitled - Notepad
send, Question 1. 2{+}2=? {enter}
send, {enter}
send, Answers{enter}
send, A. 3 TO ANSWER QUESTION HOLD CTRL BUTTON AND{enter}
send, B. 4 LETTER OF THE CORRECT ANSWER AT THE SAME{enter} ;correct answer
send, C. 5 TIME...... EX{:} [CTRL{+}A]
return
^a::
MsgBox Incorrect, Try Again
return
^c::
MsgBox Incorrect, Try Again
return
^b::
MsgBox Way To Go %OutputVar% Time for Question 2!
winactivate, Untitled - Notepad
send, {enter}
send, {enter}
send, {enter}
send, {enter}
send, Question 2. 4{+}3=? {enter}
send, {enter}
send, Answers{enter}
send, D. 5 {enter}
send, E. 8 {enter}
send, F. 7{enter} ;correct answer
return
^d::
MsgBox Incorrect Sorry
return
^e::
MsgBox Incorrect Sorry
return
^f::
MsgBox Correct!!!
winactivate, untitled - Notepad
send, {enter}
send, {enter}
send, {enter}
send, {enter}
send, Question 3. 5x2=? {enter}
send, {enter}
send, Answers{enter}
send, G. 6 {enter}
send, H. 10 {enter} ; correct answer
send, I. 8 {enter}
return
^g::
MsgBox Really? Try Again
return
^i::
MsgBox Closer, Try Again
return
^H::
msgBox Woah nice, Keep Going
winactivate, Untitled - Notepad
send, {enter}
send, {enter}
send, {enter}
send, {enter}
send, Question 4. 8x5=?
send, {enter}
send, Answers{enter}
send, J. 40 {enter}
send, K. 50 {enter}
send, L. 60 {enter}
return
^k::
MsgBox Wrong
return
^L::
MsgBox nope
return
^J::
MsgBox, 4, , woah Your smart!! You've Passed The Test!! Want To Try Part 2?
IfMsgBox, no
MsgBox OK!! EXIT OUT and Click Dont Save, Have a good day %OutputVar%
IfMsgBox, yes
winactivate, Untitled - Notepad
Send, {enter}
Send, {enter}
Send, {enter}
Send, {enter}
Send, {enter}
Send, {enter}
Send, {enter}
Send, {enter}
send, -----------------------------------PART 2------------------------------------------------{enter}
Send, {enter}
Send, {enter}
send, Welcome To Part Two{!}{enter}
send, These Questions Will be Harder{enter}
send, {enter}
send, {enter}
send, Question 1. What does pi Equal{?}{enter}
send, {enter}
send, O. 3.14 Rember to summit answers Hold Ctrl{+}Letter chosen{enter} ;correct answer
send, P. 2.14{enter}
send, Q. 3.15
return
^Q::
MsgBox Incorrect, Try Again
return
^p::
MsgBox Incorrect, Try Again
return
^O::
MsgBox Woah You Know Your Stuff
winactivate, Untitled - Notepad
Send, {enter}
send, {enter}
send, {enter}
send, {enter}
send, Question 2. 3.14x7 =?
send, {enter}
send, R. 29.21{enter}
send, S. 21.55{enter}
send, T. 21.98{enter} ;correct answer
Send, Need Some Help? Press [Alt{+}C]
return
!c::
run, C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories\Calculator
return
^r::
Msgbox WrongO!!!
return
^s::
Msgbox Incorrect
^t::
Msgbox Correct, Good Job!!
winactivate, Untitled - Notepad
send, {enter}
send, {enter}
send, {enter}
send, {enter}
Send, Question 3. 98x98=?{enter}
send, {enter}
Send, U. 9,604{enter} ;correct answer
send, V. 9,898{enter}
send, W. 9,904{enter}
return
^v::
Msgbox TRY AGAIN
return
^W::
Msgbox SO CLOSE, try again
return
^u::
Msgbox Yourrrrrrr RIGHT!!!
winactivate, Untitled - Notepad
send, {enter}
send, {enter}
send, {enter}
send, {enter}
send, Question 4. {(}FINAL QUESTION{)} 111{/}88=?{enter}
send, {enter}
send, X. 1,23{enter}
send, Y. 1.26{enter} ;correct answer
send, Z. 2.16{enter}
return
^x::
Msgbox incorrect
return
^Z::
Msgbox Try Again
return
^Y::
Msgbox FINALLY YOU WON, CONGRATS %OutputVar%!!
MsgBox NOW CLICK DONT SAVE AND HAVE A GOOD DAY, THANKS
winclose, C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories\Calculator
winclose, Untitled - Notepad
return
florisvos
Posts: 20
Joined: 15 Apr 2016, 06:26
Facebook: https://www.facebook.com/floris.vos.77

Re: My first script help

25 May 2016, 12:38

You understand the concept of:

InputBox, OutputVar, MsgBox, First Whats Your Name?
if (OutputVar = Michael)

How about:

InputBox, OutputVar, MsgBox, What is 1+1
if (OutputVar = 2)
etc.

And maybe throw a loop around it:


loop
{
InputBox, OutputVar, MsgBox, What is 1+1
if OutputVar = 2
break
msgbox Try again
}
msgbox Well Done!
Haswell
Posts: 46
Joined: 21 Feb 2016, 17:11

Re: My first script help

26 May 2016, 03:06

Instead:

Code: Select all

Send, {enter}
Send, {enter}
Send, {enter}
Send, {enter}
Send, {enter}
Send, {enter}
Send, {enter}
Send, {enter}
You may use:

Code: Select all

Send, {enter 8}
Focusing our efforts on non-productive and non-creative endeavours wastes lives as surely as war.
Jacque Fresco / The best that money can't buy

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], djuga, mikeyww, Reeyan283, tatagi and 27 guests