boogieoompa Posted August 7, 2009 Share Posted August 7, 2009 (edited) 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. expandcollapse popup#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 August 7, 2009 by boogieoompa Link to comment Share on other sites More sharing options...
Authenticity Posted August 7, 2009 Share Posted August 7, 2009 You need to reset the hot-key in the FuncSend2() function, something like: Func FunSend2() HotKeySet("a") Send("a") HotKeySet("a", "FuncTrap") EndFunc ..and be ready to ignore the next WM_INPUT that will be posted as a result of sending another keystroke, if it'll be posted, of-course. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now