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.
Related
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
Is there a way to keep a Shoes GUI Always On Top of other windows.
In AHK I use a checkbox:
Gui, Add, CheckBox, x730 y520 gUpdate vCheck, Always on Top
guicontrol, , check, 1
Update:
Gui, Submit, NoHide
If Check = 1
{
Gui, +AlwaysOnTop
}
else
{
Gui, -AlwaysOnTop
}
Return
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
I'm using a AutoHotkey GUI + ListBox to select an option from various choices, but I cannot find a way to make the RETURN key to close the GUI without creating an additional default button with an associated ButtonOk event. Here's my code using a default button:
Gui, +LastFound +AlwaysOnTop -Caption
Gui, Add, ListBox, vMyListBox gMyListBox w300 r10
Gui, Add, Button, Default, OK
GuiControl,, MyListBox, Option 1
GuiControl,, MyListBox, Option 2
GuiControl,, MyListBox, Option 3
Gui, Show
return
MyListBox:
if A_GuiEvent <> DoubleClick
return
ButtonOK:
GuiControlGet, MyListBox
Gui Hide
MsgBox %MyListBox% selected!
ExitApp
GuiClose:
GuiEscape:
ExitApp
You can use the Hotkey command to temporarily enable Return as a hotkey when the GUI is visible and disable it when the gui is closed.
You can monitor for the WM_KEYDOWN message. In the auto-execute section:
OnMessage(0x100, "OnKeyDown")
Then elsewhere in the script:
OnKeyDown(wParam)
{
if (A_Gui = 1 && wParam = 13) ; VK_ENTER := 13
{
GuiControlGet, MyListBox
Gui Hide
MsgBox %MyListBox% selected!
ExitApp
}
}