Sign in to follow this  
Followers 0
dexto

Keyboatd hook quriosity

4 posts in this topic

In Code for Keyboard Hook:

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

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


Func EvaluateKey($keycode)
    ConsoleWrite($keycode)
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 = 256 Then;256=keydown, 257=keyup
        EvaluateKey(DllStructGetData($tKEYHOOKS, "vkCode"))
    EndIf
    Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndFunc  ;==>_KeyProc

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

What is the function of:

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

If it returns False of 0 will that disable the keyboard?

Share this post


Link to post
Share on other sites



If you'll return anything non-zero then it'll prevent the system from passing it to the rest of the chain. If another application is registering it's own procedure latter, then the system is going to call it first.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

In Code for Keyboard Hook:

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

Global $hHook
<...redacted...>

What is the function of:

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

If it returns False of 0 will that disable the keyboard?

It's required by the Windows API specs, but I don't see (and wouldn't expect) details on the consequences for mis-handling it: MSDN: LowLevelKeyboardProc Function

Parameters

nCode

[in] Specifies a code the hook procedure uses to determine how to process the message. If nCode is less than zero, the hook procedure must pass the message to the CallNextHookEx function without further processing and should return the value returned by CallNextHookEx.

:)

P.S. Your code doesn't run because there is no loop to keep it alive while waiting for events.

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Thanks guys.

P.S. i use this as include (loop is in the main script)

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