Jump to content

LLH Mouse AND Keyboard?


MyEarth
 Share

Recommended Posts

Hello guys, i have found many example of low level hook but they are separate, one for mouse and one for keyboard. Insead i'd like and hook for check a mouse-keyboard combination like control + click. Please don't suggest to use IsPressed or things like that.

Many thanks

Edited by MyEarth
Link to comment
Share on other sites

?

_WinAPI_SetWindowsHookEx()

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

could use _ispressed

#include <Misc.au3>
#include <MsgBoxConstants.au3>

Local $hDLL = DllOpen("user32.dll")

While 1
    If _IsPressed("11", $hDLL) And  _IsPressed("01", $hDLL) Then
        ConsoleWrite("!CTRL+LEFTCLICK Pressed" & @CRLF)

      EndIf
    Sleep(100)
WEnd

DllClose($hDLL)

Saludos

Link to comment
Share on other sites

@MikahS Really? Wow i didn't know that :D

I know how to open the help. I can choice between mouse OR keyboard with SetWindowsHookEx not both. Any operator on the parameter will not work, BitOr, BitAND... the help is clear "This parameter can be one of the following values"

@Danyfirex Thanks but i have already say "Please don't suggest to use IsPressed or things like that" because i'd like to know if is possible with low level hooking

Link to comment
Share on other sites

Hmm, didn't see you were being sarcastic at first. To bad I was trying to help, but I thought you were being nice, oh well. :(

You gave yourself the answer then MyEarth. "This parameter can be one of the following values" and "I can choice between mouse OR keyboard with SetWindowsHookEx not both".

:bye:

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

Maybe this:

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

Opt("MustDeclareVars", 1)

Global $g_hHook, $g_hHookm, $g_hStub_KeyProc, $hMouseProc
Global $bCtrl = False
Example()

Func Example()
    OnAutoItExitRegister("Cleanup")

    Local $hMod=0

    $g_hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam")
    $hMouseProc = DllCallbackRegister("_MouseProc", "int", "int;ptr;ptr")
    $hMod = _WinAPI_GetModuleHandle(0)
    $g_hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($g_hStub_KeyProc), $hMod)
    $g_hHookm = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hMouseProc), $hMod)


    While 1
        Sleep(10)
    WEnd
    
EndFunc   ;==>Example


Func _MouseProc($nCode, $wParam, $lParam)
    If $nCode < 0 Then
        Return _WinAPI_CallNextHookEx($g_hHookm, $nCode, $wParam, $lParam)
    EndIf

    Switch BitAND($wParam, 0xFFFF)
        Case 513
            If $bCtrl Then ConsoleWrite("CTRL+LEFTCLICK" & @CRLF)

    EndSwitch
    Return _WinAPI_CallNextHookEx($g_hHookm, $nCode, $wParam, $lParam)
EndFunc   ;==>_MouseProc


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
        If DllStructGetData($tKEYHOOKS, "vkCode") = 162 Then $bCtrl = True
    EndIf

    If $wParam = $WM_KEYUP Then
        If DllStructGetData($tKEYHOOKS, "vkCode") = 162 Then $bCtrl = False
    EndIf

    Return _WinAPI_CallNextHookEx($g_hHook, $nCode, $wParam, $lParam)
EndFunc   ;==>_KeyProc

Func Cleanup()
    _WinAPI_UnhookWindowsHookEx($g_hHook)
    _WinAPI_UnhookWindowsHookEx($g_hHookm)
    DllCallbackFree($g_hStub_KeyProc)
    DllCallbackFree($hMouseProc)
EndFunc   ;==>Cleanup

Saludos

Link to comment
Share on other sites

@MikahS ok you what to try to help but post the name of the function does mean nothing with my OP, hope can you understand. Thanks anyway

@Danyfirex Before post i have think to use the same solution but i don't have never see in any script more then once callback registered and i don't know if can cause any issue-crash at the script, waiting for some MVP can confirm.

Link to comment
Share on other sites

it should not.

#include <MsgBoxConstants.au3>


; Create callback function.
Local $hHandle[10]
For $i=0 to 9
    $hHandle[$i]=DllCallbackRegister("_EnumWindowsProc" & $i+1, "int", "hwnd;lparam")
Next

; Call EnumWindows.
while True
DllCall("user32.dll", "int", "EnumWindows", "ptr", DllCallbackGetPtr($hHandle[0]), "lparam", 10)
DllCall("user32.dll", "int", "EnumWindows", "ptr", DllCallbackGetPtr($hHandle[1]), "lparam", 10)
DllCall("user32.dll", "int", "EnumWindows", "ptr", DllCallbackGetPtr($hHandle[2]), "lparam", 10)
DllCall("user32.dll", "int", "EnumWindows", "ptr", DllCallbackGetPtr($hHandle[3]), "lparam", 10)
DllCall("user32.dll", "int", "EnumWindows", "ptr", DllCallbackGetPtr($hHandle[4]), "lparam", 10)
DllCall("user32.dll", "int", "EnumWindows", "ptr", DllCallbackGetPtr($hHandle[5]), "lparam", 10)
DllCall("user32.dll", "int", "EnumWindows", "ptr", DllCallbackGetPtr($hHandle[6]), "lparam", 10)
DllCall("user32.dll", "int", "EnumWindows", "ptr", DllCallbackGetPtr($hHandle[7]), "lparam", 10)
DllCall("user32.dll", "int", "EnumWindows", "ptr", DllCallbackGetPtr($hHandle[8]), "lparam", 10)
DllCall("user32.dll", "int", "EnumWindows", "ptr", DllCallbackGetPtr($hHandle[9]), "lparam", 10)
WEnd

