Jump to content

Sending a traped key


Recommended Posts

For one of my scripts I need to trap a key (to do some dll stuff) and than plug in some logic that basically states if this input came from device x send a different key stroke however if this input came from the keyboard resend the key that was pressed. In the case of the simplified script below I have the "a" key trapped so that if it is pressed it will register under GUIRegisterMsg() and not in that hotkeyset however once it goes thru the logic it will not send the "a" to the application if the input came from the keyboard.

Any suggestions?

Thanks in advance.

#include <RawInput.au3>
HotKeySet('{ESC}', '_EXIT')
HotKeySet("a", "FuncTrap")



Global $tRID_KD, $pRID_KD, $iRID_KD
Global $tRIH, $pRIH, $iRIH
Global $iNumDevices
Global $hGUI , $pData

$hGUI = GUICreate('Test', 100, 100)
GUIRegisterMsg($WM_INPUT, 'OnInput')

$tRID_KD = DllStructCreate($tagRAWINPUTDEVICE)
$pRID_KD = DllStructGetPtr($tRID_KD)
$iRID_KD = DllStructGetSize($tRID_KD)

$tRIH = DllStructCreate($tagRAWINPUTHEADER)
$pRIH = DllStructGetPtr($tRIH)
$iRIH = DllStructGetSize($tRIH)

$iNumDevices = 1

DllStructSetData($tRID_KD, 'usUsagePage', 0x01)
DllStructSetData($tRID_KD, 'usUsage', 0x06)
DllStructSetData($tRID_KD, 'dwFlags', BitOR($RIDEV_NOLEGACY, $RIDEV_INPUTSINK))
DllStructSetData($tRID_KD, 'hwndTarget', $hGUI)

_RegisterRawInputDevices($pRID_KD, $iNumDevices, $iRID_KD)

While 1
    Sleep(20)
WEnd

Func FuncTrap()

EndFunc

Func FuncSend()
    send("j")
EndFunc

Func FuncSend2()
    send("a")
EndFunc

Func OnInput($hwnd, $iMsg, $iwParam, $ilParam)
    Local $tRI_KD, $pRI_KD, $iRI_KB
    Local $tRIDI_HID, $pRIDI_HID, $iRIDI_HID
    Local $hDevice
   
    $tRI_KD = DllStructCreate($tagRAWINPUT_KEYBOARD)
    $pRI_KD = DllStructGetPtr($tRI_KD)
    $iRI_KB = DllStructGetSize($tRI_KD)
    
    $tRIDI_HID = DllStructCreate($tagRIDDEVICEINFO_HID)
    $pRIDI_HID = DllStructGetPtr($tRIDI_HID)
    $iRIDI_HID = DllStructGetSize($tRIDI_HID)
    DllStructSetData($tRIDI_HID, 'cbSize', $iRIDI_HID)



    _GetRawInputData($ilParam, $RID_INPUT, $pRI_KD, $iRI_KB, $iRIH)  
    If Not @error Then
        $hDevice = DllStructGetData($tRI_KD, 'hDevice')
        ConsoleWrite($hDevice & @LF)
        ConsoleWrite(DllStructGetData($tRI_KD, 'VKey') & @LF)
        ConsoleWrite(DllStructGetData($tRI_KD, 'hDevice') & @LF)
        
        _GetRawInputDeviceInfo($hDevice, $RIDI_DEVICEINFO, $pRIDI_HID, $iRIDI_HID)
If $hDevice = 0x0190016B Then
    FuncSend()
Else
    FuncSend2()

EndIf

    EndIf
   
    $tRI_KD = 0
    Return 'GUI_RUNDEFMSG'
EndFunc

Func _EXIT()
    GUIDelete()
    Exit
EndFunc
Edited by boogieoompa
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...