Jump to content

Nested AdlibRegister?


Recommended Posts

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 :blink:

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

@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 by MyEarth
Link to comment
Share on other sites

  • Moderators

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:

#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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 by MyEarth
Link to comment
Share on other sites

  • Moderators

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 :

#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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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