Jump to content

Recommended Posts

Posted

Good day,

To begin with, I DO understand that you are unable to pass parameters employing "HotKeySet".

I have looked at, and considered, a number of potential "resolves" - which are, sad-to-say...way above my pay grade!

Anyhow, I do have the following example:

Spoiler
; -----------------------------------------------
#include <AutoItConstants.au3>
#include <FileConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
; -----------------------------------------------
Opt("MustDeclareVars", 1)
Opt("MouseCoordMode", 0)
; -----------------------------------------------
Global $iExtTimeOut = 2000
; ---------------------
Global $LblHotKey
Global $mActivateHotKey
; -----------------------------------------------
GetInput()
; -----------------------------------------------
Func GetInput()
    Local $sPrompt = "Notice!"
    Local $sPromptMessage = "Enter the [name]:" & @CRLF & _
            "[1] name1" & @CRLF & _
            "[2] name2" & @CRLF
    ; -----------------
    Local $sResult = InputBox($sPrompt, $sPromptMessage, "", " ", 200, 150)
    ; -----------------------------------------------
    If @error Then
        Exit
    EndIf
    ; -----------------------------------------------
    If $sResult = "1" Then
        MainT1()
    EndIf
    If $sResult = 2 Then
        MainT2()
    EndIf
EndFunc   ;==>GetInput
; -----------------------------------------------
; For Main Type_1
; -----------------------------------------------
Func MainT1()
    ConsoleWrite("MainT1" & @CRLF)
    Local $hMainGUI = GUICreate(" Menu Title", 125, 19, 1500, 19)
    WinSetOnTop(" Menu", "", $WINDOWS_ONTOP)
    ; -----------------------------------------------
    Local $mMain = GUICtrlCreateMenu("HotKey")
    Local $mActivateHotKey = GUICtrlCreateMenuItem("Activate", $mMain)
    ; -----------------------------------------------
    GUISetState(@SW_SHOW)
    ; -----------------------------------------------
    While 1
        Local $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
                ; -----------------
            Case $mActivateHotKey
                CreateLabelT1()
        EndSwitch
    WEnd
EndFunc   ;==>MainT1
; -----------------------------------------------
Func CreateLabelT1()
    $mActivateHotKey = GUICreate("", 150, 20, 115, 52, $WS_POPUP, $WS_EX_TOPMOST)
    GUISetFont(14, 800, 0, "Calibri")
    GUISetBkColor(0x3D3D3D)
    ; -----------------------------------------------
    $LblHotKey = GUICtrlCreateLabel("Activate HotKey  ", 0, 0, 150, 20, $SS_CENTER)
    GUICtrlSetColor(-1, 0xFFFFFF)
    ; -----------------------------------------------
    GUISetState(@SW_SHOW)
    ; -----------------------------------------------
    While 1
        Switch GUIGetMsg()
            Case $LblHotKey
                Local $hbActivateHotKey = ActivateHotKeyT1()
                If $hbActivateHotKey = True Then ExitLoop
        EndSwitch
    WEnd
EndFunc   ;==>CreateLabelT1
; -----------------------------------------------
Func ActivateHotKeyT1()
    Local Static $hbActivateHotKey = True
    ; -----------------------------------------------
    If $hbActivateHotKey = True Then
        HotKeySet("{`}", CallT1)
        GUICtrlSetData($LblHotKey, "Deactivate HotKey")
        $hbActivateHotKey = False
        ToolTip("Employ the Grave Key [`]...", 192, 68, "The HotKey feature is now activated!", 0, $TIP_BALLOON)
        AdlibRegister(ToolTipOffT1, $iExtTimeOut)
    Else
        HotKeySet("{`}")
        GUICtrlSetData($LblHotKey, "Activate HotKey")
        GUIDelete($mActivateHotKey)
        $hbActivateHotKey = True
        ToolTip("Exiting HotKey feature...", 192, 68, "The HotKey feature is now deactivated!", 0, $TIP_BALLOON)
        AdlibRegister(ToolTipOffT1, $iExtTimeOut)
    EndIf
    Return $hbActivateHotKey
