Jump to content

Keyboatd hook quriosity


Recommended Posts

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?

Link to comment
Share on other sites

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
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...