; Delete callback function.
For $i=0 to 9
DllCallbackFree($hHandle[$i])
Next
; Callback Procedure
Func _EnumWindowsProc1($hWnd, $lParam)
    ; If the Title is empty or if the window is not visible then continue enumeration.
If WinGetTitle($hWnd) = "" Or BitAND(WinGetState($hWnd), 2) = 0 Then Return 1
 ConsoleWrite("HOLA1" & @CRLF)

Return 1 ; Return 1 to continue enumeration.
EndFunc   ;==>_EnumWindowsProc


; Callback Procedure
Func _EnumWindowsProc2($hWnd, $lParam)
    ; If the Title is empty or if the window is not visible then continue enumeration.
If WinGetTitle($hWnd) = "" Or BitAND(WinGetState($hWnd), 2) = 0 Then Return 1
 ConsoleWrite("HOLA2" & @CRLF)

Return 1 ; Return 1 to continue enumeration.
EndFunc   ;==>_EnumWindowsProc
; Callback Procedure
Func _EnumWindowsProc3($hWnd, $lParam)
    ; If the Title is empty or if the window is not visible then continue enumeration.
If WinGetTitle($hWnd) = "" Or BitAND(WinGetState($hWnd), 2) = 0 Then Return 1
 ConsoleWrite("HOLA3" & @CRLF)

Return 1 ; Return 1 to continue enumeration.
EndFunc   ;==>_EnumWindowsProc
; Callback Procedure
Func _EnumWindowsProc4($hWnd, $lParam)
    ; If the Title is empty or if the window is not visible then continue enumeration.
If WinGetTitle($hWnd) = "" Or BitAND(WinGetState($hWnd), 2) = 0 Then Return 1
 ConsoleWrite("HOLA4" & @CRLF)

Return 1 ; Return 1 to continue enumeration.
EndFunc   ;==>_EnumWindowsProc
; Callback Procedure
Func _EnumWindowsProc5($hWnd, $lParam)
    ; If the Title is empty or if the window is not visible then continue enumeration.
If WinGetTitle($hWnd) = "" Or BitAND(WinGetState($hWnd), 2) = 0 Then Return 1
 ConsoleWrite("HOLA5" & @CRLF)

Return 1 ; Return 1 to continue enumeration.
EndFunc   ;==>_EnumWindowsProc
; Callback Procedure
Func _EnumWindowsProc6($hWnd, $lParam)
    ; If the Title is empty or if the window is not visible then continue enumeration.
If WinGetTitle($hWnd) = "" Or BitAND(WinGetState($hWnd), 2) = 0 Then Return 1
 ConsoleWrite("HOLA6" & @CRLF)

Return 1 ; Return 1 to continue enumeration.
EndFunc   ;==>_EnumWindowsProc
; Callback Procedure
Func _EnumWindowsProc7($hWnd, $lParam)
    ; If the Title is empty or if the window is not visible then continue enumeration.
If WinGetTitle($hWnd) = "" Or BitAND(WinGetState($hWnd), 2) = 0 Then Return 1
 ConsoleWrite("HOLA7" & @CRLF)

Return 1 ; Return 1 to continue enumeration.
EndFunc   ;==>_EnumWindowsProc
; Callback Procedure
Func _EnumWindowsProc8($hWnd, $lParam)
    ; If the Title is empty or if the window is not visible then continue enumeration.
If WinGetTitle($hWnd) = "" Or BitAND(WinGetState($hWnd), 2) = 0 Then Return 1
 ConsoleWrite("HOLA8" & @CRLF)

Return 1 ; Return 1 to continue enumeration.
EndFunc   ;==>_EnumWindowsProc
; Callback Procedure
Func _EnumWindowsProc9($hWnd, $lParam)
    ; If the Title is empty or if the window is not visible then continue enumeration.
If WinGetTitle($hWnd) = "" Or BitAND(WinGetState($hWnd), 2) = 0 Then Return 1
 ConsoleWrite("HOLA9" & @CRLF)

Return 1 ; Return 1 to continue enumeration.
EndFunc   ;==>_EnumWindowsProc
; Callback Procedure
Func _EnumWindowsProc10($hWnd, $lParam)
    ; If the Title is empty or if the window is not visible then continue enumeration.
If WinGetTitle($hWnd) = "" Or BitAND(WinGetState($hWnd), 2) = 0 Then Return 1
 ConsoleWrite("HOLA10" & @CRLF)

Return 1 ; Return 1 to continue enumeration.
EndFunc   ;==>_EnumWindowsProc

Saludos

Edited by Danyfirex
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...