Sign in to follow this  
Followers 0
iCode

HotKey UDF (Yashied) - problem may not be the UDF

2 posts in this topic

having a bloody difficult time trying to work with Yashied's HotKey UDF when using it in this particular way and beginning to suspect the problem may not be the UDF. it could be something i'm doing wrong in working with the UDF (likely), or may with AutoIt (?). either way, i decided to post here as i wasn't getting any feedback in Yashied's topics

there are several problems with my example, including the failing of _HotKey_Assign(), _HotKey_Enable(), _HotKey_Disable and _HotKey_Release(), all of which fail on the second run of the GUI

example: run script > press ESC > press F1 - everything's cool - now ESC and F1 again - various HotKey functions fail, but F1 still shows the GUI - with GUI showing, assign a new hotkey - this fails and F1 still works

in my script i need to keep the structure in my example, where _HotKey_Assign() is in a separate func and hotkeys are disabled when running the GUI, then enabled again on hiding deleting the GUI

#include "F:\AutoIt\_Funcs\_Other\HotKey\_Hotkey.au3"
#include "F:\AutoIt\_Funcs\_Other\HotKey\_HotkeyInput.au3"
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("GUICloseOnESC", 0)

Global $err
Global $Hk = 112 ; F1

_AssignHk()

_ShowGUI()

While 1

    Sleep(1000)

WEnd

Func _ShowGUI()

    ConsoleWrite(@LF & "::: FUNC _ShowGUI() - ENTERING :::" & @LF)

    Local $inHk = $Hk

    $err = _HotKey_Disable() ; FAILS ON 2nd RUN OF GUI, BUT HOTKEY STILL WORKS
    ConsoleWrite("_HotKey_Disable=" & $err & @LF)

    Local $Form = GUICreate("", 251, 201, -1, -1)
    GUICtrlCreateLabel("Press ESC, then F1 - Repeat", 8, 12, 200, 21)
    Local $Input_Hk = _GUICtrlHKI_Create("", 12, 40, 121, 21)
    Local $Button = GUICtrlCreateButton("Save", 8, 80, 75, 25)
    Local $Form_AccelTable[1][2] = [["{ESC}", $Button]]
    GUISetAccelerators($Form_AccelTable)

    _GUICtrlHKI_SetHotKey($Input_Hk, $Hk)

    GUISetState(@SW_SHOW)

    While 1

        Switch GUIGetMsg()

            Case $GUI_EVENT_CLOSE

                Exit

            Case $Button

                ExitLoop

        EndSwitch

    WEnd

    ConsoleWrite(@LF & "::: FUNC _ShowGUI() - EXITING :::" & @LF)

    $Hk = _GUICtrlHKI_GetHotKey($Input_Hk)
    ConsoleWrite("$inHk=" & $inHk & @LF)
    ConsoleWrite("$Hk=" & $Hk & @LF)

    If $inHk <> $Hk Then
        $err = _HotKey_Release() ; FAILING
        ConsoleWrite("_HotKey_Release=" & $err & @LF)
        ;$err = _HotKey_Assign($Hk)
        ;ConsoleWrite("_HotKey_Assign=" & $err & @LF)
        _AssignHk()
    EndIf

    $err = _GUICtrlHKI_Release()
    ConsoleWrite("_GUICtrlHKI_Release=" & $err & @LF)

    GUIDelete($Form)

    $err = _HotKey_Enable() ; FAILS ON 2nd EXIT OF GUI, BUT HOTKEY STILL WORKS
    ConsoleWrite("_HotKey_Enable=" & $err & @LF)

EndFunc

Func _AssignHk()

    ConsoleWrite(@LF & "::: FUNC _AssignHk() :::" & @LF)

    $err = _HotKey_Assign($Hk, "_Hk_ShowGUI", $HK_FLAG_DEFAULT) ; FAILS TO ASSIGN NEW HOTKEY ON 2nd RUN OF GUI AND THEREAFTER

    ConsoleWrite("_HotKey_Assign ($err)=" & $err & @LF)
    ConsoleWrite("_HotKey_Assign (@error)=" & @error & @LF)

    If @error Then
        MsgBox(48, "", "Unable to set hot-key!")
        Exit
    EndIf

EndFunc

Func _Hk_ShowGUI() ; not supposed to introduce significant delays in func called from _HotKey_Assign(), so we call _ShowGUI() from this func

    _ShowGUI()

EndFunc

FUNCTIONS: WinDock (dock window to screen edge) | EditCtrl_ToggleLineWrap (line/word wrap for AU3 edit control) | SendEX (yet another alternative to Send( ) ) | Spell Checker (Hunspell wrapper) | SentenceCase (capitalize first letter of sentences)

CODE SNIPPITS: Dynamic tab width (set tab control width according to window width)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

still don't know what is causing problems, but i posted the latest example code, which clearly shows _HotKey_Assign() failing,

Edited by iCode

FUNCTIONS: WinDock (dock window to screen edge) | EditCtrl_ToggleLineWrap (line/word wrap for AU3 edit control) | SendEX (yet another alternative to Send( ) ) | Spell Checker (Hunspell wrapper) | SentenceCase (capitalize first letter of sentences)

CODE SNIPPITS: Dynamic tab width (set tab control width according to window width)

Share this post


Link to post
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
Sign in to follow this  
Followers 0