mr-es335 Posted 11 hours ago Posted 11 hours ago (edited) Good day, With the assistance of argumentum, he assisted me in developing a workable script that enables|disables a HotKey with an accompanying ToolTip. I now require that script to be divided into two separate scripts, a) one script to enable the HotKey, and b) one script to disable the HotKey. • Note: the enabling|disabling of each script will be invoked via Menu options. Here is the original script: expandcollapse popup#include <AutoItConstants.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> ; ----------------------------------------------- #AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ; ----------------------------------------------- Opt("MustDeclareVars", 1) ; ---------------------------------------------- Global $iW = 170, $iH = 45 Global $MainGui2 Global $sColRow, $sHotKey = "m" ; "{APPSKEY}" ..I don't have that key on my keyboard =( ; ----------------------------------------------- _MainGui1() ; ----------------------------------------------- Func _MainGui1() GUICreate("_MainGui1", $iW, $iH, 875, -1) GUISetFont(14, 800, 0, "Calibri") ; ----------------------------------------------- Local $sCol1Row1 = GUICtrlCreateButton("Add SoundFile", 10, 10, $iW - 20, 25) ; ----------------------------------------------- GUISetState(@SW_SHOW) ; ----------------------------------------------- While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _ExitMe() Case $sCol1Row1 GUICtrlSetState($sCol1Row1, $GUI_DISABLE) _MainGui2() GUICtrlSetState($sCol1Row1, $GUI_ENABLE) EndSwitch WEnd EndFunc ;==>_MainGui1 ; ----------------------------------------------- Func _MainGui2() _LaunchNP() ; Add for testing purposes only!!! $MainGui2 = GUICreate("", 130, 30, 895, 400, $WS_POPUP, $WS_EX_TOPMOST) GUISetFont(14, 800, 0, "Calibri") GUISetBkColor(0x3D3D3D) ; ----------------------------------------------- $sColRow = GUICtrlCreateLabel("Enable HotKey", 1, 3, 130, 25, $SS_CENTER) GUICtrlSetColor(-1, 0xFFFFFF) ; ----------------------------------------------- GUISetState(@SW_SHOW) ; ----------------------------------------------- While 1 Switch GUIGetMsg() Case $sColRow Local $hbHotKeyEnabled = _EnableHotKey() If $hbHotKeyEnabled = True Then ExitLoop EndSwitch WEnd EndFunc ;==>_MainGui2 ; ----------------------------------------------- Func _AccessMenuOption() WinActivate("[CLASS:Notepad]", "") WinMenuSelectItem("[CLASS:Notepad]", "", "&File", "Page Set&up...") EndFunc ;==>_AccessMenuOption ; ----------------------------------------------- Func _EnableHotKey() Local Static $hbHotKeyEnabled = True ; ----------------------------------------------- If $hbHotKeyEnabled = True Then HotKeySet($sHotKey, "_AccessMenuOption") GUICtrlSetData($sColRow, "Disable HotKey") GUICtrlSetTip($sColRow, "HotKey is now enabled!") $hbHotKeyEnabled = False ToolTip("Select [APPSKEY] to add SoundFile!", 852, 232, "HotKey Enabled", 1, $TIP_BALLOON) ;~ Sleep(1500) AdlibRegister(ToolTipOff, 1000) ; ToolTip("") Else HotKeySet($sHotKey) GUICtrlSetData($sColRow, "Enable HotKey") GUICtrlSetData($sColRow, "") GUICtrlSetTip($sColRow, "HotKey is now disabled!") GUIDelete($MainGui2) $hbHotKeyEnabled = True ToolTip("Select [Add SoundFile] to re-enable.", 852, 232, "HotKey Disabled", 1, $TIP_BALLOON) ;~ Sleep(1500) AdlibRegister(ToolTipOff, 1000) ; ToolTip("") EndIf Return $hbHotKeyEnabled EndFunc ;==>_EnableHotKey ; ----------------------------------------------- Func ToolTipOff() ; AutoiIt3 is single threaded so, this timer/Adlib, will free the AdlibUnRegister(ToolTipOff) ; thread so it do not have to wait X mSec just to do a: ToolTip("") ToolTip("") EndFunc ; ----------------------------------------------- Func _ExitMe() GUIDelete() Exit EndFunc ;==>_ExitMe ; ----------------------------------------------- Func _LaunchNP() Local $sSrcAppPath = @WindowsDir & "\System32\notepad.exe" ; ----------------------------------------------- ShellExecute($sSrcAppPath) ; ----------------------------------------------- WinWait("[CLASS:Notepad]", "", 10) ; wait 10 sec. max. ; Sleep(1) ; ----------------- WinMove("[CLASS:Notepad]", "", 835, 200, 250, 250) EndFunc ;==>_LaunchNP ; ----------------------------------------------- From that sampling, I have been able to derive the following - which enables the HotKey: expandcollapse popup; ----------------------------------------------- #include <AutoItConstants.au3> ; ----------------------------------------------- Opt("MustDeclareVars", 1) ; ----------------------------------------------- EnableHotKey() ; ----------------------------------------------- Func EnableHotKey() LaunchNP() ; Add for testing purposes only!!! HotKeySet("{APPSKEY}", "AccessMenuOption") ToolTip("Select [APPSKEY] to add SoundFile!", 84, 17, "HotKey Enabled", 1, $TIP_BALLOON) AdlibRegister(ToolTipOff, 1500) ; ----------------------------------------------- While 1 Sleep(100) WEnd EndFunc ;==>EnableHotKey ; ----------------------------------------------- Func AccessMenuOption() WinActivate("[CLASS:Notepad]", "") WinMenuSelectItem("[CLASS:Notepad]", "", "&File", "Page Set&up...") EndFunc ;==>AccessMenuOption ; ----------------------------------------------- Func ToolTipOff() AdlibUnRegister(ToolTipOff) ToolTip("") EndFunc ;==>ToolTipOff ; ----------------------------------------------- Func LaunchNP() Local $sSrcAppPath = @WindowsDir & "\System32\notepad.exe" ; ----------------------------------------------- ShellExecute($sSrcAppPath) ; ----------------------------------------------- WinWait("[CLASS:Notepad]", "", 10) ; wait 10 sec. max. ; Sleep(1) ; ----------------- WinMove("[CLASS:Notepad]", "", 835, 200, 250, 250) EndFunc ;==>LaunchNP ; ----------------------------------------------- I now require a script that disables the HotKey. Any attempts that I have tried have failed...and therefore,, assistance would be greatly appreciated. • Note: What I am looking for is the exact opposite of the "EnableHotKey" script. Following is what I have thus far: ; ----------------------------------------------- #include <AutoItConstants.au3> ; ----------------------------------------------- Opt("MustDeclareVars", 1) ; ----------------------------------------------- DisableHotKey() ; ----------------------------------------------- Func DisableHotKey() HotKeySet("{APPSKEY}") ToolTip("The HotKey is now disabled!", 84, 17, "HotKey Disabled!", 1, $TIP_BALLOON) AdlibRegister(ToolTipOff, 1500) ; ----------------------------------------------- While 1 Sleep(100) WEnd EndFunc ;==>DisableHotKey ; ----------------------------------------------- Func ToolTipOff() AdlibUnRegister(ToolTipOff) ToolTip("") EndFunc ;==>ToolTipOff ; ----------------------------------------------- Edited 10 hours ago by mr-es335 mr-es335 Sentinel Music Studios
argumentum Posted 9 hours ago Posted 9 hours ago you can send messages back and forth to each of your scripts and do the HotKey and anything else with: The example in the thread should be enough to show you how to implement it in your project. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
mr-es335 Posted 7 hours ago Author Posted 7 hours ago (edited) argumentum, Way...way, way above my pay-grade I am afraid!! I am attempting this: expandcollapse popup; ----------------------------------------------- #include <AutoItConstants.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> ; ----------------------------------------------- Global $MainGui2 Global $sColRow, $sHotKey = "{APPSKEY}" ; ----------------------------------------------- MainGui1() ; ----------------------------------------------- Func MainGui1() GUICreate("MainGui1", 170, 45, 2000, -1) GUISetFont(14, 800, 0, "Calibri") ; ----------------------------------------------- ConsoleWrite("1st" & @CRLF) ; <<< 1ST >>>> Local $sCol1Row1 = GUICtrlCreateButton("Add SoundFile", 10, 10, 150, 25) ; ----------------------------------------------- GUISetState(@SW_SHOW) ; ----------------------------------------------- While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitMe() Case $sCol1Row1 ConsoleWrite("2nd" & @CRLF) ; <<< 2ND >>>> GUICtrlSetState($sCol1Row1, $GUI_DISABLE) MainGui2() GUICtrlSetState($sCol1Row1, $GUI_ENABLE) EndSwitch WEnd EndFunc ;==>MainGui1 ; ----------------------------------------------- Func MainGui2() ConsoleWrite("3rd MainGui2" & @CRLF) ; <<< 3RD >>>> ;LaunchNP() ; ----------------------------------------------- $MainGui2 = GUICreate("", 130, 30, 895, 400, $WS_POPUP, $WS_EX_TOPMOST) ; ----------------------------------------------- ConsoleWrite("4th" & @CRLF) ; <<< 4TH >>>> $sColRow = GUICtrlCreateLabel("1 Enable HotKey", 1, 3, 130, 25, $SS_CENTER) ; ----------------------------------------------- GUISetState(@SW_SHOW) ; ----------------------------------------------- While 1 Switch GUIGetMsg() Case $sColRow Local $hbHotKeyEnabled = EnableHotKey() If $hbHotKeyEnabled = True Then ExitLoop EndSwitch WEnd EndFunc ;==>MainGui2 ; ----------------------------------------------- Func EnableHotKey() ConsoleWrite("5th EnableHotKey" & @CRLF) ; <<< 5TH >>>> Local Static $hbHotKeyEnabled = True ; ----------------------------------------------- If $hbHotKeyEnabled = True Then ConsoleWrite("6th $hbHotKeyEnabled = True" & @CRLF) ; <<< 6TH >>>> HotKeySet($sHotKey, "AccessMenuOption") ConsoleWrite("7th" & @CRLF) ; <<< 7TH >>>> GUICtrlSetData($sColRow, "1 Disable HotKey") $hbHotKeyEnabled = False ToolTip("Select [APPSKEY] to add SoundFile!", 852, 232, "HotKey Enabled", 1, $TIP_BALLOON) AdlibRegister(ToolTipOff, 1000) Else ConsoleWrite("3rd" & @CRLF) GUIDelete($MainGui2) $hbHotKeyEnabled = True ToolTip("Select [Add SoundFile] to re-enable.", 852, 232, "HotKey Disabled", 1, $TIP_BALLOON) AdlibRegister(ToolTipOff, 1000) EndIf Return $hbHotKeyEnabled EndFunc ;==>EnableHotKey ; ----------------------------------------------- ; ----------------------------------------------- ; ----------------------------------------------- Func LaunchNP() Local $sSrcAppPath = @WindowsDir & "\System32\notepad.exe" ; ----------------------------------------------- ShellExecute($sSrcAppPath) ; ----------------------------------------------- WinWait("[CLASS:Notepad]", "", 10) ; wait 10 sec. max. ; Sleep(1) ; ----------------- WinMove("[CLASS:Notepad]", "", 835, 200, 250, 250) EndFunc ;==>LaunchNP ; ----------------------------------------------- Func AccessMenuOption() WinActivate("[CLASS:Notepad]", "") WinMenuSelectItem("[CLASS:Notepad]", "", "&File", "Page Set&up...") EndFunc ;==>AccessMenuOption ; ----------------------------------------------- Func ToolTipOff() ; AutoiIt3 is single threaded so, this timer/Adlib, will free the AdlibUnRegister(ToolTipOff) ; thread so it do not have to wait X mSec just to do a: ToolTip("") ToolTip("") EndFunc ; ----------------------------------------------- Func ExitMe() GUIDelete() Exit EndFunc ;==>ExitMe ; ----------------------------------------------- Still at a loss...I am afraid! [...an old British vernacular!!] Edited 6 hours ago by mr-es335 mr-es335 Sentinel Music Studios
argumentum Posted 4 hours ago Posted 4 hours ago (edited) ..hmmm..., you'll have to think like a programmer. Then code accordingly. The trend of thought should be: I have 2 GUIs, named MainGui1() and MainGui2(). The ConsoleWrite is going to show the MainGui1() but not the MainGui2() so, 1st things first. Write yourself a ConsoleWrite that will output somewhere you can follow your code while coding/debugging. ( I would ask you to try Fork UDFish that has an example for it but given that this is too much, the other will be more confusing. And the aim is that you learn while you copy'n'paste ) I could give you something to send to SciTE but the aim is to learn IPC ( inter-process communication ) and use it to interact with other scripts running at the same time. So this script ( hidden ) is the "ConsoleThing" script that will receive your messages ( via MyConsoleWrite() function ) Spoiler expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include-once ; in case you use it as a UDF or as include to not include more than once #include <WMCDIPC.au3> ; the IPC UDF ; https://www.autoitscript.com/forum/index.php?showtopic=212541 #include <GuiEdit.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Exit ConsoleThing_GUI() Func ConsoleThing_GUI() #Region ### START Koda GUI section ### Form= Local $nMsg, $iW = 600, $iH = 400 Local $hForm = GUICreate(Chr(160) & "ConsoleThing" & Chr(160), $iW, $iH, @DesktopWidth - $iW - 20, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_TABSTOP)) Local $idBttn_Clear = GUICtrlCreateButton("Clear edit box", 3, 3, 95, 25) Local $idBttn_Reload = GUICtrlCreateButton("Reload script", 103, 3, 95, 25) ; so you can free SciTE to run other scripts GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT) Local $idEdit = GUICtrlCreateEdit("", 0, 30, $iW, $iH - 30) ; taking the lower right corner will show the resize control GUICtrlSetData(-1, "Nothing yet" & @CRLF) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM) GUICtrlSetFont(-1, 10, 400, 0, "Terminal") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### WMCDIPC_MSGFLT_AllAllowed() ; to get msg from every level, elevated or not. WMCDIPC_AdlibFunc("") ; must declare WMCDIPC_AdlibFunc("") to run in the loop WMCDIPC_Register() ; register the message handler While 1 $nMsg = GUIGetMsg() If WMCDIPC_MsgData()[0] Then ConsoleThing_Receiver($idEdit) Switch $nMsg Case $GUI_EVENT_CLOSE, $idBttn_Reload GUIDelete($hForm) If $nMsg = $idBttn_Reload Then ShellExecute(@AutoItExe, ((@AutoItExe = @ScriptFullPath) ? "" : ' "' & @ScriptFullPath & '" ')) EndIf Exit Case $idBttn_Clear GUICtrlSetData($idEdit, "Cleared the edit box" & @CRLF) EndSwitch WEnd EndFunc ;==>ConsoleThing Func ConsoleThing_Receiver($idEdit) Local $sTimestamp = @HOUR & ':' & @MIN & ':' & @SEC & '.' & @MSEC & ' >' Local $aDataArray = WMCDIPC_MsgData() ; will get the message data Local Enum $eWMCDIPC_Adlib, $eWMCDIPC_receiver, $eWMCDIPC_iMsg, $eWMCDIPC_sender, $eWMCDIPC_int, $eWMCDIPC_string, _ $eWMCDIPC_TimerDiff, $eWMCDIPC_TimerInit, $eWMCDIPC_MsgCounter, $eWMCDIPC_CaughtCounter, $eWMCDIPC_UBound _GUICtrlEdit_AppendText($idEdit, $sTimestamp & $aDataArray[$eWMCDIPC_string] & (StringRight($aDataArray[$eWMCDIPC_string], 2) = @CRLF ? "" : @CRLF)) WMCDIPC_MsgData(1) ; at the end to allow a next message EndFunc that will receive the debug/console write Then you'd use MyConsoleWrite() to send the debug info using this: Func MyConsoleWrite($sStr) Local $hHwdSender = WinGetHandle(AutoItWinGetTitle()) WMCDIPC_Send($hHwdSender, WinGetHandle(Chr(160) & "ConsoleThing" & Chr(160)), 1, AutoItWinGetTitle() & ' |' & $sStr) EndFunc ..so, your script would be ( hidden ) Spoiler expandcollapse popup; ----------------------------------------------- #include <WMCDIPC.au3> ; the IPC UDF ; https://www.autoitscript.com/forum/index.php?showtopic=212541 #include <AutoItConstants.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> ; ----------------------------------------------- Global $MainGui2 Global $sColRow, $sHotKey = "{APPSKEY}" ; ----------------------------------------------- MainGui1() ; ----------------------------------------------- Func MainGui1() AutoItWinSetTitle("MainGui1()") ; used by MyConsoleWrite to know who/what send the text GUICreate("MainGui1", 170, 45, 2000, -1) GUISetFont(14, 800, 0, "Calibri") ; ----------------------------------------------- MyConsoleWrite("1st" & @CRLF) ; <<< 1ST >>>> Local $sCol1Row1 = GUICtrlCreateButton("Add SoundFile", 10, 10, 150, 25) ; ----------------------------------------------- GUISetState(@SW_SHOW) ; ----------------------------------------------- While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitMe() Case $sCol1Row1 MyConsoleWrite("2nd" & @CRLF) ; <<< 2ND >>>> GUICtrlSetState($sCol1Row1, $GUI_DISABLE) MainGui2() GUICtrlSetState($sCol1Row1, $GUI_ENABLE) EndSwitch WEnd EndFunc ;==>MainGui1 ; ----------------------------------------------- Func MainGui2() AutoItWinSetTitle("MainGui2()") ; used by MyConsoleWrite to know who/what send the text MyConsoleWrite("3rd MainGui2" & @CRLF) ; <<< 3RD >>>> ;LaunchNP() ; ----------------------------------------------- $MainGui2 = GUICreate("", 130, 30, 895, 400, $WS_POPUP, $WS_EX_TOPMOST) ; ----------------------------------------------- MyConsoleWrite("4th" & @CRLF) ; <<< 4TH >>>> $sColRow = GUICtrlCreateLabel("1 Enable HotKey", 1, 3, 130, 25, $SS_CENTER) ; ----------------------------------------------- GUISetState(@SW_SHOW) ; ----------------------------------------------- While 1 Switch GUIGetMsg() Case $sColRow Local $hbHotKeyEnabled = EnableHotKey() If $hbHotKeyEnabled = True Then ExitLoop EndSwitch WEnd EndFunc ;==>MainGui2 ; ----------------------------------------------- Func EnableHotKey() MyConsoleWrite("5th EnableHotKey" & @CRLF) ; <<< 5TH >>>> Local Static $hbHotKeyEnabled = True ; ----------------------------------------------- If $hbHotKeyEnabled = True Then MyConsoleWrite("6th $hbHotKeyEnabled = True" & @CRLF) ; <<< 6TH >>>> HotKeySet($sHotKey, "AccessMenuOption") MyConsoleWrite("7th" & @CRLF) ; <<< 7TH >>>> GUICtrlSetData($sColRow, "1 Disable HotKey") $hbHotKeyEnabled = False ToolTip("Select [APPSKEY] to add SoundFile!", 852, 232, "HotKey Enabled", 1, $TIP_BALLOON) AdlibRegister(ToolTipOff, 1000) Else MyConsoleWrite("3rd" & @CRLF) GUIDelete($MainGui2) $hbHotKeyEnabled = True ToolTip("Select [Add SoundFile] to re-enable.", 852, 232, "HotKey Disabled", 1, $TIP_BALLOON) AdlibRegister(ToolTipOff, 1000) EndIf Return $hbHotKeyEnabled EndFunc ;==>EnableHotKey ; ----------------------------------------------- ; ----------------------------------------------- ; ----------------------------------------------- Func LaunchNP() Local $sSrcAppPath = @WindowsDir & "\System32\notepad.exe" ; ----------------------------------------------- ShellExecute($sSrcAppPath) ; ----------------------------------------------- WinWait("[CLASS:Notepad]", "", 10) ; wait 10 sec. max. ; Sleep(1) ; ----------------- WinMove("[CLASS:Notepad]", "", 835, 200, 250, 250) EndFunc ;==>LaunchNP ; ----------------------------------------------- Func AccessMenuOption() WinActivate("[CLASS:Notepad]", "") WinMenuSelectItem("[CLASS:Notepad]", "", "&File", "Page Set&up...") EndFunc ;==>AccessMenuOption ; ----------------------------------------------- Func ToolTipOff() ; AutoiIt3 is single threaded so, this timer/Adlib, will free the AdlibUnRegister(ToolTipOff) ; thread so it do not have to wait X mSec just to do a: ToolTip("") ToolTip("") EndFunc ; ----------------------------------------------- Func ExitMe() MyConsoleWrite("ExitMe()") GUIDelete() Exit EndFunc ;==>ExitMe ; ----------------------------------------------- Func MyConsoleWrite($sStr) Local $hHwdSender = WinGetHandle(AutoItWinGetTitle()) WMCDIPC_Send($hHwdSender, WinGetHandle(Chr(160) & "ConsoleThing" & Chr(160)), 1, AutoItWinGetTitle() & ' |' & $sStr) EndFunc that replaced every ConsoleWrite() with MyConsoleWrite(), giving you a tool to use and follow the code you're writing. With this running exercise, you can see that is not so complicated. MyConsoleWrite() is quite simple and the ConsoleThing script is also ( if not well understood yet ) quite simple too. If this example does not help you to get started, that's as far as I can take you. I hope you get the basics for what you need Edited 3 hours ago by argumentum Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
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