Jump to content

[Solved] SetWindowsHookEx need to disable detection

Recommended Posts

Posted (edited)

Hi, taken from the help file is this example, changed it a bit so that uppon pressing the space key, the script should send some text, but the problem is that it seems like the space key i press to trigger the send, pushes a space into the middle of the send. Aka a string like 'abcdefgh123456789abcdefgh123456789' can become: 'abcdefgh123456789abcdefgh12345 6789'

So i think i need to disable the key detection or something, before the send, allowing me to press any keys, without them being sent in the middle of the send.

Before you suggest a hotkeyset or something else, no, it has to be this way, this is to be part of something bigger that needs to work with this method.

Like the "hotstrings" example in the forum.



#include <MsgBoxConstants.au3>
#include <StructureConstants.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
Global $g_hHook, $g_hStub_KeyProc, $g_sBuffer = ""

Func Example()
    $g_hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam")
    Local $hMod = _WinAPI_GetModuleHandle(0)
    $g_hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($g_hStub_KeyProc), $hMod)
    While 1
        ConsoleWrite($g_sBuffer &' - '&@MSEC&@CRLF)
EndFunc   ;==>Example

Func EvaluateKey($iKeycode)
    If ($iKeycode = 32) Then ; space key
        $g_sBuffer = ""
    ;ConsoleWrite('$g_sBuffer - '& $g_sBuffer &' - '&@MSEC&@CRLF)
EndFunc   ;==>EvaluateKey
Func Go()
        $g_sBuffer = ''
EndFunc   ;==>UseAndGo
Func _KeyProc($nCode, $wParam, $lParam)
    Local $tKEYHOOKS
    $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)
    If $nCode < 0 Then
        Return _WinAPI_CallNextHookEx($g_hHook, $nCode, $wParam, $lParam)
    If $wParam = $WM_KEYDOWN Then
        EvaluateKey(DllStructGetData($tKEYHOOKS, "vkCode"))
        Local $iFlags = DllStructGetData($tKEYHOOKS, "flags")
        Switch $iFlags
            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)
    Return _WinAPI_CallNextHookEx($g_hHook, $nCode, $wParam, $lParam)
EndFunc   ;==>_KeyProc
Func Cleanup()
EndFunc   ;==>Cleanup


Edited by careca


Paster - Main function is to paste text, but has more functions. (No longer mantained, switched to String Trigger)

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples


Share this post

Link to post
Share on other sites

If you space key is pressed  return 1 in _KeyProc instead _WinAPI_CallNextHookEx. that will block the space key.



  • Like 1

Share this post

Link to post
Share on other sites

If the hook procedure processed the message, it may return a nonzero value to prevent the system from passing the message to the rest of the hook chain or the target window procedure.

  • Like 1

When the words fail... music speaks

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