Meerecat Posted June 5, 2011 Posted June 5, 2011 Hello, noob here again. My script now displays a html page within a gui when you press a hotkey in notepad. What I need to achieve is when that GUI is closed, either with the X, a hotkey or a button, it doesn't close the script but goes back to the main function an waits for the hotkey to be pressed again. Something like this: Program Launches>Program Idle>Notepad started and hotkey pressed>GUI Displays>GUI Closed>Program Idle. I hope that makes sense, Many Thanks, here is my code: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <IE.au3> Opt ('TrayIconDebug',1) HotKeySet("^+q", "_Quit") ;Quit HotKeySet("^+{F1}", "_Main") Opt("WinTitleMatchMode", 2) ;Allow any text in window title While 1 ;Loop the program WEnd Func _Quit() ;Quit the program Exit EndFunc Func _Main() HotKeySet("^+{F1}") Local $sVal = "" If WinActive("[CLASS:Notepad]", "") Then _Hotkey_List() ElseIf WinActive("[CLASS:IEFrame]", "") Then $sVal = "IE" ElseIf WinActive("[CLASS:MozillaWindowClass]", "") Then $sVal = "FireFox" EndIf If $sVal <> "" Then msgbox (0, $sVal, "You are running " & $sVal) HotKeySet("^+{F1}", "_Main") EndFunc Func _Hotkey_List() HotKeySet("{ESC}", "_Main") _IEErrorHandlerRegister () $oIE = _IECreateEmbedded () GUICreate("Hotkeys", 640, 580, _ (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, _ $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN) $GUIActiveX = GUICtrlCreateObj($oIE, 10, 40, 600, 360) GUISetState() ;Show GUI $oIE.navigate(@ScriptDir & "\Notepad.html") ; Waiting for user to close the window While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE _Main() ; EndSelect WEnd GUIDelete() Exit EndFunc Lack of planning on your part does not constitute an emergency on my part.-The biggest idiot can ask questions the smartest man cannot answer.
NoNStoP Posted June 5, 2011 Posted June 5, 2011 you have to use ExitLoop and i used _IsPressed as hotkeys because i hate HotKeySet xD and dunno if it wont work cuz there's ExitLoop there's my code expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <IE.au3> #include <Misc.au3> Opt ('TrayIconDebug',1) HotKeySet("^+q", "_Quit") ;Quit Opt("WinTitleMatchMode", 2) ;Allow any text in window title While 1 ;Loop the program If _IsPressed("11") AND _IsPressed("70") AND _IsPressed("10") Then _Main() EndIf WEnd Func _Quit() ;Quit the program Exit EndFunc Func _Main() Local $sVal = "" If WinActive("[CLASS:Notepad]", "") Then _Hotkey_List() ElseIf WinActive("[CLASS:IEFrame]", "") Then $sVal = "IE" ElseIf WinActive("[CLASS:MozillaWindowClass]", "") Then $sVal = "FireFox" EndIf If $sVal <> "" Then msgbox (0, $sVal, "You are running " & $sVal) HotKeySet("^+{F1}", "_Main") EndFunc Func _Hotkey_List() _IEErrorHandlerRegister () $oIE = _IECreateEmbedded () GUICreate("Hotkeys", 640, 580, _ (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, _ $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN) $GUIActiveX = GUICtrlCreateObj($oIE, 10, 40, 600, 360) GUISetState() ;Show GUI $oIE.navigate(@ScriptDir & "\Notepad.html") ; Waiting for user to close the window While 1 If _IsPressed("1B") Then GUIDelete() ExitLoop EndIf $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE GUIDelete() ExitLoop ; EndSelect WEnd EndFunc I hope I helped!
UEZ Posted June 5, 2011 Posted June 5, 2011 Try this: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <IE.au3> #Include <Misc.au3> Opt ('TrayIconDebug',1) Opt("WinTitleMatchMode", 2) ;Allow any text in window title $dll = DllOpen("user32.dll") While Sleep(100) ;Loop the program If _IsPressed("7B", $dll) Then _Main() If _IsPressed("7A", $dll) Then DllClose($dll) Exit EndIf WEnd Func _Main() Local $sVal = "" If WinActive("[CLASS:Notepad]", "") Then _Hotkey_List() ElseIf WinActive("[CLASS:IEFrame]", "") Then $sVal = "IE" ElseIf WinActive("[CLASS:MozillaWindowClass]", "") Then $sVal = "FireFox" EndIf If $sVal <> "" Then msgbox (0, $sVal, "You are running " & $sVal) EndFunc Func _Hotkey_List() _IEErrorHandlerRegister () $oIE = _IECreateEmbedded () $hGUI = GUICreate("Hotkeys", 640, 580, _ (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, _ $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN) $GUIActiveX = GUICtrlCreateObj($oIE, 10, 40, 600, 360) GUISetState() ;Show GUI WinSetOnTop($hGUI, "", 1) $oIE.navigate(@ScriptDir & "\Notepad.html") WinSetOnTop($hGUI, "", 0) ; Waiting for user to close the window While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE GUIDelete($hGUI) Return 1 ; EndSelect WEnd EndFunc F12 activates windows F11 exits script Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Meerecat Posted June 5, 2011 Author Posted June 5, 2011 (edited) Try this: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <IE.au3> #Include <Misc.au3> Opt ('TrayIconDebug',1) Opt("WinTitleMatchMode", 2) ;Allow any text in window title $dll = DllOpen("user32.dll") While Sleep(100) ;Loop the program If _IsPressed("7B", $dll) Then _Main() If _IsPressed("7A", $dll) Then DllClose($dll) Exit EndIf WEnd Func _Main() Local $sVal = "" If WinActive("[CLASS:Notepad]", "") Then _Hotkey_List() ElseIf WinActive("[CLASS:IEFrame]", "") Then $sVal = "IE" ElseIf WinActive("[CLASS:MozillaWindowClass]", "") Then $sVal = "FireFox" EndIf If $sVal <> "" Then msgbox (0, $sVal, "You are running " & $sVal) EndFunc Func _Hotkey_List() _IEErrorHandlerRegister () $oIE = _IECreateEmbedded () $hGUI = GUICreate("Hotkeys", 640, 580, _ (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, _ $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN) $GUIActiveX = GUICtrlCreateObj($oIE, 10, 40, 600, 360) GUISetState() ;Show GUI WinSetOnTop($hGUI, "", 1) $oIE.navigate(@ScriptDir & "\Notepad.html") WinSetOnTop($hGUI, "", 0) ; Waiting for user to close the window While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE GUIDelete($hGUI) Return 1 ; EndSelect WEnd EndFunc F12 activates windows F11 exits script Br, UEZ Thank you both very much. This is why I gave up on C++, because there were so many different ways of doing things my little brain gets fried lol. Both your ways achieve what I want. Is there an advantage of using either of the above methods? I guess the second one is calling Windows dll's? Also what is the advantage of _IsPressed over HotKeySet? Thanks again Edited June 5, 2011 by Meerecat Lack of planning on your part does not constitute an emergency on my part.-The biggest idiot can ask questions the smartest man cannot answer.
Meerecat Posted June 5, 2011 Author Posted June 5, 2011 Thank you both very much. This is why I gave up on C++, because there were so many different ways of doing things my little brain gets fried lol. Both your ways achieve what I want. Is there an advantage of using either of the above methods? I guess the second one is calling Windows dll's? Also what is the advantage of _IsPressed over HotKeySet? Thanks again Also what do I add to this to say if the WinActive is none of these show a different message box? I have tried various else if statements and they all give an error. Local $sVal = "" If WinActive("[CLASS:Notepad]", "") Then _Hotkey_List() ElseIf WinActive("[CLASS:IEFrame]", "") Then $sVal = "IE" ElseIf WinActive("[CLASS:MozillaWindowClass]", "") Then $sVal = "FireFox" EndIf If $sVal <> "" Then msgbox (0, $sVal, "You are running " & $sVal) Many thanks for all your help. Lack of planning on your part does not constitute an emergency on my part.-The biggest idiot can ask questions the smartest man cannot answer.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now