From 10fea1a6e065086e3952d3e99e4f5d7c43e0c262 Mon Sep 17 00:00:00 2001 From: egieb <93350544+beigeworm@users.noreply.github.com> Date: Sat, 8 Jun 2024 16:32:06 +0000 Subject: [PATCH] Update main.ps1 --- Mouse-Clicks-Recorder/main.ps1 | 95 ++++++++++++++++++++++++++++++++-- 1 file changed, 92 insertions(+), 3 deletions(-) diff --git a/Mouse-Clicks-Recorder/main.ps1 b/Mouse-Clicks-Recorder/main.ps1 index eefeb03..9669021 100644 --- a/Mouse-Clicks-Recorder/main.ps1 +++ b/Mouse-Clicks-Recorder/main.ps1 @@ -26,7 +26,7 @@ while ($true){ $header = " =============================================== - =========== MOUSE CLICKS RECORDER =========== + =========== MOUSE CLICK RECORDER ============ =============================================== @@ -42,7 +42,9 @@ while ($true){ $option = Read-Host "Please Select an Option " if ($option -eq 1){ - $sequencefile = "$env:TEMP/sequence.ps1" + $sequencefile = "$env:TEMP\sequence.ps1" + $fullPath = (Get-Item $sequencefile).FullName + $sequencefileforc = $fullPath -replace '\\', '\\' Write-Host "Creating a file.." "# ===================================== CLICK SEQUENCER ========================================" | Out-File -FilePath $sequencefile -Force @@ -85,7 +87,91 @@ while ($true){ Write-Host "Setting up..." -ForegroundColor Yellow sleep 1 + +Add-Type @" +using System; +using System.IO; +using System.Runtime.InteropServices; +using System.Text; +public class MouseHook +{ + public delegate IntPtr HookProc(int nCode, IntPtr wParam, IntPtr lParam); + + [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] + public static extern IntPtr SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hMod, uint dwThreadId); + + [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool UnhookWindowsHookEx(IntPtr hhk); + + [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] + public static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam); + + public const int WH_MOUSE_LL = 14; + public const int WM_MOUSEWHEEL = 0x020A; + + private static HookProc _proc = HookCallback; + private static IntPtr _hookID = IntPtr.Zero; + + private static Encoding encoding = Encoding.Unicode; + private static string logFilePath = "$sequencefileforc"; + + public static void Start() + { + _hookID = SetHook(_proc); + } + + public static void Stop() + { + UnhookWindowsHookEx(_hookID); + } + + private static IntPtr SetHook(HookProc proc) + { + using (var curProcess = System.Diagnostics.Process.GetCurrentProcess()) + using (var curModule = curProcess.MainModule) + { + return SetWindowsHookEx(WH_MOUSE_LL, proc, GetModuleHandle(curModule.ModuleName), 0); + } + } + + private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam) + { + if (nCode >= 0 && wParam == (IntPtr)WM_MOUSEWHEEL) + { + int delta = Marshal.ReadInt32(lParam, 8); + string message; + if (delta > 0) + { + message = "[MouseSimulator]::ScrollUp()"; + } + else if (delta < 0) + { + message = "[MouseSimulator]::ScrollDown()"; + } + else + { + return CallNextHookEx(_hookID, nCode, wParam, lParam); + } + + using (StreamWriter writer = new StreamWriter(logFilePath, true, encoding)) + { + writer.WriteLine(message); + } + } + return CallNextHookEx(_hookID, nCode, wParam, lParam); + } + + [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] + private static extern IntPtr GetModuleHandle(string lpModuleName); +} +"@ + +# Start the mouse hook +[MouseHook]::Start() + function MouseState { + $previousState = [System.Windows.Forms.Control]::MouseButtons $previousPosition = [System.Windows.Forms.Cursor]::Position $lastClickTime = $null @@ -160,7 +246,10 @@ function MouseState { Write-Host "Recording..." -ForegroundColor Red while ($true) { MouseState -} +} + +[MouseHook]::Stop() + } if ($option -eq 2){