Technofyed

Full Version: AutoHotKey Macro Program (AHK)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I discovered this macro program several years back, and soon found out it is far more than a simple macro system you will find with most programs. It is capable of much more including the ability to create graphical user interfaces, otherwise known as, GUI's. The browser window you're reading this in right now is a GUI. Autohotkey has a vast amount of commands you can use to do practically whatever might need to be done. If you finish a program, and want to share it you can compile the script into an executable file (exe). The most impressive part is this software is it's still free, and will likely remain free. If you want to step into basic programming, and eventually learn advanced programming Autohotkey is a great place to start.

http://www.autohotkey.com/

Below is a script I wrote that compiles into a race game. Basically progress bars are turned into race progress with random processing. That ensures the end result is always random, and different. You start with a set amount of money, and bet on which progress bar will win the race. Please feel free to download Autohotkey, and run my interesting game! Smile

Quote:; RaceGame.AHK - Made by: .AHK

#NoEnv
#SingleInstance Ignore
Balance = 2000
R_Played = 0
Status1 = 1
Status2 = 1
Status3 = 1
Status4 = 1
Status5 = 1
Racer1W = 0
Racer2W = 0
Racer3W = 0
Racer4W = 0
Racer5W = 0
AmountW = 0
AmountL = 0
Racer1 = 0
Racer2 = 0
Racer3 = 0
Racer4 = 0
Racer5 = 0
Gui, Color, C0C0C0
Gui Font, S11
Gui Add, Progress, w350 h15 cBlue BackgroundWhite Range0-500 vRacer1
Gui Add, Progress, w350 h15 cBlack BackgroundWhite Range0-500 vRacer2
Gui Add, Progress, w350 h15 cRed BackgroundWhite Range0-500 vRacer3
Gui Add, Progress, w350 h15 cYellow BackgroundWhite Range0-500 vRacer4
Gui Add, Progress, w350 h15 cGreen BackgroundWhite Range0-500 vRacer5
Gui Add, Button, W75 H20 gStart, Start Race
Gui Add, Button, x+20 y+-20 W60 H20 gRestart, Restart
Gui Add, Text, x370 y8, Racer #1
Gui Add, Text, y+7, Racer #2
Gui Add, Text, y+7, Racer #3
Gui Add, Text, y+7, Racer #4
Gui Add, Text, y+7, Racer #5
Gui Add, Text, x275 y135, Balance
Gui Add, Edit, x+5 y+-20 r1 W100 +ReadOnly, $%Balance%
Gui Add, Radio, x10 vNoBet Checked, No Bet
Gui Add, Radio, x+5 y+-16 vBet1, Bet #1
Gui Add, Radio, x+5 y+-16 vBet2, Bet #2
Gui Add, Radio, x10 vBet3, Bet #3
Gui Add, Radio, x+9 y+-16 vBet4, Bet #4
Gui Add, Radio, x+5 y+-16 vBet5, Bet #5
Gui Add, Text, x243 y180, Amount to Bet
Gui Add, Edit, vBetAmount x+5 y+-20 r1 W70 Number Limit8, 100
Gui Add, Text, x10 y230, Rounds Played
Gui Add, Edit, x+5 y+-20 r1 W45 +ReadOnly, 0
Gui Add, Text, x+15 y+-20, Amount Won
Gui Add, Edit, x+5 y+-20 r1 W70 +ReadOnly, $0
Gui Add, Text, x+15 y+-20, Amount Lost
Gui Add, Edit, x+5 y+-20 r1 W70 +ReadOnly, $0
Gui Add, Edit, x430 y6 H20 W35 +ReadOnly, 0
Gui Add, Edit, y+3 H20 W35 +ReadOnly, 0
Gui Add, Edit, y+3 H20 W35 +ReadOnly, 0
Gui Add, Edit, y+3 H20 W35 +ReadOnly, 0
Gui Add, Edit, y+3 H20 W35 +ReadOnly, 0
Gui Show, Center, Race Game
Return

Restart:
Reload
Return

GuiClose:
ExitApp
Return

Start:
Gui +OwnDialogs
Gui Submit, NoHide

If betamount IS space
betamount = 0

