IF function in DropDownList\CoboBox - autohotkey

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

Related

Autohotkey - How to navigate a radio list using up and down arrow keys?

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.

Button automatically activating

I'm not quite sure why, but whenever I run the ahk file the button automatically activates. (I put the GuiClose: ExitApp so that it doesn't infinitely refresh). Also, is there a better way to do this?
#Persistent
#SingleInstance, force
ontop = 1
Gui, -Caption
Gui, Font,cPurple s10, Arial Bold
Gui, Add, Picture, x0 y0 gUImove, bg-1.jpg
Gui, Add, Picture, x0 y40, bg-1.jpg
If ontop = 1
{
Gui, +AlwaysOnTop
}
Gui, Add, Text, x190 y0 +BackgroundTrans,test
Gui, Add, Button, x100 y200 w120 h40 , disableOnTop
Gui, Show, w500 h340
TrayTip , Title, test, 20
UImove:
GuiClose:
ExitApp
disableOnTop:
{
If ontop = 0
{
ontop = 1
Reload
Sleep 5000
Return
}
Else If ontop = 1
{
ontop = 1
Reload
Sleep 5000
Return
}
}
Return
If you want the code following the disableOnTop label to run when clicking the GUI button, you need to put its name in the options of the button following a letter "g", like so:
Gui, Add, Button, x100 y200 w120 h40 gdisableOnTop , Click me
For proper functionality, you'll also need to put a Return after Gui, Show.
Note that variables are not saved when you reload. Also, note that the Sleep 5000 and Return are after Reload, which means it won't be executed. (Unless it can't reload, such as if there is a syntax error.)
I'm surprised that it's running your button code at all; it looks like it should run into ExitApp and all you'd see is a brief flash of the GUI before it exits.

Unknown issue, Numbers not inputting for a counter

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

Input text on any application with autohotkey gui

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

Show the GUI every time the Notepad window is opened

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