Sign in to follow this  
Followers 0
Skrip

_WinAPI_SetWindowsHookEx Further Explaination?

3 posts in this topic

Hey guys. I'm a bit confused on how to use the various hooks in _WinAPI_SetWindowsHookEx(). The example was a bit helpful, but I do not understand how to use $lpfn and $hmod.

For the $WH_GETMESSAGE hook, how exactly can I use that?

#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()

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..." & _

@LF & @LF & "Jon" & @LF & "AutoIt" & @LF & @LF & "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

;===========================================================

; callback function

;===========================================================

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" & @LF)

Case $LLKHF_EXTENDED

ConsoleWrite("$LLKHF_EXTENDED" & @LF)

Case $LLKHF_INJECTED

ConsoleWrite("$LLKHF_INJECTED" & @LF)

Case $LLKHF_UP

ConsoleWrite("$LLKHF_UP: scanCode - " & DllStructGetData($tKEYHOOKS, "scanCode") & @TAB & "vkCode - " & DllStructGetData($tKEYHOOKS, "vkCode") & @LF)

EndSwitch

EndIf

Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)

EndFunc ;==>_KeyProc

Func OnAutoItExit()

_WinAPI_UnhookWindowsHookEx($hHook)

DllCallbackFree($hStub_KeyProc)

EndFunc ;==>OnAutoItExit


[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Share this post


Link to post
Share on other sites



Now that I look at it, it seems pretty useless. Heh.

But still, how do you use these other hooks that are available?


[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

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