If betamount > %balance%
{
MsgBox 0, Lower Bet, The amount to bet is above your balance.
Return
}

Loop {
Sleep 75
If (Status1 = 0 AND Status2 = 0 AND Status3 = 0 AND Status4 = 0 AND Status5 = 0)
Break

If Racer1 >= 500
{ Racer1W++
Break
}
If Racer2 >= 500
{ Racer2W++
Break
}
If Racer3 >= 500
{ Racer3W++
Break
}
If Racer4 >= 500
{ Racer4W++
Break
}
If Racer5 >= 500
{ Racer5W++
Break
}

n = 1
Gosub S_progress
If Complete = 1
Break

n = 2
Gosub S_progress
If Complete = 1
Break

n = 3
Gosub S_progress
If Complete = 1
Break

n = 4
Gosub S_progress
If Complete = 1
Break

n = 5
Gosub S_progress
If Complete = 1
Break
}

ControlSetText Edit1, $%balance%

If balance = 0
{
MsgBox 4, Game Over, You lost all your money! Restart the game?
IfMsgBox Yes
Reload
Else
ExitApp
}

R_Played++
ControlSetText Edit3, %R_Played%
ControlSetText Edit4, $%AmountW%
ControlSetText Edit5, $%AmountL%
ControlSetText Edit6, %Racer1W%
ControlSetText Edit7, %Racer2W%
ControlSetText Edit8, %Racer3W%
ControlSetText Edit9, %Racer4W%
ControlSetText Edit10, %Racer5W%
GuiControl,, Racer1, 0
GuiControl,, Racer2, 0
GuiControl,, Racer3, 0
GuiControl,, Racer4, 0
GuiControl,, Racer5, 0
Racer1 = 0
Racer2 = 0
Racer3 = 0
Racer4 = 0
Racer5 = 0
Complete = 0
Status1 = 1
Status2 = 1
Status3 = 1
Status4 = 1
Status5 = 1
Return

DeriveFall() {
Tn = 0
Loop 6 {
Random, Rn, 0,2
Tn += Rn
}
Return Tn
}

S_progress:
If Status%n% <> 0
Status%n% := DeriveFall()
If Status%n% = 0
Return
Random count, 1, 10
GuiControl,, Racer%n%, +%count%
Racer%n% := (Racer%n% + count)
If Racer%n% >= 500
If bet%n% = 1
{
balance := (balance + betamount)
amountw := (amountw + betamount)
Racer%n%W += 1
MsgBox 0, Win, You won $%betamount%
Complete = 1
} Else {
If nobet = 0
{
balance := (balance - betamount)
amountl := (amountl + betamount)
Racer%n%W += 1
MsgBox 0, Loss, You lost $%betamount%
Complete = 1
}
}
Return
I have that AHK file in my AHK folder. I play it from time to time. I lose big time, but oh well. Smile

My best program was WordFix if I remember correctly. Not very complicated compared to yours. Tongue
i love AHK. robert showed it to me. and since then i made one really dumb and korny gag program.
it was just a bunch of text boxes running along the lines of trying to convince the person that it's a self-destruct program. Ohh, and it beeps at the end...... Big Grin
I remember that. It actually wasn't that bad. I probably have it in my downloads folder. I'll look for it when I get home.
Remember that fake virus I made Robert? Smile
I think so. Do you still have the AHK file so you can post the script?
Just checked my AHK folder, and no I don't have it anymore... Sad
Aww, how unfortunate. Must have lost it in your last OS reinstall. Or maybe the one before that.
Or even the one before that... Smile
I thought you have only done 2 since I met you. Maybe I forgot one.
Hi Everyone..

I found out about AHK from a friend while we were playing Star Wars Galaxies. I used tasker at that time. Tasker blows now that i know what all can be done in AHK.

The only thing tasker seemed to do better was ctrldown, click, ctrlup at a very fast rate.
Hi stormturner, what scripts have you made with Autohotkey?
It reassign keys are the parameters of change in the map, you can use a joystick or keyboard and mouse, make a window transparent, always-on-top, or change its shape, manipulate the clipboard, customize menu icon tray and menu items.
Reference URL's