MyEarth Posted April 7, 2017 Share Posted April 7, 2017 Why i can't use AdlibRegister in this way? Global $bTest = False AdlibRegister("_Test", 10) While 1 Sleep(100) WEnd Func _Test() If $bTest = False Then AdlibRegister("_Test2", 10) EndIf EndFunc Func _Test2() $bTest = True ConsoleWrite(1 & @CRLF) AdlibUnRegister("_Test2") EndFunc On the help i don't have found nothing about "nested" adlib and the second adilib is writter to work just one time. I don't understand Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 7, 2017 Moderators Share Posted April 7, 2017 MyEarth, You are setting the Global variable in the wrong place - try this: HotKeySet("{ESC}", "_Exit") Global $bTest = False AdlibRegister("_Test", 1000) While 1 Sleep(10) WEnd Func _Test() ConsoleWrite("_Test firing" & @CRLF) If $bTest = False Then ConsoleWrite("_Test2 registering" & @CRLF) AdlibRegister("_Test2", 1000) $bTest = True EndIf EndFunc Func _Test2() ConsoleWrite("_Test2 firing and unregistering" & @CRLF) AdlibUnRegister("_Test2") $bTest = False EndFunc Func _Exit() Exit EndFunc I get: _Test firing _Test2 registering _Test firing _Test2 firing and unregistering _Test firing _Test2 registering _Test firing _Test2 firing and unregistering _Test firing _Test2 registering _Test firing _Test2 firing and unregistering _Test firing _Test2 registering _Test firing _Test2 firing and unregistering _Test firing _Test2 registering _Test firing _Test2 firing and unregistering as long as I leave it running. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
MyEarth Posted April 7, 2017 Author Share Posted April 7, 2017 Understood, thanks. @Melba23 a related question. With HotKeySet is possible to avoid or "skip" if the key is pressed and not released? Launch the funtion only one instead to do until the key is released? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 7, 2017 Moderators Share Posted April 7, 2017 MyEarth, Easy - within the HotKey function use _IsPressed to see if the key is still pressed and loop until it is not, but you might also need to unset the Hotkey as you enter the HotKey function and reset it as you leave to prevent the typematic key repeat continually firing the HotKey. Something like this: #include <Misc.au3> HotKeySet("{ESC}", "_Exit") HotKeySet("g", "_HKS_g") Global $hDLL = DllOpen("user32.dll") While 1 Sleep(10) WEnd ; Now the function Func _HKS_g() ; Unset the HotKey to prevent repeats HotKeySet("g") ; Now run the function code ConsoleWrite("HotKey fired" & @CRLF) ; If the key is still likely to be pressed then check if it is Do Sleep(10) Until _IsPressed("47", $hDLL) <> 1 ; Now reset the HotKey ready for the next press HotKeySet("g", "_HKS_g") EndFunc Func _Exit() DllClose($hDLL) Exit EndFunc M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
MyEarth Posted April 7, 2017 Author Share Posted April 7, 2017 (edited) @Melba23 that will stop the script, is possible to do the same without the Do-Until, maybe using an AdlibRegister in combination with @HotKeyPressed-GetKeyboardState? My HotKey is inside a INI so i don't know what it will choiced by the user so i can't use _IsPressed in that way plus as i have said it stop the script and i need it running. Edited April 7, 2017 by MyEarth Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 7, 2017 Moderators Share Posted April 7, 2017 MyEarth, You can determine the HotKey used via the @HotKeyPressed macro. Why is it so important that the script continues running even if the HotKey is still pressed? Here is a way to use an Adlib function to reset the HotKey but it seems rather too complicated in my opinion: expandcollapse popup#include <Misc.au3> HotKeySet("{ESC}", "_Exit") HotKeySet("g", "_HKS_g") Global $hDLL = DllOpen("user32.dll") Global $sHotKey = "" While 1 Sleep(10) WEnd ; Now the function Func _HKS_g() $sHotKey = @HotKeyPressed ; Unset the HotKey to prevent repeats HotKeySet($sHotKey) ; Now run the function code ConsoleWrite("HotKey fired" & @CRLF) ; Register an Adlib to check if it is still pressed ConsoleWrite("Registered" & @CRLF) AdlibRegister("_HotKeyCheck", 250) EndFunc Func _HotKeyCheck() ; Convert the HotKey used into the correct _IsPressed code $iASCII = Asc($sHotKey) If $iASCII > 9 Then $iASCII -= 32 EndIf $sHotKeyCode = StringTrimLeft(Hex($iASCII), 6) If Not _IsPressed($sHotKeyCode, $hDLL) Then ; Unregister the Adlib ConsoleWrite("Unregistered" & @CRLF) AdlibUnRegister("_HotKeyCheck") ; Now reset the HotKey ready for the next press HotKeySet($sHotKey, "_HKS_g") EndIf EndFunc Func _Exit() DllClose($hDLL) Exit EndFunc M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
MyEarth Posted April 7, 2017 Author Share Posted April 7, 2017 (edited) 11 minutes ago, Melba23 said: Why is it so important that the script continues running even if the HotKey is still pressed? Multiple timers, the script will loose the syncro if i'll stop with the Do-Until and unfortunately even "fire" more that one the function of the hotkey can create some difficulty, lol so many problems are totally unexpected for just a simple key press. Anyway, i have try with a combination like SHIFT+t ( aka +t ) and it will fired also if i don't leave the key EDIT: I don't remeber if _IsPressed work with combination, i never use it Edited April 7, 2017 by MyEarth Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 7, 2017 Moderators Share Posted April 7, 2017 MyEarth, Why did you not say earlier that you wanted a modifier in the HotKey combination? You just have to make a few changes to extract the base key from the combination : expandcollapse popup#include <Misc.au3> HotKeySet("{ESC}", "_Exit") HotKeySet("+t", "_HKS_Func") Global $hDLL = DllOpen("user32.dll") Global $sHotKey, $sHotKeyBase While 1 Sleep(10) WEnd ; Now the function Func _HKS_Func() $sHotKey = @HotKeyPressed ; Unset the HotKey to prevent repeats HotKeySet($sHotKey) ; Convert to base key only $sHotKeyBase = StringRegExpReplace($sHotKey, "\W", "") ; Now run the function code ConsoleWrite("HotKey fired" & @CRLF) ; Register an Adlib to check if the base key is still pressed ConsoleWrite("Registered" & @CRLF) AdlibRegister("_HotKeyCheck", 250) EndFunc Func _HotKeyCheck() $iASCII = Asc($sHotKeyBase) If $iASCII > 9 Then $iASCII -= 32 EndIf $sHotKeyCode = StringTrimLeft(Hex($iASCII), 6) If Not _IsPressed($sHotKeyCode, $hDLL) Then ; Unregister the Adlib ConsoleWrite("Unregistered" & @CRLF) AdlibUnRegister("_HotKeyCheck") ; Now reset the HotKey ready for the next press HotKeySet($sHotKey, "_HKS_Func") EndIf EndFunc Func _Exit() DllClose($hDLL) Exit EndFunc M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
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