Jump to content
Sign in to follow this  
autoitxp

_WinAPI_SetWindowsHookEx key combinations

Recommended Posts

autoitxp

Im asking this question again coz i thought previous thread is not right to ask this question

how to get AT using this code really didnt found any solution n all forum realted shit + hotkeys

is possible to to do that or nt

even little help appreciated

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

Global $hHook, $hStub_KeyProc


    $hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam")
    $hmod = _WinAPI_GetModuleHandle(0)
    $hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hStub_KeyProc), $hmod)


While 1
    Sleep(250)
WEnd



Func _KeyProc($nCode, $wParam, $lParam)
    Local $tKEYHOOKS
    $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)
    If $nCode < 0 Then
        Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
    EndIf
    Local $vkCode = DllStructGetData($tKEYHOOKS, "vkCode")


    If $wParam = $WM_KEYDOWN Then

;If $vkCode = 0xA1 AND $vkCode = 0x32 Then ConsoleWrite('@')

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



Func OnAutoItExit()

    _WinAPI_UnhookWindowsHookEx($hHook)
    DllCallbackFree($hStub_KeyProc)
    MsgBox(0, "Exit", "Bye!")
EndFunc  ;==>_OnExit

Share this post


Link to post
Share on other sites
Authenticity

You do realize that if $vkCode is equal to 0xA1 it won't be equal to 0x32 and vice versa right? Either, use appropriate flags variables like if $WM_KEYDOWN is a shift virtual-key code then $fShift = True for example, if $WM_KEYUP with shift virtual-key code then $fShift = False, then process is 0x32 is 2 or @ properly. You can also use much simpler approach by using _IsPressed() function to see if the shift is pressed and whether the capslock is toggled.

Share this post


Link to post
Share on other sites
autoitxp

thanks for your help i looked up in search n found this nice code but i have question

$LLKHF_ALTDOWN

is equal to right Alt

can we use @ or _ instead of RALT if yes then how plz explain and if possible show little example

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


Global $hHook, $hStub_KeyProc


    $hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam")
    $hmod = _WinAPI_GetModuleHandle(0)
    $hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hStub_KeyProc), $hmod)


While 1
    Sleep(250)
WEnd



Func _KeyProc($nCode, $wParam, $lParam)
    Local $tKEYHOOKS
    $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)
    If $nCode < 0 Then
        Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
    EndIf


 Switch  $wParam
  Case $WM_KEYDOWN, $WM_SYSKEYDOWN
            Local $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)
            Local $vKode = DllStructGetData($tKEYHOOKS, "vkCode")
            Local $iFlags = DllStructGetData($tKEYHOOKS, "flags")

  Switch $vKode
    Case 0xA1

IF BitAND ($iFlags, $LLKHF_ALTDOWN) Then
    ConsoleWrite ( BitAND ($iFlags, $LLKHF_ALTDOWN) &@CRLF )
Else
Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
                   EndIf


            EndSwitch
    EndSwitch



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





Func OnAutoItExit()

    _WinAPI_UnhookWindowsHookEx($hHook)
    DllCallbackFree($hStub_KeyProc)
    MsgBox(0, "Exit", "Bye!")
EndFunc  ;==>_OnExit

Share this post


Link to post
Share on other sites
Authenticity

What is the purpose of determining if the alt is down also, or what is the purpose of the @ or _ characters in the hook procedure? If you can explain what you're trying to achieve it may help.

Share this post


Link to post
Share on other sites
autoitxp

I'm trying emulate the @ and other spicial chars using other other keys. like numeric keys

_IsPressed is not smart for my application

but first i wanted to know how to achive shift +2 = @ using above code i tried true false statements like u above explained but failed ; d

like here is my little try:

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

Global $hHook, $hStub_KeyProc


    $hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam")
    $hmod = _WinAPI_GetModuleHandle(0)
    $hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hStub_KeyProc), $hmod)


While 1
    Sleep(250)
WEnd



Func _KeyProc($nCode, $wParam, $lParam)
    Local $tKEYHOOKS
    $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)
    If $nCode < 0 Then
        Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
    EndIf




 Switch  $wParam
  Case $WM_KEYDOWN, $WM_SYSKEYDOWN, $WM_SYSKEYUP, $WM_KEYUP
            Local $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)
            Local $vKode = DllStructGetData($tKEYHOOKS, "vkCode")
            Local $iFlags = DllStructGetData($tKEYHOOKS, "flags")

  Switch $vKode
    Case 0xA1

if $wParam = 256 then


ConsoleWrite ("down" &@CRLF)
Else
if $wParam = 257 then


ConsoleWrite ("up"&@CRLF)
  EndIf
  EndIf


            EndSwitch
    EndSwitch


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



Func OnAutoItExit()

    _WinAPI_UnhookWindowsHookEx($hHook)
    DllCallbackFree($hStub_KeyProc)
    MsgBox(0, "Exit", "Bye!")
EndFunc  ;==>_OnExit
Edited by autoitxp

Share this post


Link to post
Share on other sites
Authenticity

#include <Misc.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Global Const $VK_CAPS = 0x14
Global $hHook, $hStub_KeyProc

$hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam")
$hmod = _WinAPI_GetModuleHandle(0)
$hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hStub_KeyProc), $hmod)


While 1
    Sleep(50)
WEnd


Func _KeyProc($nCode, $wParam, $lParam)
    Local $tKEYHOOKS
    Local $vKode, $iFlags, $fShift, $fCaps
    
    $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)
    If $nCode > -1 Then
        Switch $wParam
            Case $WM_KEYDOWN, $WM_SYSKEYDOWN
                $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)
                $vKode = DllStructGetData($tKEYHOOKS, "vkCode")
                $iFlags = DllStructGetData($tKEYHOOKS, "flags")
                $fShift = _IsPressed('10')
                $fCaps =_GetKeyState($VK_CAPS); In case you need it.

                If $vKode = 0x32 Then
                    If $fShift Then
                        ConsoleWrite('@' & @LF)
                    Else
                        ConsoleWrite('2' & @LF)
                    EndIf
                EndIf
        EndSwitch
        EndIf

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


Func OnAutoItExit()
    _WinAPI_UnhookWindowsHookEx($hHook)
    DllCallbackFree($hStub_KeyProc)
EndFunc   ;==>OnAutoItExit

Func _GetKeyState($ivkCode)
    Local $aRet
    
    $aRet = DllCall('user32.dll', 'short', 'GetKeyState', 'int', $ivkCode)
    Return BitAND($aRet[0], 1)
EndFunc

Share this post


Link to post
Share on other sites
autoitxp

Thanks alot man issue resolved help really appreciated ;

Thanks Alot

Regards

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
Sign in to follow this  

×