Jump to content

DllCallbackRegister()


Recommended Posts

Hold down a few seconds any key and then click mouse on close button.

???

^_^

#Include <WinAPI.au3>

global $hProc = DllCallbackRegister('_MyHook', 'long', 'int;wparam;lparam')
global $hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hProc), _WinAPI_GetModuleHandle(0), 0)

GUICreate('Bug')
GUICtrlCreateLabel('Hold down a few seconds any key and then click mouse on close button.', 20, 20)
GUISetState()

do
until GUIGetMsg() = -3

func _MyHook($iCode, $wParam, $lParam)
    return _WinAPI_CallNextHookEx($hHook, $iCode, $wParam, $lParam)
endfunc; _MyHook

func OnAutoItExit()
    ConsoleWrite('Call _WinAPI_UnhookWindowsHookEx()')
    _WinAPI_UnhookWindowsHookEx($hHook)
endfunc; OnAutoItExit
Edited by Yashied
Link to comment
Share on other sites

try adding DllCallbackFree($hProc) to OnAutoItExit()

your script wouldn't hang for me , but I do have a mousehook example that momentarily hangs on gui close very time

Edit o.k. I got it to hang by holding down keys while clicking close button

more like 30 seconds of hung pc for me

problem is probably caused by installing system hook, not DllCallbackRegister

Edited by rover

I see fascists...

Link to comment
Share on other sites

Link to comment
Share on other sites

Edit o.k. I got it to hang by holding down keys while clicking close button

more like 30 seconds of hung pc for me

problem is probably caused by installing system hook, not DllCallbackRegister

I think this is due to the GUI.
Link to comment
Share on other sites

I solve the problem is not the best way.

^_^

#Include <WinAPI.au3>

global $hProc = DllCallbackRegister('_MyHook', 'long', 'int;wparam;lparam')
global $hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hProc), _WinAPI_GetModuleHandle(0), 0)

GUICreate('Bug')
GUIRegisterMsg(0x00A1, 'WM_NCLBUTTONDOWN')
GUICtrlCreateLabel('Hold down a few seconds any key and then click mouse on close button.', 20, 20)
GUISetState()

do
until GUIGetMsg() = -3

func _MyHook($iCode, $wParam, $lParam)
    return _WinAPI_CallNextHookEx($hHook, $iCode, $wParam, $lParam)
endfunc; _MyHook

func _HoldDown()
    
    local $Ret, $tState = DllStructCreate('byte[256]')
    
    $Ret = DllCall('user32.dll', 'int', 'GetKeyboardState', 'ptr', DllStructGetPtr($tState))
    if (@error) or ($Ret[0] = 0) then
        return SetError(1, 0, 0)
    endif
    
    for $i = 0x08 to 0xFF
        switch $i
            case 0x0A, 0x0B, 0x0E to 0x0F, 0x16, 0x1A, 0x1C to 0x1F, 0x3A to 0x40, 0x5E, 0x88 to 0x8F, 0x97 to 0x9F, 0xB8 to 0xB9, 0xC1 to 0xDA, 0xE0, 0xE8
                continueloop
            case else
                if BitAND(DllStructGetData($tState, 1, $i + 1), 0xF0) > 0 then
                    return 1
                endif
        endswitch
    next
    return 0
endfunc; _HoldDown

func WM_NCLBUTTONDOWN($hWnd, $msgID, $wParam, $lParam)

    switch $wParam
        case 0x08, 0x09, 0x14, 0x15
            if _HoldDown() then
                return 0
            endif
    endswitch
    return 'GUI_RUNDEFMSG'
endfunc; WM_NCLBUTTONDOWN

func OnAutoItExit()
    ConsoleWrite('Call _WinAPI_UnhookWindowsHookEx()')
    _WinAPI_UnhookWindowsHookEx($hHook)
endfunc; OnAutoItExit
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...