Jump to content

Recommended Posts

Posted (edited)

Good day,

I have the following script...

; -----------------------------------------------
#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 by mr-es335
Posted

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?  

 

Posted (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?

Main_GUI.png

Edited by mr-es335
Posted (edited)

I added another button so you can see the difference, and that one don't need  the other.

; -----------------------------------------------
#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

; -----------------------------------------------
#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

; -----------------------------------------------
#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 by ioa747
correction

I know that I know nothing

  • Solution
Posted

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

I know that I know nothing

Posted (edited)

ioa747,

Here is my "take"...

; 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 by mr-es335
Posted


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
; -----------------------------------------------

 

I know that I know nothing

Posted

ioa747,

"WOW! WOW! WOW!"

The employment of "WinMenuSelectItem" is most definitely more efficient and effective!! Here is final offering...

; 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..."

Posted (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 by ioa747

I know that I know nothing

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...