Function Reference

_WinAPI_UnhookWindowsHookEx

_WinAPI_SetWindowsHookEx関数によってフックチェーンに設置されたフックプロシージャを取り除きます。

#Include <WinAPI.au3>
_WinAPI_UnhookWindowsHookEx($hhk)

 

パラメータ

$hhk 取り除かれるフックのハンドル

 

返し値

成功: True
失敗: False

 

注意

なし。

 

関連

_WinAPI_SetWindowsHookEx, DllCallbackFree

 

こちらも参照

MSDNライブラリでUnhookWindowsHookExを検索して下さい。

 


#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <StructureConstants.au3>

Opt('MustDeclareVars', 1)

Global $hHook, $hStub_KeyProc, $buffer = ""

_Main()

Func _Main()
    OnAutoItExitRegister("Cleanup")

    Local $hmod

    $hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam")
    $hmod = _WinAPI_GetModuleHandle(0)
    $hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hStub_KeyProc), $hmod)

    MsgBox(4096, "", "Click OK, then in notepad type..." & _
            @CRLF & @CRLF & "Jon" & @CRLF & "AutoIt" & @CRLF & @CRLF & "Press Esc to exit script")

    Run("Notepad")
    WinWait("Untitled -")
    WinActivate("Untitled -")

    While 1
        Sleep(10)
    WEnd
EndFunc   ;==>_Main

Func EvaluateKey($keycode)
    If (($keycode > 64) And ($keycode < 91)) _ ; a - z
            Or (($keycode > 96) And ($keycode < 123)) _ ; A - Z
            Or (($keycode > 47) And ($keycode < 58)) Then ; 0 - 9
        $buffer &= Chr($keycode)
        Switch $buffer
            Case "Jon"
                ToolTip("What can you say?")
            Case "AutoIt"
                ToolTip("AutoIt Rocks")
        EndSwitch
    ElseIf ($keycode > 159) And ($keycode < 164) Then
        Return
    ElseIf ($keycode = 27) Then ; esc key
        Exit
    Else
        $buffer = ""
    EndIf
EndFunc   ;==>EvaluateKey

;===========================================================
; コールバック関数
;===========================================================
Func _KeyProc($nCode, $wParam, $lParam)
    Local $tKEYHOOKS
    $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)
    If $nCode < 0 Then
        Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
    EndIf
    If $wParam = $WM_KEYDOWN Then
        EvaluateKey(DllStructGetData($tKEYHOOKS, "vkCode"))
    Else
        Local $flags = DllStructGetData($tKEYHOOKS, "flags")
        Switch $flags
            Case $LLKHF_ALTDOWN
                ConsoleWrite("$LLKHF_ALTDOWN" & @CRLF)
            Case $LLKHF_EXTENDED
                ConsoleWrite("$LLKHF_EXTENDED" & @CRLF)
            Case $LLKHF_INJECTED
                ConsoleWrite("$LLKHF_INJECTED" & @CRLF)
            Case $LLKHF_UP
                ConsoleWrite("$LLKHF_UP: scanCode - " & DllStructGetData($tKEYHOOKS, "scanCode") & @TAB & "vkCode - " & DllStructGetData($tKEYHOOKS, "vkCode") & @CRLF)
        EndSwitch
    EndIf
    Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndFunc   ;==>_KeyProc

Func Cleanup()
    _WinAPI_UnhookWindowsHookEx($hHook)
    DllCallbackFree($hStub_KeyProc)
EndFunc   ;==>Cleanup