EndFunc   ;==>ActivateHotKeyT1
; -----------------------------------------------
Func ToolTipOffT1()
    AdlibUnRegister(ToolTipOffT2)
    ToolTip("")
EndFunc   ;==>ToolTipOffT1
; -----------------------------------------------
Func CallT1()
    ConsoleWrite("CallT1" & @CRLF)
EndFunc   ;==>CallT1
; -----------------------------------------------
; For Main Type_2
; -----------------------------------------------
Func MainT2()
    ConsoleWrite("MainT2" & @CRLF)
    Local $hMainGUI = GUICreate(" Menu Title", 125, 19, 1500, 19)
    WinSetOnTop(" Menu", "", $WINDOWS_ONTOP)
    ; -----------------------------------------------
    Local $mMain = GUICtrlCreateMenu("HotKey")
    Local $mActivateHotKey = GUICtrlCreateMenuItem("Activate", $mMain)
    ; -----------------------------------------------
    GUISetState(@SW_SHOW)
    ; -----------------------------------------------
    While 1
        Local $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
                ; -----------------
            Case $mActivateHotKey
                CreateLabelT2()
        EndSwitch
    WEnd
EndFunc   ;==>MainT2
; -----------------------------------------------
Func CreateLabelT2()
    $mActivateHotKey = GUICreate("", 150, 20, 115, 52, $WS_POPUP, $WS_EX_TOPMOST)
    GUISetFont(14, 800, 0, "Calibri")
    GUISetBkColor(0x3D3D3D)
    ; -----------------------------------------------
    $LblHotKey = GUICtrlCreateLabel("Activate HotKey  ", 0, 0, 150, 20, $SS_CENTER)
    GUICtrlSetColor(-1, 0xFFFFFF)
    ; -----------------------------------------------
    GUISetState(@SW_SHOW)
    ; -----------------------------------------------
    While 1
        Switch GUIGetMsg()
            Case $LblHotKey
                Local $hbActivateHotKey = ActivateHotKeyT2()
                If $hbActivateHotKey = True Then ExitLoop
        EndSwitch
    WEnd
EndFunc   ;==>CreateLabelT2
; -----------------------------------------------
Func ActivateHotKeyT2()
    Local Static $hbActivateHotKey = True
    ; -----------------------------------------------
    If $hbActivateHotKey = True Then
        HotKeySet("{`}", CallT2)
        GUICtrlSetData($LblHotKey, "Deactivate HotKey")
        $hbActivateHotKey = False
        ToolTip("Employ the Grave Key [`]...", 192, 68, "The HotKey feature is now activated!", 0, $TIP_BALLOON)
        AdlibRegister(ToolTipOffT2, $iExtTimeOut)
    Else
        HotKeySet("{`}")
        GUICtrlSetData($LblHotKey, "Activate HotKey")
        GUIDelete($mActivateHotKey)
        $hbActivateHotKey = True
        ToolTip("Exiting HotKey feature...", 192, 68, "The HotKey feature is now deactivated!", 0, $TIP_BALLOON)
        AdlibRegister(ToolTipOffT2, $iExtTimeOut)
    EndIf
    Return $hbActivateHotKey
EndFunc   ;==>ActivateHotKeyT2
; -----------------------------------------------
Func ToolTipOffT2()
    AdlibUnRegister(ToolTipOffT2)
    ToolTip("")
EndFunc   ;==>ToolTipOffT2
; -----------------------------------------------
Func CallT2()
    ConsoleWrite("CallT2" & @CRLF)
EndFunc   ;==>CallT2
; -----------------------------------------------

 

Based on the above example, I have the following 2 questions:

Q1: Can the above be "streamlined"?
Q2: How can I return tot he calling function [GetInput()]...without having to exit the functions first?

As always...any assistance in this matter would be greatly appreciated!

 

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
×
×
  • Create New...