Jump to content

SetWindowsHookEx combination


Terenz
 Share

Recommended Posts

I'm stuck :D

I don't have understand how to intercept combination with a keyboard hook. Example, if i want to catch alt + a i can use:

; stripped
Local $vkCode = DllStructGetData($tKEYHOOKS, "vkCode")
Local $iFlags = DllStructGetData($tKEYHOOKS, "flags")
Switch $wParam
    Case $WM_KEYDOWN, $WM_SYSKEYDOWN
        Switch $vkCode
            Case 0x41 ; A key
                If BitAND($iFlags, $LLKHF_ALTDOWN) Then ConsoleWrite("alt+a" & @CR)
        EndSwitch
EndSwitch
Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
;etc

But what about ctrl, shift? I mean without using _IsPressed

Thanks

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Link to comment
Share on other sites

That link ( i already know it or where i have take 0x41? ) don't answer in any way my question. If $LLKHF_ALTDOWN is used for check the ALT key combination, what i can use for shift or ctrl?

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Link to comment
Share on other sites

  • Moderators

There's probably a language barrier interferring with me understanding what you're asking.

You say you know about that site.

The answer to your question (as much of it as I understand anyway) is right there:


VK_SHIFT = 0x10

VK_CTRL = 0x11

 

So I'd imagine you'd use:

<snip> see code below

Next time provide "working" code, something that we can just plug into scite and run so we can test for you.  I've no idea if that's going to work.

Edit:

Ahh, I get it, I took the code out of the help file so I could alter it.

You're going to need to trap the down/up key codes.

I didn't do the global array work, but pointed out in this code (in the _keyproc callback func) where to look:

<snipped>

Edit2:

Working example of how I'd do it (use Esc key to exit) (have both left and right now):

#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")

    Local $hMod

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

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

Func _isctrlshiftdown($iKey, $fDown)

    Local Static $aDown[] = [0, 0]

    Switch $iKey
        Case 160, 161
            $aDown[0] = ($fDown) ? 1 : 0
        Case 162, 163
            $aDown[1] = ($fDown) ? 1 : 0
    EndSwitch

    Return (($aDown[0] + $aDown[1]) > 1)
EndFunc

; ===========================================================
; callback function
; ===========================================================
Func _KeyProc($nCode, $wParam, $lParam)
    Local $tKEYHOOKS
    Local $fCTRLSHFTDOWN = 0
    $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)
    If $nCode < 0 Then
        Return _WinAPI_CallNextHookEx($g_hHook, $nCode, $wParam, $lParam)
    EndIf
    If $wParam = $WM_KEYDOWN Then
        Switch $tKEYHOOKS.vkCode
            Case 160 To 163
                $fCTRLSHFTDOWN = _isctrlshiftdown($tKEYHOOKS.vkCode, True)
            Case 27
                Exit
        EndSwitch
    Else
        Local $iFlags = DllStructGetData($tKEYHOOKS, "flags")
        Switch $iFlags
            Case $LLKHF_UP
                Switch $tKEYHOOKS.vkCode
                    Case 160 To 163
                        $fCTRLSHFTDOWN = _isctrlshiftdown($tKEYHOOKS.vkCode, False)
                EndSwitch
        EndSwitch
    EndIf
    If $fCTRLSHFTDOWN Then ConsoleWrite("Ctrl & Shift are down" & @CRLF)
    Return _WinAPI_CallNextHookEx($g_hHook, $nCode, $wParam, $lParam)
EndFunc   ;==>_KeyProc 

.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Yes probably my english isn't perfect but i'll try to do the best for make you understand. You are near :D

In the first post i have posted a stripped example ( next time i'll post the entire script, i don't have do it because was in the help ) of intercept alt+a using hook and $LLKHF_ALTDOWN. Imagine now i want to intercept also:

cltr+a

cltr+alt+a

shift+a

shift+alt+a

ctrl+shift+a

etc.

But having a separate ConsoleWrite ( and a separate Case event ) for every output, pressing cltr+a give me ConsoleWrite("cltr+a"), shift+a give me ConsoleWrite("shift+a") and so on, avoiding the use of HotKeySet and _IsPressed like your example and using only the hooking function.

Thanks for the help

Edited by Terenz

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Link to comment
Share on other sites

  • Moderators

There's a fairly simple solution to this, if you base your code "similar" to what I've provided.

The issue for what specific you're asking for is that there are right and left shift/ctrl buttons.  So there are 4 possible combinations of keys you'd have to check for.

CTRL-R + SHIFT-R

CTRL-R + SHIFT-L

CTRL-L + SHIFT-R

CTRL-R + SHIFT-L

I did not find any special "ALT" type key down option for ctrl and shift, there were only 5 options all together I believe.  I'm unsure if you can bitshift and test the extended data or not.

If I provide you the means to do exactly what you want, then I've shown you and anyone else how to create a simple "effective" keylogger, so I must back out of this, I wish you well.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Yes is a keylogger for automating a game with additional a joke script :sweating:

I don't care for left and right key, both are equal for me ( LSHIFT+a = RSHIFT+a ) so i can use the same case. Is only one key ( the "a" ) with combination of ctrl, alt and shift ( with HotKeySet or _IsPressed every n00b with 1 post can do it but i prefer the cleanest script method ) so isn't a keylogger in any way. If i want a keylogger in autoit i can search it on google but i don't want it and i don't need it.

If my words may don't have convinced you, i'll requital wish you well and thank you for the help you gave me ;)

Edited by Terenz

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Link to comment
Share on other sites

  • Moderators

Thanks Terenz, I'm going to lock this thread all the same.  I hope you have what you need to do the right thing(s) with it.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...