From d1ad15558e8edfa0f3796be5081bb33386148c65 Mon Sep 17 00:00:00 2001 From: Clive Galway Date: Tue, 21 Mar 2023 15:07:36 +0000 Subject: [PATCH] Device list and copy buttons working for v2 monitor --- v2/Monitor.ahk | 249 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 249 insertions(+) create mode 100644 v2/Monitor.ahk diff --git a/v2/Monitor.ahk b/v2/Monitor.ahk new file mode 100644 index 0000000..094775f --- /dev/null +++ b/v2/Monitor.ahk @@ -0,0 +1,249 @@ +/* +Script to show data flowing from Interception +*/ +#SingleInstance force +Persistent +#include Lib\AutoHotInterception.ahk + +OutputDebug("DBGVIEWCLEAR") + +mg := Gui("", "AutoHotInterception Monitor") +mg.MarginX := 0 +mg.MarginY := 0 + +DeviceList := {} +filterMouseMove := 1 +filterKeyPress := 0 + +AHI := AutoHotInterception() + +; Device List +DeviceList := AHI.GetDeviceList() + +marginX := 10 +marginY := 10 +idW := 50 ; Width of the ID text +vhOff := 7 ; Width to space VIDPID / Handle above/below ID row +copyW := 40 ; Width of the Copy buttons +outputH := 350 ; Height of the Output boxes +rowH := 35 ; Distance between each row of devices + +maxWidths := Map("K", 0, "M", 0) ; Max Width of device entries for each column +totalWidths := Map("K", 0, "M", 0) ; Total Width of each column +tW := Map("K", 0, "M", 0) +devTypes := ["K", "M"] ; Lookup table for device type +starts := Map("K", 0, "M", 10) ; Start IDs for each device type +columnTitles := Map("K", "Keyboards", "M", "Mice") ; Column Titles +columnX := Map("K", 0, "M", 0) + + +Loop 2 { + strings := Map() + devType := devTypes[A_Index] + columnX[devType] := GetColX(devType) + + start := starts[devType] + UpdateWidth(0, 1) ; Reset max width + + ; Add device entries + Loop 10 { + i := start + A_Index + if (!DeviceList.Has(i)){ + continue + } + dev := DeviceList[i] + rowY := (marginY * 3) + ((A_Index - 1) * rowH) + + chkDevice := mg.Add("Checkbox", "x" columnX[devType] " y" rowY " w" idW, "ID: " dev.id) + chkDevice.OnEvent("Click", CheckboxChanged.Bind(dev.id)) + + lowest := UpdateLowest(chkDevice) + strings[A_index] := {vid:FormatHex(dev.VID), pid: FormatHex(dev.PID), handle: dev.Handle} + + textVidPid := mg.Add("Text", "x" columnX[devType] + idW " y" rowY - vhOff, "VID / PID:`t0x" strings[A_index].vid ", 0x" strings[A_index].pid) + maxWidths[devType] := UpdateWidth(textVidPid) + + textHandle := mg.Add("Text", "x" columnX[devType] + idW " y" rowY + vhOff, "Handle:`t`t" StrReplace(strings[A_index].Handle, "&", "&&")) + maxWidths[devType] := UpdateWidth(textHandle) + } + + ; Add copy buttons + Loop 10 { + i := start + A_Index + if (!DeviceList.Has(i)){ + continue + } + dev := DeviceList[i] + rowY := (marginY * 3) + ((A_Index - 1) * rowH) + xpos := columnX[devType] + idW + maxWidths[devType] + + btnCopyVidPid := mg.Add("Button", "x" xpos " y" rowY - vhOff " h14 w" copyW, "Copy") + btnCopyVidPid.OnEvent("Click", CopyClipboard.Bind("0x" strings[A_index].vid ", 0x" strings[A_index].pid)) + + btnCopyHandle := mg.Add("Button", "x" xpos " y" rowY + vhOff " h14 w" copyW, "Copy") + btnCopyHandle.OnEvent("Click", CopyClipboard.Bind(strings[A_index].handle)) + } + + totalWidths[devType] := idW + maxWidths[devType] + copyW + mg.Add("Text", "x" columnX[devType] " y5 w" totalWidths[devType] " Center", columnTitles[devType]) +} + +lowest += 2 * MarginY + +; Options +; Gui, Add, CheckBox, % "x" columnX.K " y" lowest " hwndhCbFilterPress", Only show key releases +; fn := Func("FilterPress") +; GuiControl, +g, % hCbFilterPress, % fn + +; Gui, Add, CheckBox, % "x" columnX.M " w" totalWidths[devType] " yp hwndhCbFilterMove Checked", Filter Movement (Warning: Turning off can cause crashes) +; fn := Func("FilterMove") +; GuiControl, +g, % hCbFilterMove, % fn + +lowest += 2 * MarginY + +; Gui, Add, Button, % "x" columnX.K " y" lowest " w" totalWidths.K " Center gClearKeyboard", Clear +; Gui, Add, Button, % "x" columnX.M " yp w" totalWidths.M " gClearMouse Center", Clear + +lowest += 30 + +; Output +; Gui, Add, ListView, % "x" columnX.K " y" lowest " w" totalWidths.K " h" outputH " hwndhLvKeyboard", ID|Code|State|Key Name +; LV_ModifyCol(4, 100) +; Gui, Add, ListView, % "x" columnX.M " yp w" totalWidths.M " h" outputH " hwndhLvMouse", ID|Code|State|X|Y|Info +; LV_ModifyCol(6, 200) + +lowest += outputH + +; Gui("Show", "w" (marginX * 3) + totalWidths.K + totalWidths.M " h" marginY + lowest, "AutoHotInterception Monitor") +mg.Show("w" (marginX * 3) + totalWidths["K"] + totalWidths["M"] " h" marginY + lowest) + +;~ Monitor.Subscribe(Func("KeyboardEvent"), Func("MouseEvent")) + +return + + +GetColX(devType){ + global marginX, idW, maxWidths, copyW + if (devType == "K") + return marginX + else + return (marginX * 2) + idW + maxWidths["K"] + copyW +} + +UpdateLowest(ctrl){ + static max := 0 + ctrl.GetPos(&cpX, &cpY, &cpW, &cpH) + pos := cpY + cpH + if (pos > max){ + max := pos + } + return max +} + +UpdateWidth(ctrl, reset := 0){ + static max := 0 + if (reset){ + max := 0 + return + } + ctrl.GetPos(&cpX, &cpY, &cpW, &cpH) + if (cpW > max){ + max := cpW + } + return max +} + +CheckboxChanged(id, ctrl, info){ + global AHI + if (ctrl.Value){ + if (id < 11){ + AHI.SubscribeKeyboard(id, false, KeyboardEvent.Bind(id)) + } else { + AHI.SubscribeMouseButtons(id, false, MouseButtonEvent.Bind(id)) + AHI.SubscribeMouseMoveRelative(id, false, MouseAxisEvent.Bind(id, "Relative Move")) + AHI.SubscribeMouseMoveAbsolute(id, false, MouseAxisEvent.Bind(id, "Absolute Move")) + } + } else { + if (id < 11){ + AHI.UnsubscribeKeyboard(id) + } else { + AHI.UnsubscribeMouseButtons(id) + AHI.UnsubscribeMouseMoveRelative(id) + AHI.UnsubscribeMouseMoveAbsolute(id) + } + } +} +/* + +FilterMove(hwnd){ + global filterMouseMove + GuiControlGet, state, , % hwnd + filterMouseMove := state +} + +FilterPress(hwnd){ + global filterKeyPress + GuiControlGet, state, , % hwnd + filterKeyPress := state +} + +ClearKeyboard: + Gui, ListView, % hLvKeyboard + LV_Delete() + return + +ClearMouse: + Gui, ListView, % hLvMouse + LV_Delete() + return + +*/ + +FormatHex(num){ + return Format("{:04X}", num) +} + + +KeyboardEvent(id, code, state){ + ToolTip("Keyboard Event`nid: " id "`ncode: " code "`nstate: " state) + ; global hLvKeyboard, filterKeyPress + ; if (filterKeyPress && state) + ; return + ; Gui, ListView, % hLvKeyboard + ; scanCode := Format("{:x}", code) + ; keyName := GetKeyName("SC" scanCode) + ; row := LV_Add(, id, code, state, keyName) + ; LV_Modify(row, "Vis") +} + +MouseButtonEvent(id, code, state){ + ; global hLvMouse + ; Gui, ListView, % hLvMouse + ; row := LV_Add(, id, code, state, "", "", "Button") + ; LV_Modify(row, "Vis") +} + +MouseAxisEvent(id, info, x, y){ + ; global hLvMouse, filterMouseMove + ; if (filterMouseMove) + ; return + ; Gui, ListView, % hLvMouse + ; row := LV_Add(, id, "", "", x, y, info) + ; LV_Modify(row, "Vis") +} + +CopyClipboard(str, ctrl, info){ + A_Clipboard := str + Tooltip("Copied to Clipboard") + SetTimer(ClearTooltip, 1000) +} + +ClearTooltip(){ + ToolTip +} + +^Esc:: +{ + GuiClose: + ExitApp +}