Jump to content

_WinAPI_SetWindowsHookEx key combinations


Recommended Posts

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

#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

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...