mr-es335 Posted December 9 Posted December 9 (edited) Good day, I have the following script... expandcollapse popup; ----------------------------------------------- #include <File.au3> #include <GUIConstantsEx.au3> ; ----------------------------------------------- Opt("MustDeclareVars", 1) ; ----------------------------------------------- Global $hMainGUI = GUICreate(" Session|Show Development Main Menu", 220, 45) ; ----------------------------------------------- Global $_sCol2Row1 = GUICtrlCreateButton("Add SoundFile", 10, 10, 200, 25) ; ----------------------------------------------- GUISetState(@SW_SHOW, $hMainGUI) ; ----------------------------------------------- While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $_sCol2Row1 _EnableHotKey() EndSwitch WEnd ; ----------------------------------------------- Func _EnableHotKey() HotKeySet("{NUMPADMULT}", "_AccessMenuOption") HotKeySet("{NUMPADSUB}", "Terminate") ToolTip("Select NUMPAD *...to enable SoundFile section!" & @CRLF & "Select NUMPAD -...to exit the script!", 110, 45) ; ----------------------------------------------- While 1 Sleep(100) WEnd EndFunc ;==>_EnableHotKey ; ----------------------------------------------- Func _AccessMenuOption() Local $SAWTitle = "SAWStudio64" Local $AudioPath = " F:\Audio" ; ----------------- WinActivate("[CLASS:SAWSTUDIO_MAIN]", "") ; ----------------- Send("{alt down}") Send("{alt up}") MouseClick($MOUSE_CLICK_LEFT, 83, 15, 1, 0) Sleep(250) Send("{DOWN 12}") Send("{ENTER}") Send($AudioPath) Send("{ENTER}") EndFunc ;==>_AccessMenuOption ; ----------------------------------------------- Func Terminate() Exit EndFunc ;==>Terminate ; ----------------------------------------------- At present the entire script terminates via the "NumPad -" key. I am using a GUI button to access this function. Is there any way to have the function "work" without exiting the entire script...return to the main GUJI? "Help!" Edited December 9 by mr-es335 mr-es335 Sentinel Music Studios
spudw2k Posted December 9 Posted December 9 I'm not getting the whole picture. Without understanding more, remove Exit from the Terminate function and that won't close the script. If you do that, the "Terminate" function will still be called, but as-is there is nothing else being done in the function except exiting the script. Can you explain more? What do you want the NUMPAD - key press to do? Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF
mr-es335 Posted December 9 Author Posted December 9 (edited) spudw2k, Thanks for the follow-up...appreciated... If I do as you say...which I have tried, then there is no way to exit out of the _EnableHotKey routine. As noted, when I press the NumPad - [minus] key, the entire script exits and I not longer have access to the other menu options. • See attached... I want to return to the main GUI on exiting the _EnableHotKey routine. I do hope that this makes sense? Edited December 9 by mr-es335 mr-es335 Sentinel Music Studios
spudw2k Posted December 9 Posted December 9 Ah, I see now. There shouldn't be any need to have a while loop in the _EnableHotKey function. Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF
mr-es335 Posted December 9 Author Posted December 9 spudwek, So, I disabled the loop, but sill "no go". mr-es335 Sentinel Music Studios
ioa747 Posted December 9 Posted December 9 (edited) I added another button so you can see the difference, and that one don't need the other. expandcollapse popup; ----------------------------------------------- #include <File.au3> #include <GUIConstantsEx.au3> ; ----------------------------------------------- Opt("MustDeclareVars", 1) ; ----------------------------------------------- Global $hMainGUI = GUICreate(" Session|Show Development Main Menu", 220, 85) ; ----------------------------------------------- Global $_sCol2Row1 = GUICtrlCreateButton("Add SoundFile", 10, 10, 200, 25) Global $_sCol2Row123 = GUICtrlCreateButton("Enable HotKey", 10, 40, 200, 25) GUICtrlSetTip($_sCol2Row123, "Now is disabled, Press to enabled") ; ----------------------------------------------- GUISetState(@SW_SHOW, $hMainGUI) ; ----------------------------------------------- While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $_sCol2Row1 _AccessMenuOption() Case $_sCol2Row123 _EnableHotKey() EndSwitch WEnd ; ----------------------------------------------- Func _EnableHotKey() Local Static $hbHotKeyEnabled = True ConsoleWrite("$hbHotKeyEnabled=" & $hbHotKeyEnabled & @CRLF) If $hbHotKeyEnabled = True Then ; then enable hotkeys HotKeySet("{NUMPADMULT}", "_AccessMenuOption") HotKeySet("{NUMPADSUB}", "Terminate") GUICtrlSetData($_sCol2Row123, "Disable HotKey") GUICtrlSetTip($_sCol2Row123, "Now is enabled, Press to disabled") $hbHotKeyEnabled = False ToolTip("Select NUMPAD *...to enable SoundFile section!" & @CRLF & "Select NUMPAD -...to exit the script!", 110, 45, "HotKey Enabled", 1) Else ; then disable hotkeys HotKeySet("{NUMPADMULT}") HotKeySet("{NUMPADSUB}") GUICtrlSetData($_sCol2Row123, "Enable HotKey") GUICtrlSetTip($_sCol2Row123, "Now is disabled, Press to enabled") $hbHotKeyEnabled = True ToolTip(" ", 110, 45, "HotKey Disabled", 1) EndIf ; give some time to dispay ToolTip Sleep(3000) ToolTip("") EndFunc ;==>_EnableHotKey ; ----------------------------------------------- Func _AccessMenuOption() ConsoleWrite("Add SoundFile - ok" & @CRLF) Return ; <- *** just for testing <- Local $SAWTitle = "SAWStudio64" Local $AudioPath = " F:\Audio" ; ----------------- WinActivate("[CLASS:SAWSTUDIO_MAIN]", "") ; ----------------- Send("{alt down}") Send("{alt up}") MouseClick($MOUSE_CLICK_LEFT, 83, 15, 1, 0) Sleep(250) Send("{DOWN 12}") Send("{ENTER}") Send($AudioPath) Send("{ENTER}") EndFunc ;==>_AccessMenuOption ; ----------------------------------------------- Func Terminate() Exit EndFunc ;==>Terminate ; ----------------------------------------------- removed Global $hbHotKeyEnabled Edit: a short version without enable \ disable expandcollapse popup; ----------------------------------------------- #include <File.au3> #include <GUIConstantsEx.au3> ; ----------------------------------------------- Opt("MustDeclareVars", 1) ; ----------------------------------------------- Global $hMainGUI = GUICreate(" Session|Show Development Main Menu", 220, 45) ; ----------------------------------------------- Global $_sCol2Row1 = GUICtrlCreateButton("Add SoundFile", 10, 10, 200, 25) ; ----------------------------------------------- GUISetState(@SW_SHOW, $hMainGUI) HotKeySet("{NUMPADMULT}", "_AccessMenuOption") HotKeySet("{NUMPADSUB}", "Terminate") ToolTip("Select NUMPAD *...to enable SoundFile section!" & @CRLF & "Select NUMPAD -...to exit the script!", 110, 45) ; give some time to dispay ToolTip Sleep(3000) ToolTip("") ; ----------------------------------------------- While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $_sCol2Row1 _AccessMenuOption() EndSwitch WEnd ; ----------------------------------------------- Func _AccessMenuOption() Local $SAWTitle = "SAWStudio64" Local $AudioPath = " F:\Audio" ; ----------------- WinActivate("[CLASS:SAWSTUDIO_MAIN]", "") ; ----------------- Send("{alt down}") Send("{alt up}") MouseClick($MOUSE_CLICK_LEFT, 83, 15, 1, 0) Sleep(250) Send("{DOWN 12}") Send("{ENTER}") Send($AudioPath) Send("{ENTER}") EndFunc ;==>_AccessMenuOption ; ----------------------------------------------- Func Terminate() Exit EndFunc ;==>Terminate ; ----------------------------------------------- a short version enable \ disable expandcollapse popup; ----------------------------------------------- #include <File.au3> #include <GUIConstantsEx.au3> ; ----------------------------------------------- Opt("MustDeclareVars", 1) ; ----------------------------------------------- Global $hMainGUI = GUICreate(" Session|Show Development Main Menu", 220, 45) ; ----------------------------------------------- Global $_sCol2Row1 = GUICtrlCreateButton("Enable HotKey",10, 10, 200, 25) GUICtrlSetTip($_sCol2Row1, "Now is disabled, Press to enabled") ; ----------------------------------------------- GUISetState(@SW_SHOW, $hMainGUI) ; ----------------------------------------------- While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $_sCol2Row1 _EnableHotKey() EndSwitch WEnd ; ----------------------------------------------- Func _EnableHotKey() Local Static $hbHotKeyEnabled = True ConsoleWrite("$hbHotKeyEnabled=" & $hbHotKeyEnabled & @CRLF) If $hbHotKeyEnabled = True Then ; then enable hotkeys HotKeySet("{NUMPADMULT}", "_AccessMenuOption") HotKeySet("{NUMPADSUB}", "Terminate") GUICtrlSetData($_sCol2Row1, "Disable HotKey") GUICtrlSetTip($_sCol2Row1, "Now is enabled, Press to disabled") $hbHotKeyEnabled = False ToolTip("Select NUMPAD *...to enable SoundFile section!" & @CRLF & "Select NUMPAD -...to exit the script!", 110, 45, "HotKey Enabled", 1) Else ; then disable hotkeys HotKeySet("{NUMPADMULT}") HotKeySet("{NUMPADSUB}") GUICtrlSetData($_sCol2Row1, "Enable HotKey") GUICtrlSetTip($_sCol2Row1, "Now is disabled, Press to enabled") $hbHotKeyEnabled = True ToolTip(" ", 110, 45, "HotKey Disabled", 1) EndIf ; give some time to dispay ToolTip Sleep(3000) ToolTip("") EndFunc ;==>_EnableHotKey ; ----------------------------------------------- Func _AccessMenuOption() ConsoleWrite("Add SoundFile - ok" & @CRLF) Return ; <- *** just for testing <- Local $SAWTitle = "SAWStudio64" Local $AudioPath = " F:\Audio" ; ----------------- WinActivate("[CLASS:SAWSTUDIO_MAIN]", "") ; ----------------- Send("{alt down}") Send("{alt up}") MouseClick($MOUSE_CLICK_LEFT, 83, 15, 1, 0) Sleep(250) Send("{DOWN 12}") Send("{ENTER}") Send($AudioPath) Send("{ENTER}") EndFunc ;==>_AccessMenuOption ; ----------------------------------------------- Func Terminate() Exit EndFunc ;==>Terminate ; ----------------------------------------------- Edited December 9 by ioa747 correction mr-es335 1 I know that I know nothing
Solution ioa747 Posted December 9 Solution Posted December 9 Another thing I noticed is the _AccessMenuOption() function. From what I understand it calls a menu in the CLASS:SAWSTUDIO_MAIN window. The approach you have here is not the safest look for WinMenuSelectItem mr-es335 1 I know that I know nothing
mr-es335 Posted December 9 Author Posted December 9 (edited) ioa747, Here is my "take"... expandcollapse popup; https://www.autoitscript.com/forum/topic/212528-hotkeyset-issues/#comment-1539248 ; ----------------------------------------------- #include <File.au3> #include <GUIConstantsEx.au3> ; ----------------------------------------------- Opt("MustDeclareVars", 1) ; ----------------------------------------------- Global $hMainGUI = GUICreate(" Add SoundFile", 220, 45) GUISetFont(14, 800, 0, "Calibri") Global $hbHotKeyEnabled = False ; ----------------------------------------------- Global $_sCol2Row1 = GUICtrlCreateButton("Enable Hotkey", 10, 10, 200, 25) ; ----------------------------------------------- GUISetState(@SW_SHOW, $hMainGUI) ; ----------------------------------------------- While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $_sCol2Row1 _EnableHotKey() EndSwitch WEnd ; ----------------------------------------------- Func _EnableHotKey() If $hbHotKeyEnabled = True Then ; To disable hotkeys HotKeySet("{APPSKEY}") GUICtrlSetData($_sCol2Row1, "Enable HotKey") GUICtrlSetTip($_sCol2Row1, "HotKey is now disabled!") $hbHotKeyEnabled = False ToolTip("Select [Enable HotKey] to enable.", 84, 17, "HotKey Disabled", 1, $TIP_BALLOON) Else ; To enable hotkeys HotKeySet("{APPSKEY}", "_AccessMenuOption") GUICtrlSetData($_sCol2Row1, "Disable HotKey") GUICtrlSetTip($_sCol2Row1, "HotKey is now enabled!") $hbHotKeyEnabled = True ToolTip("Select [APPSKEY] to add SoundFile!", 84, 17, "HotKey Enabled", 1, $TIP_BALLOON) EndIf ; Provide time to dispay ToolTip Sleep(2000) ToolTip("") EndFunc ;==>_EnableHotKey ; ----------------------------------------------- Func _AccessMenuOption() ConsoleWrite("Add SoundFile - ok" & @CRLF) ;Return ; <- *** just for testing <- Local $SAWTitle = "SAWStudio64" Local $AudioPath = " F:\Audio" ; ----------------- WinActivate("[CLASS:SAWSTUDIO_MAIN]", "") ; ----- Send("{alt down}") Send("{alt up}") MouseClick($MOUSE_CLICK_LEFT, 83, 15, 1, 0) Sleep(250) Send("{DOWN 12}") Send("{ENTER}") Send($AudioPath) Send("{ENTER}") EndFunc ;==>_AccessMenuOption ; ----------------------------------------------- ...similar to your final "take"!!! As always, thanks for the efforts. All are very, very, very much appreciated! PS: Regarding "WinMenuSelectItem"...will look into this. Thanks for the "heads-up"! Edited December 9 by mr-es335 mr-es335 Sentinel Music Studios
ioa747 Posted December 9 Posted December 9 it's ok but change $hbHotKeyEnabled from Global $hbHotKeyEnabled = False to Local Static $hbHotKeyEnabled = False (I corrected the above.) mr-es335 1 I know that I know nothing
ioa747 Posted December 9 Posted December 9 I turned them to match. Func _EnableHotKey() Local Static $hbHotKeyEnabled = True ConsoleWrite("$hbHotKeyEnabled=" & $hbHotKeyEnabled & @CRLF) If $hbHotKeyEnabled = True Then ; To enable hotkeys HotKeySet("{APPSKEY}", "_AccessMenuOption") GUICtrlSetData($_sCol2Row1, "Disable HotKey") GUICtrlSetTip($_sCol2Row1, "HotKey is now enabled!") $hbHotKeyEnabled = False ToolTip("Select [APPSKEY] to add SoundFile!", 84, 17, "HotKey Enabled", 1, $TIP_BALLOON) Else ; To disable hotkeys HotKeySet("{APPSKEY}") GUICtrlSetData($_sCol2Row1, "Enable HotKey") GUICtrlSetTip($_sCol2Row1, "HotKey is now disabled!") $hbHotKeyEnabled = True ToolTip("Select [Enable HotKey] to enable.", 84, 17, "HotKey Disabled", 1, $TIP_BALLOON) EndIf ; Provide time to dispay ToolTip Sleep(2000) ToolTip("") EndFunc ;==>_EnableHotKey ; ----------------------------------------------- mr-es335 1 I know that I know nothing
mr-es335 Posted December 9 Author Posted December 9 ioa747, "WOW! WOW! WOW!" The employment of "WinMenuSelectItem" is most definitely more efficient and effective!! Here is final offering... expandcollapse popup; https://www.autoitscript.com/forum/topic/212528-hotkeyset-issues/#comment-1539248 ; https://www.autoitscript.com/forum/topic/212528-hotkeyset-issues/?do=findComment&comment=1539255 ; ----------------------------------------------- #include <File.au3> #include <GUIConstantsEx.au3> ; ----------------------------------------------- Opt("MustDeclareVars", 1) ; ----------------------------------------------- Global $hMainGUI = GUICreate(" Add SoundFile", 220, 45) GUISetFont(14, 800, 0, "Calibri") Local Static $hbHotKeyEnabled = False ; ----------------------------------------------- Global $_sCol2Row1 = GUICtrlCreateButton("Enable Hotkey", 10, 10, 200, 25) ; ----------------------------------------------- GUISetState(@SW_SHOW, $hMainGUI) ; ----------------------------------------------- While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $_sCol2Row1 _EnableHotKey() EndSwitch WEnd ; ----------------------------------------------- Func _EnableHotKey() Local Static $hbHotKeyEnabled = True ConsoleWrite("$hbHotKeyEnabled=" & $hbHotKeyEnabled & @CRLF) If $hbHotKeyEnabled = True Then ; To enable hotkeys HotKeySet("{APPSKEY}", "_AccessMenuOption") GUICtrlSetData($_sCol2Row1, "Disable HotKey") GUICtrlSetTip($_sCol2Row1, "HotKey is now enabled!") $hbHotKeyEnabled = False ToolTip("Select [APPSKEY] to add SoundFile!", 84, 17, "HotKey Enabled", 1, $TIP_BALLOON) Else ; To disable hotkeys HotKeySet("{APPSKEY}") GUICtrlSetData($_sCol2Row1, "Enable HotKey") GUICtrlSetTip($_sCol2Row1, "HotKey is now disabled!") $hbHotKeyEnabled = True ToolTip("Select [Enable HotKey] to enable.", 84, 17, "HotKey Disabled", 1, $TIP_BALLOON) EndIf ; Provide time to dispay ToolTip Sleep(2000) ToolTip("") EndFunc ;==>_EnableHotKey ; ----------------------------------------------- Func _AccessMenuOption() ConsoleWrite("Add SoundFile - ok" & @CRLF) ;Return ; <- *** just for testing <- Local $SAWTitle = "SAWStudio64" Local $AudioPath = " F:\Audio" ; ----------------- WinActivate("[CLASS:SAWSTUDIO_MAIN]", "") WinMenuSelectItem("[CLASS:SAWSTUDIO_MAIN]", "", "&File", "Add SoundFile To MT") EndFunc ;==>_AccessMenuOption ; ----------------------------------------------- Thanks again! "io!...io!...to him I do io..." ioa747 1 mr-es335 Sentinel Music Studios
ioa747 Posted December 9 Posted December 9 (edited) I understand that this is a first approach, with a dose of enthusiasm. but something is probably missing here. Func _AccessMenuOption() ConsoleWrite("Add SoundFile - ok" & @CRLF) ;Return ; <- *** just for testing <- Local $SAWTitle = "SAWStudio64" Local $AudioPath = " F:\Audio" ; ----------------- WinActivate("[CLASS:SAWSTUDIO_MAIN]", "") WinMenuSelectItem("[CLASS:SAWSTUDIO_MAIN]", "", "&File", "Add SoundFile To MT") EndFunc ;==>_AccessMenuOption ; ----------------------------------------------- otherwise Local $SAWTitle = "SAWStudio64" Local $AudioPath = " F:\Audio" are not needed In the previous approach, you sent the $AudioPath somewhere. Take a look here. as help tool Edited December 9 by ioa747 I know that I know nothing
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