careca

[Solved] SetWindowsHookEx need to disable detection

3 posts in this topic

#1 ·  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 = ""

Example()
Func Example()
    OnAutoItExitRegister("Cleanup")
    $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
        Sleep(100)
        ConsoleWrite($g_sBuffer &' - '&@MSEC&@CRLF)
    WEnd
EndFunc   ;==>Example

Func EvaluateKey($iKeycode)
    If ($iKeycode = 32) Then ; space key
        Go()
    Else
        $g_sBuffer = ""
    EndIf
    ;ConsoleWrite('$g_sBuffer - '& $g_sBuffer &' - '&@MSEC&@CRLF)
EndFunc   ;==>EvaluateKey
;=============================================================================
Func Go()
        Send('abcdefgh123456789abcdefgh123456789')
        $g_sBuffer = ''
        Return
    Return
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)
    EndIf
    If $wParam = $WM_KEYDOWN Then
        EvaluateKey(DllStructGetData($tKEYHOOKS, "vkCode"))
        Else
        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)
        EndSwitch
    EndIf
    Return _WinAPI_CallNextHookEx($g_hHook, $nCode, $wParam, $lParam)
EndFunc   ;==>_KeyProc
;=============================================================================
Func Cleanup()
    _WinAPI_UnhookWindowsHookEx($g_hHook)
    DllCallbackFree($g_hStub_KeyProc)
EndFunc   ;==>Cleanup

 

Edited by careca

Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

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

BeatsPlayer - Music player.

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

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

Au3Record.exe

Share this post


Link to post
Share on other sites

#2 ·  Posted

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

 

Saludos

1 person likes this

Share this post


Link to post
Share on other sites

#3 ·  Posted

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.

1 person likes this

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