I am making a AHK script for a discord counter. Useless stuff but im trying to learn how to AHK and work with a GUI system. This is my first time making a GUI and i have a working counter code. I want to make it user friendly by making a gui so you can change the values.
I have tried adding % and removing % around the variables. At this point I'm really confused.
This is the working NON GUI code I'm using
F11::Goto,lol
ESC::ExitApp,
lol:
; example add 1
VAR1 := (1)
VAR2 := (11492)
Loop,300
{
VAR2 := (VAR2+VAR1)
Send, %VAR2%
Send, {Enter}
Sleep, 6500
}
return
And this is the code im using with my GUI system with variables.
; Simple counter script. This is for Discord counting
Gui, Show , w210 h200, Counter
; GUI stuff
Gui, Add, Text, x20 y10 w130 Left,Input a number for delay:
Gui, Add, Text, x20 y50 w130 Left,Input a starting number:
Gui, Add, Text, x20 y90 w130 Left,Input a number to add by:
Gui, Add, Text, x20 y120 w130 Left,Input a number for the number of loops:
Gui, Add, Text, x0 y160 w200 Center,Press F11 to start the script
Gui, Add, Text, x0 y180 w200 Center,Made by Pyro#5249
Gui, Add, Edit, w50 h19 x150 y10 vDelay Left,
Gui, Add, Edit, w50 h19 x150 y50 vSTART Left,
Gui, Add, Edit, w50 h19 x150 y90 vADD Left,
Gui, Add, Edit, w50 h19 x150 y120 vLOOP Left,
F11::goto,lol
return
lol:
{
VAR1 := (%ADD%)
VAR2 := (%START%)
Loop,%LOOP%
{
VAR2 := (VAR2+VAR1)
Send, %VAR2%
Send, {Enter}
Sleep, %DELAY%
}
return
}
GuiClose:
ExitApp
ESC::ExitApp,
I want it to start on F11 and start listing off the couning. Such as
1
2
3
4
5
6
ect...
But as of now im not getting anything. No results.
You have a good start! Here are a few things that should help:
If you want to get values from a GUI, you need to use Gui , Submit. If you want the Gui to stay up, use the NoHide option (Gui , Submit , NoHide).
When you are assigning values using :=, percents aren't used. So, VAR := ADD would assign the value of the variable "ADD" to the variable "VAR". You can assign values with just = and you wouldn't need to use percent-signs as you have it (VAR = %ADD%), but this is only supported for legacy and isn't recommended for new scripts.
Some things need to be enclosed in braces {} as you have done with the loop, but some things do not, such as the "lol" label.
You can send multiple things in one send command instead of splitting it into two separate send commands.
The AutoHotkey help documentation is excellent and will give a good understanding of proper syntax. Here is a working example of your script with it showing a message box counter since I don't know where you want to type the values (I commented that portion out).
; Simple counter script. This is for Discord counting
Gui, Show , w210 h200, Counter
; GUI stuff
Gui, Add, Text, x20 y10 w130 Left,Input a number for delay (ms):
Gui, Add, Text, x20 y50 w130 Left,Input a starting number:
Gui, Add, Text, x20 y90 w130 Left,Input a number to add by:
Gui, Add, Text, x20 y120 w130 Left,Input a number for the amount of loops:
Gui, Add, Text, x0 y160 w200 Center,Press F11 to start the script
Gui, Add, Text, x0 y180 w200 Center,Made by Pyro#5249
Gui, Add, Edit, w50 h19 x150 y10 vDelay Left,
Gui, Add, Edit, w50 h19 x150 y50 vSTART Left,
Gui, Add, Edit, w50 h19 x150 y90 vADD Left,
Gui, Add, Edit, w50 h19 x150 y120 vLOOP Left,
F11::goto,lol
return
lol:
Gui , Submit , NoHide
VAR1 := ADD
VAR2 := START
Loop , %LOOP%
{
VAR2 += VAR1
MsgBox ,, Counter , Counter value = %VAR2% , % DELAY / 2000
Sleep , % DELAY / 2 ; halved delay since MsgBox is also half the delay
; Send, %VAR2%{Enter}
; Sleep, %DELAY%
}
return
GuiClose:
ExitApp
Related
I've created a GUI using AHK. I am storing the Id and description as key-value pairs. I want to update the Desc when the user enters the ID with the corresponding desc stored in the associative array. How can I dynamically updated the GUI?
^h::
oKeys := []
oValues := []
oArray := {}
if (WinExist("ahk_id " hwndgui)) {
Gui, Destroy
return
}
gui, add, text,, Type:
Gui, Add, DropDownList,vType, TSO|PAX|DVI
gui, add, text,, ID:
Gui, Add, Edit, vId
gui, add, text,, Partial|Complete:
Gui, Add, DropDownList,vPartial, Partial||Complete
gui, add, text,, Left-Behind:
Gui, Add, DropDownList,vLeft, False||True
gui, add, text,, XFR-Type:
Gui, Add, DropDownList,vXFR, Standard||Contact|Theft
gui, add, text,, DESC:
Gui, Add, Edit, vDesc , oArray[(TypeId)]
Gui, Add, Button, Default gOK, OK
Gui, Show, Hide
Gui, +LastFound
hwndgui:=WinExist()
OK:
Gui, Submit
oKeys.Push((TypeId))
oValues.Push((Desc))
Loop, % oKeys.Length()
oArray[oKeys[A_Index]] := oValues[A_Index]
if WinExist("labelImg")
WinActivate ; Uses the last found window.
Send, ^a
Send, %Type%_%Id%_%Partial%_%Desc%
for vKey, vValue in oArray
vOutput .= vKey " " vValue "`r`n"
MsgBox, % vOutput
Gui, Show
return
I have the following script. I'm not sure how I can modify it to navigate the results using the up or down arrow keys. To run it, just create a .txt file and add some words in there (one word per line), then edit the filepath to where your .txt file is located. Then just search for a keyword that is found in at least 2 of the lines. e.g
Word1
Word2
If you search for word, it will return both word1 and word2. Then I just need to choose between them using up and down arrow key.
F9::
{
FilePath := "D:\5. Programs\AutoHotkey L x64\test.txt"
Gui, Destroy
Gui, Font, S20
Gui, Add, Text, X25 Y10 W450 H30 +Center , Search Box
Gui, Font, S10
Gui, Add, Edit, XP Y+20 W450 H20 vSearchString,
Gui, Color
Gui, Show, W500 H100, Search Box
return
#IfWinActive, Search Box
{
Enter::
Gui, Submit, NoHide
ResultList := []
ChosenString := ""
Loop, Read, %FilePath%
{
if (InStr(A_LoopReadLine, SearchString))
{
ResultList.Push(A_LoopReadLine)
}
}
if (!ResultList.Length())
{
;MsgBox % "No match found!"
return
}
Gui, DisplayResults:New,-MaximizeBox -MinimizeBox , Search results
Gui, Add, Text, w250, % "Click on one of the results below:"
for key, value in ResultList
{
if (key = 1)
Gui, Add, Radio, gSelectResult vChosenString, %value%
else
Gui, Add, Radio, gSelectResult, %value%
}
Gui, DisplayResults:Show
return
SelectResult:
Gui, DisplayResults:Submit
;Msgbox, % ResultList[ChosenString]
Clipboard := % ResultList[ChosenString]
return
}
}
return
You don't want the GUI to disappear?
Add NoHide in line number 44 like this:
Gui, DisplayResults:Submit, NoHide.
i want to make LShift in ComboBox become a <+,when i tap a batton. But IF function in LB11 is not working.
toggle1 := !toggle1
Gui, Add, Button, x0 w175 y469 Default, Save
Gui, Add, Button, x+1 w175 y469 Default, Exit
Gui, Add, Tab, x0 y0 w350 h468, System|Chrome|three
Gui, Tab, System
Gui, Add, Button, x10 y52 w23 h23 gEdit1 vEdit1, 1
Gui, Add, Text, x37 y39 vbtxt11, %LB11%+%LB12%+%LB13%
Gui, Add, ComboBox, +hidden x36 y32 w50 gLM11 vLB11 AltSubmit, LShift|RShift|LCtrl|RCtrl|LAlt|RAlt|LWin|Rwin
Gui, show, w351 h493
return
Edit1:
if toggle1
{
GuiControl, Show, LB11
GuiControl, Hide, btxt11
}
else
{
GuiControl, Hide, LB11
GuiControl, Show, btxt11
}
toggle1 := not toggle1
return
Gui, Tab
ButtonExit:
ExitApp
ButtonSave:
Gui, Submit, Nohide
GuiControl,,btxt11, %LB11%+%LB12%+%LB13%
IniWrite, %LB11%, E:\Reserve\AHK scrpts\exemples\4RS\partm.ini, key1, LB11
LM11:
if (LB11 = 1)
{
;<<< here is a problem
}
what i want:
i choose LShift in combobox.
LShift become <+.
<+ must be saved in .ini file.
when press the button i have a <+, not LShift.
what happening:
i choose LShift in combobox.
LShift saving in .ini file.
when press the button i have a LShift, not <+.
Full Script:
1) Script
2) .ini File
Short version:
1) Script
2) .ini File
I'm trying to find a solution to add predefined text to any application so instead of remembering a hotkey/hotstring combination I'll just need to click on the GUI button for the text.
This is what I have right now:
Gui, Add, Button, x22 y20 w120 h40 , Title
Gui, Add, Button, x22 y70 w120 h40 , Paragraph
; Generated using SmartGUI Creator 4.0
Gui, Show, x152 y89 h131 w222, New GUI Window
Return
ButtonTitle:
Send Title
return
ButtonParagraph:
Send Paragraph
return
GuiClose:
ExitApp
My problem is that I'm not able to make it work properly. I just want to click the button and that word gets shot to the notepad/word/any application.
The solution would be to always keep track of the current and the last active window. To achieve that you could use a shell hook to get notified when the active window changes: https://autohotkey.com/board/topic/66726-method-to-detect-active-window-change/
So you could have two variables currentWin and lastWin and when the active window changes you set lastWin := currentWin and currentWin := activeWin.
Soemthing like this maybe:
Gui, Add, Button, x22 y20 w120 h40 , Title
Gui, Add, Button, x22 y70 w120 h40 , Paragraph
; Generated using SmartGUI Creator 4.0
Gui, Show, x152 y89 h131 w222, New GUI Window
Gui +LastFound
hWnd := WinExist()
DllCall( "RegisterShellHookWindow", UInt,Hwnd )
MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" )
OnMessage( MsgNum, "ShellMessage" )
Return
ShellMessage(wParam, lParam) {
If (wParam=4) { ;HSHELL_WINDOWACTIVATED
lastWin := currentWin
currentWin := "ahk_id " . lParam
}
}
ButtonTitle:
WinActivate, % lastWin
Send Title
return
ButtonParagraph:
WinActivate, % lastWin
Send Paragraph
return
GuiClose:
ExitApp
(completely untested)
Hi Stephan and Forivin,
Thank you for your help. I used the alt+tab approach to solve the problem though I need to ensure that I get notepad on alt+tab keystroke or else it goes to another application. The below solves the problem.
Gui, Add, Button, x22 y20 w120 h40 , Title
Gui, Add, Button, x22 y70 w120 h40 , Paragraph
Gui, Show, x152 y89 h131 w222, New GUI Window
Return
ButtonTitle:
Send, !{Esc}
Send Title
return
ButtonParagraph:
Send, !{Esc}
Send Paragraph
return
GuiClose:
ExitApp
I am trying to create the code, that will show the foo window every time the Notepad is opened. The problem is, that if I close foo once, it will not be shown again (when I open Notepad next time). Currently I am using the following code:
SetTitleMatchMode, 2
WinWaitActive, Notepad
Gui, Add, Button, w200 h25 gTest1 , button 1
Gui, Add, Button, w200 h25 gTest2 , button 2
Gui, Show,, foo
Return
Test1:
Run test1.ahk
Return
Test2:
Run test2.ahk
Return
#Persistent
Gui, Add, Button, w200 h25 gTest1 , button 1
Gui, Add, Button, w200 h25 gTest2 , button 2
SetTimer, Show_Gui, 300
return
Show_Gui:
IfWinNotExist, ahk_class Notepad
{
Gui, cancel
return
}
; Otherwise:
SetTimer, Show_Gui, off
Gui, Show,, foo
WinWaitClose, ahk_class Notepad
SetTimer, Show_Gui, on
Return
Test1:
; do sth
return
Test2:
; do sth
return
https://autohotkey.com/docs/commands/SetTimer.htm#Examples