Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Toggle Button Creation


  • Please log in to reply
2 replies to this topic
Sir Daniel
  • Guests
  • Last active:
  • Joined: --
How does one go about making a toggle button in AHK?

I currently have a start button and have F12 set as stop, but I'd like the start button to turn into the stop button upon clicking it and vice versa.

I'd also like to know how to limit a text box's input to numbers only.

;
; AutoHotkey:     Version: 1.0.47.06
; Language:       English
; Platform:       Win9x/NT
; Author:         Sir Daniel
;

#NoEnv
#SingleInstance Force
Process Priority,,High
SendMode Input
SetBatchLines -1
SetWorkingDir %A_ScriptDir%
#NoTrayIcon

Gui, -Resize -MaximizeBox -MinimizeBox +AlwaysOnTop
Gui, Font, s9, Georgia
Gui, Add, Edit, y17 w76 vtext1, 1500
Gui, Add, Text, x92 y22 vMyText, Ms
Gui, Add, Button, x10 h25 w110, Start
Gui, Show, x309 y217 h84 w133, UberClicker
Return

ButtonStart:
Gui, Submit, NoHide
LoopBreak := False
Loop {
If (LoopBreak)
  Break
xx = %Text1%
Random, rand1, 0, 150
x2x := xx + Rand1
Click
Sleep, %x2x%
}
Return

F12::
LoopBreak := True
Return

GuiClose:
ExitApp
Return


Leef_me
  • Moderators
  • 8487 posts
  • Last active: Today, 05:44 PM
  • Joined: 08 Apr 2009

How does one go about making a toggle button in AHK?

I currently have a start button and have F12 set as stop, but I'd like the start button to turn into the stop button upon clicking it and vice versa.

You can make changes to a control based on displayed label, or a variable name. Since you want to change the label add a variable name to the button. This makes it easier to change the button name when you have a stable reference.
Gui, Add, Button, x10 h25 w110 [color=red]vstrt[/color], Start
where appropriate, change the name of the button
guicontrol,, [color=red]vstrt[/color], Stop

I'd also like to know how to limit a text box's input to numbers only.


Edit:
The control is an Edit box not a text box
I suggest reading about the edit options called Number and Limit
<!-- m -->http://www.autohotke... ... s.htm#Edit<!-- m -->

Leef_me

Hide/Show
  • Guests
  • Last active:
  • Joined: --
U could do this aswell...
#NoEnv
s := 0
Gui, Add, Edit, [color=red]Number[/color] Right w85 vED,  ; Only Numbers allowed
Gui, Add, Button, xm w40 h30 gStart Default, Start
Gui, Add, Button, xp w40 h30 gStop, Stop
Gui, Add, Button, x+5 w40 h30 gExit, E&xit
Gui, Show, , 
GuiControl, Hide, Stop ; On Startup hide the Ctrls u dont want to be shown/used
Return

GuiClose:
Exit:
$x::
ExitApp

Start:
s := 0
Gui,Submit, NoHide
GuiControl, Disable, ED
GuiControl, Hide, Start ; Just hide the Ctrls u dont want to be used
GuiControl, Show, Stop ; and show those u want to be displayed
Loop, {
 ToolTip, % ED -= 1
 Sleep, 100
 If(ED <= 0) || (S = 1)
    Break
}
GuiControl, Enable, ED
GuiControl, Hide, Stop
GuiControl, Show, Start
ToolTip
Return

Stop:
s := 1
GuiControl, Enable, ED
GuiControl, Hide, Stop
GuiControl, Show, Start
ToolTip
Return