#Requires Autohotkey v2.0+ #SingleInstance force ~^s::Reload ; have ctrl-s reload the script - useful when making frequent edits ; The HID top level collection for the Natural Keyboard 4000 is: ; Usage 1 ; Usage Page 12 ; Keyboards are always Usage 6, Usage Page 1, Mice are Usage 2, Usage Page 1, ; HID devices specify their top level collection in the info block Usage := 1 UsagePage := 12 inputFuncs := Map() inputFuncs["1735E"] := Send.Bind("{LAlt Down}{LShift Down}{b Down}{LAlt Up}{LShift Up}{b Up}") ;-------------------------------------------------------- DetectHiddenWindows(true) OnMessage(0x00FF, InputMessage) SizeofRawInputDeviceList := A_PtrSize * 2 SizeofRawInputDevice := 8 + A_PtrSize SizeofRidDeviceInfo := 8 + A_PtrSize * 2 RIM_TYPEMOUSE := 0 RIM_TYPEKEYBOARD := 1 RIM_TYPEHID := 2 RIDI_DEVICENAME := 0x20000007 RIDI_DEVICEINFO := 0x2000000b RIDEV_INPUTSINK := 0x00000100 RID_INPUT := 0x10000003 NaturalCapture := Gui(,"NaturalCapture") NaturalCapture.OnEvent("Close", (*)=>ExitApp) NaturalCapture.Show("Hide") HWND := NaturalCapture.Hwnd RawDevice := Buffer(SizeOfRawInputDevice) NumPut("UPtr", RIDEV_INPUTSINK, RawDevice, 4) NumPut("UPtr", HWND, RawDevice, 8) NumPut("UShort", UsagePage, RawDevice, 0) NumPut("UShort", Usage, RawDevice, 2) Res := DllCall("RegisterRawInputDevices", "UInt", RawDevice.Ptr, "UInt", 1, "UInt", SizeOfRawInputDevice) if (Res = 0) MsgBox "Failed to register for HID device" ;-------------------------------------- InputMessage(wParam, lParam, msg, hwnd) { global RIM_TYPEMOUSE, RIM_TYPEKEYBOARD, RIM_TYPEHID global RID_INPUT Size := 0 Res := DllCall("GetRawInputData", "UInt", lParam, "UInt", RID_INPUT, "UInt", 0, "UInt*", &Size, "UInt", SizeofRidDeviceInfo) MsgBuffer := Buffer(Size) Res := DllCall("GetRawInputData", "UInt", lParam, "UInt", RID_INPUT, "Ptr", MsgBuffer, "UInt*", &Size, "UInt", SizeofRidDeviceInfo) VarType := NumGet(MsgBuffer, 0 * 4, "UInt") Size := NumGet(MsgBuffer, 1 * 4, "UInt") Handle := NumGet(MsgBuffer, 2 * 4, "UInt") ;Debug("Got Input with " . Res . " size " . Size . " Type " . VarType . " Handle " . Handle . "`r`n") if (VarType = RIM_TYPEHID) { SizeHid := NumGet(MsgBuffer, SizeofRidDeviceInfo , "UInt") InputCount := NumGet(MsgBuffer, 4+SizeofRidDeviceInfo, "UInt") ;Debug("HND " . Handle . " HID Size " . SizeHid . " Count " . InputCount . " Ptr " . MsgBuffer.Ptr . "`r`n") Loop InputCount { Addr := MsgBuffer.Ptr + 16+A_PtrSize*2 + ((A_Index - 1) * SizeHid) BAddr := MsgBuffer.Ptr ;Debug("BAddr: " Mem2Hex(BAddr, SizeHid) "`r`nAddr: " Mem2Hex(Addr, SizeHid)) Input := Mem2Hex(Addr, SizeHid) ;Debug("Input " . Input . "`r`n") ; comment out when you have the right input if (inputFuncs.Has(Input)) { inputFuncs[Input]() ; call the function stored in the map where the key is the input } } } return } Debug(msg) { MsgBox msg } Mem2Hex( pointer, len ) { hexDump := "" Loop len { Hex := NumGet(Pointer,"uint") Hex := StrReplace(Hex, "0x", "0x0") Hex := SubStr(Hex, -2) hexDump := hexDump . hex Pointer++ } Return Format("{:X}",StrUpper(hexDump)) }