nicolasd Posted June 27, 2023 Share Posted June 27, 2023 Hello All, I'm not new on Autoit, used to script a lot on it Now i'm stuck with a crazy idea : Be able to catch which button is pressed (and also released) on an Elgato Stream Deck so i can make various actions directly from Autoit. It works as a HID device. I already make search over your forum and google and found some old topics (2008) talking about how to read input from HID devices. Unfortunately, the only thing I was able to do is knowing that i press and release a button but no clue at all which one is it. Based on various example scripts / topics / internet gossips, I was able to write this : expandcollapse popup#include <GUIConstantsEx.au3> #include <WinAPISys.au3> #include <WindowsConstants.au3> Opt('TrayAutoPause', 0) Global $g_hForm = GUICreate('Test ' & StringReplace(@ScriptName, '.au3', '()'), 160, 212, @DesktopWidth - 179, @DesktopHeight - 283, BitOR($WS_CAPTION, $WS_POPUP, $WS_SYSMENU), $WS_EX_TOPMOST) Global $tRID = DllStructCreate($tagRAWINPUTDEVICE) DllStructSetData($tRID, 'Flags', $RIDEV_INPUTSINK) DllStructSetData($tRID, 'VendorId', 0x0FD9) DllStructSetData($tRID, 'ProductId', 0x0090) DllStructSetData($tRID, 'UsagePage', 0x0C) DllStructSetData($tRID, 'Usage', 0x01) DllStructSetData($tRID, 'hTarget', $g_hForm) ; Register HID input to obtain row input from mice _WinAPI_RegisterRawInputDevices($tRID) ; Register WM_INPUT message GUIRegisterMsg($WM_INPUT, 'WM_INPUT') Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Func WM_INPUT($hWnd, $iMsg, $wParam, $lParam) #forceref $iMsg, $wParam ConsoleWrite(@YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & " [" & @AutoItPID & "] >> START" & @CRLF) ;~ ConsoleWrite(@YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & " [" & @AutoItPID & "] >> $iMsg=" & $iMsg & @CRLF) ConsoleWrite(@YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & " [" & @AutoItPID & "] >> $wParam=" & $wParam & @CRLF) ConsoleWrite(@YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & " [" & @AutoItPID & "] >> $lParam=" & $lParam & @CRLF) ;~ ;ConsoleWrite(@YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & " [" & @AutoItPID & "] >> $tagRAWINPUTHID=" & $tagRAWINPUTHID & @CRLF) Local $tRIM = DllStructCreate($tagRAWINPUTHID & 'byte RawData[n]; byte Mask;') local $test_header = _WinAPI_GetRawInputData($lParam, $tRIM, DllStructGetSize($tRIM), $RID_HEADER) ConsoleWrite(@YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & " [" & @AutoItPID & "] >> $test_header=" & $test_header & @CRLF) local $test_input = _WinAPI_GetRawInputData($lParam, $tRIM, DllStructGetSize($tRIM), $RID_INPUT) ConsoleWrite(@YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & " [" & @AutoItPID & "] >> $test_input=" & $test_input & @CRLF) ;~ Local $iFlags = DllStructGetData($tRIM, 'Flags') ;~ ConsoleWrite(@YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & " [" & @AutoItPID & "] >> $iFlags=" & $iFlags & @CRLF) ;~ Local $ButtonFlags = DllStructGetData($tRIM, 'ButtonFlags') ;~ ConsoleWrite(@YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & " [" & @AutoItPID & "] >> $ButtonFlags=" & $ButtonFlags & @CRLF) ;~ Local $ButtonData = DllStructGetData($tRIM, 'ButtonData') ;~ ConsoleWrite(@YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & " [" & @AutoItPID & "] >> $ButtonData=" & $ButtonData & @CRLF) Local $Mask = DllStructGetData($tRIM, 'Mask') ConsoleWrite(@YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & " [" & @AutoItPID & "] >> $Mask=" & $Mask & @CRLF) ;~ ConsoleWrite(@YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & " [" & @AutoItPID & "] >>" & @CRLF) ConsoleWrite(@YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & " [" & @AutoItPID & "] >> _WinAPI_DefRawInputProc($lParam, $tRIM)= " & _WinAPI_DefRawInputProc($lParam, $tRIM) & @CRLF) ConsoleWrite(@YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & " [" & @AutoItPID & "] >> STOP" & @CRLF & @CRLF) Return $GUI_RUNDEFMSG EndFunc ;==>WM_INPUT But the only thing I got is Quote 2023/06/27 11:58:52 [26788] >> START 2023/06/27 11:58:52 [26788] >> $wParam=0x00000001 2023/06/27 11:58:52 [26788] >> $lParam=0x3E201AF5 2023/06/27 11:58:52 [26788] >> $test_header=16 2023/06/27 11:58:52 [26788] >> $test_input=536 2023/06/27 11:58:52 [26788] >> $Mask=0 2023/06/27 11:58:52 [26788] >> _WinAPI_DefRawInputProc($lParam, $tRIM)= 1 2023/06/27 11:58:52 [26788] >> STOP When i press or release one of the 6 button on the devices. The $lParam is the only thing changes but it is not the same every time, so i cannot know if i press or release the button nor knowing which button is it. Is there someone here who can help me on this ? Really appreciate it Kind regards, 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