OK, here is the changed "RemoteControl.ahk".
You have to adjust the values for your devices. Then it should give you information about the pressed and released keys in a tool tip.
I included an example for the "left" key being pressed on different devices. Adjust the device numbers to what you find in the tool tip and replace the message box with your custom code.
The script can be closed by pressing Win+C.
Note that this still doesn't deactivate any key in any way, it just adds functionality.
Hope this helps somebody out.
good luck, elmulti
Code:
; based on code by Micha
; changed by elmulti
; please adjust EditUsage and EditUsagePage for your devices
#SingleInstance force
; path to AutohotkeyRemoteControl.dll
HomePath=AutohotkeyRemoteControl.dll
; load the dll
hModule := DllCall("LoadLibrary", "str", HomePath) ; Avoids the need for DllCall() in
OnMessage(0x00FF, "InputMsg")
DetectHiddenWindows, on
SetTimer,UPDATEDSCRIPT,1000 ; for testing and developing
info_text := "" ; for testing only
; register first device
EditUsage = 6
EditUsagePage = 1
Gui, Show, Hide x0 y0 h0 w0, Autohotkey HID-Support
HWND := WinExist("Autohotkey HID-Support")
nRC := DllCall("AutohotkeyRemoteControl\RegisterDevice", INT, EditUsage, INT, EditUsagePage, INT, HWND, "Cdecl UInt")
if (errorlevel <> 0) || (nRC == -1)
{
MsgBox RegisterDevice failed. Errorcode: %errorlevel%
goto cleanup
}
; register second device (you can remove this part to use only one device)
EditUsage = 1 ; for mouse use: EditUsage = 2
EditUsagePage = 12 ; for mouse use: EditUsagePage = 1
nRC := DllCall("AutohotkeyRemoteControl\RegisterDevice", INT, EditUsage, INT, EditUsagePage, INT, HWND, "Cdecl UInt")
if (errorlevel <> 0) || (nRC == -1)
{
MsgBox RegisterDevice failed. Errorcode: %errorlevel%
goto cleanup
}
Return
InputMsg(wParam, lParam, msg, hwnd)
{
; for testing only
Global info_text
info_text := "------------------------`n" . info_text
DeviceNr = -1
; get device number and type
nRC := DllCall("AutohotkeyRemoteControl\GetWM_INPUTDataType", UINT, wParam, UINT, lParam, "INT *", DeviceNr, "Cdecl UInt")
if (errorlevel <> 0) || (nRC == 0xFFFFFFFF)
{
MsgBox GetWM_INPUTHIDData failed. Errorcode: %errorlevel%
goto cleanup
}
ifequal, nRC, 0 ; device is a mouse
{
; process mouse data
nHandle := DllCall("AutohotkeyRemoteControl\GetWM_INPUTMOUSEData", UINT, wParam, UINT, lParam, "UINT *" , pusFlags, "UINT *", pusBtnFlg
, "UINT *" , pusBtnData, "UINT *", pulRawBtn, "UINT *" , px, "UINT *", py, "UINT *", pextraInfo, "Cdecl UInt")
if (errorlevel <> 0) || (nHandle == -1)
{
MsgBox GetWM_INPUTMOUSEData failed. Errorcode: %errorlevel%
goto cleanup
}
DeviceNumber := DllCall("AutohotkeyRemoteControl\GetNumberFromHandle", UINT, nHandle, "Cdecl Int")
DeviceNumber := DeviceNumber +1 ;Index 0
; for testing only
; display a tooltip with the mouse info
info_text := "Mouse-Input `nDevicenumber: " . DeviceNumber . " `nFlags: " . pusFlags . " `nBtnFlag: " . pusBtnFlg . " `nButtonData: " . pusBtnData . " `nRawButton: " . pulRawBtn . " `nX: " . px . " `nY: " . py . " `nExtrainfo: " . pextraInfo . "`n" . info_text
Tooltip %info_text%
SetTimer, RemoveToolTip, 3000
}
else ifequal, nRC, 1 ; device is a keyboard
{
; Keyboard data
nHandle := DllCall("AutohotkeyRemoteControl\GetWM_INPUTKEYBOARDData", UINT, wParam, UINT, lParam, "UINT *" , pusMakeCode, "UINT *", pusFlags
, "UINT *" , pusKey, "UINT *", punMsg, "UINT *", pextraInfo, "Cdecl UInt")
if (errorlevel <> 0) || (nHandle == -1)
{
MsgBox GetWM_INPUTKEYBOARDData failed. Errorcode: %errorlevel%
goto cleanup
}
DeviceNumber := DllCall("AutohotkeyRemoteControl\GetNumberFromHandle", UINT, nHandle, "Cdecl Int")
DeviceNumber := DeviceNumber +1 ;Index 0
; for testing only
; display a tooltip with the key info
info_text := "Keyboard-Input `nDevice: " . DeviceNumber . "`nKey: " . pusKey . "`nMsg: " . punMsg . "`n" . info_text
Tooltip %info_text%
SetTimer, RemoveToolTip, 3000
; %punMsg% = 256 -> Button down, %punMsg% = 257 -> Button up
if DeviceNumber = 6
{
if pusKey = 37
{
MsgBox You pressed "Left" on device 6!
}
}
else if DeviceNumber = 5
{
if pusKey = 37
{
MsgBox You pressed "Left" on device 5!
}
}
}
else ifequal, nRC, 2 ; device is not a keyboard or mouse
{
DataSize = 5000
VarSetCapacity(RawData, %DataSize%)
;Write something into the var, so the script won't be aborted :
RawData = 1
nHandle := DllCall("AutohotkeyRemoteControl\GetWM_INPUTHIDData", UINT, wParam, UINT, lParam, "UINT *" , DataSize, "UINT", &RawData, "Cdecl UInt")
if (errorlevel <> 0) || (nHandle == -1)
{
MsgBox GetWM_INPUTHIDData failed. Errorcode: %errorlevel%
goto cleanup
}
DeviceNumber := DllCall("AutohotkeyRemoteControl\GetNumberFromHandle", UINT, nHandle, "Cdecl UInt")
loop, %DataSize%
{
Zahl := NumGet(RawData, a_index-1,"UChar")
Zahl := Dez2Hex(Zahl)
Vals = %Vals%%Zahl%
}
; for testing only
; display a tooltip with the button info
info_text := "HID-Button: " . vals . "`nDevice: " . DeviceNumber . "`n" . info_text
Tooltip %info_text%
SetTimer, RemoveToolTip, 3000
; perform action for the corresponding button
ifequal, Vals, 048000, gosub RED
ifequal, Vals, 040800, gosub GREEN
ifequal, Vals, 041000, gosub YELLOW
ifequal, Vals, 042000, gosub BLUE
}
; for testing only
info_text_length := StrLen(info_text)
If info_text_length > 500
info_text_length = 500
info_text := SubStr(info_text, 1 , info_text_length)
}
; for remote control buttons
RED:
Msgbox Red Button
Return
GREEN:
Msgbox Green Button
Return
YELLOW:
Msgbox Yellow Button
Return
BLUE:
Msgbox Blue Button
Return
Dez2Hex(Number)
{
format = %A_FormatInteger% ; save original integer format
SetFormat Integer, Hex ; for converting bytes to hex
Number += 0
SetFormat Integer, %format% ; restore original format
StringTrimLeft, Number, Number, 2
Stringlen := StrLen(Number)
if Stringlen < 2
Number = 0%Number%
return Number
}
; automatically updates the script as soon as it is changed
UPDATEDSCRIPT:
FileGetAttrib,attribs,%A_ScriptFullPath%
IfInString,attribs,A
{
FileSetAttrib,-A,%A_ScriptFullPath%
SplashTextOn,,,Updated Script,
Sleep,500
Reload
}
Return
; for testing only
RemoveToolTip:
SetTimer, RemoveToolTip, Off
info_text := ""
ToolTip
Return
; Win+C will exit the script
#c::
Gosub cleanup
Return
cleanup:
DllCall("FreeLibrary", "UInt", hModule) ; It is best to unload the DLL after using it (or before the script exits).
ExitApp