diff --git a/.gitignore b/.gitignore index a6342f7..037425d 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ Borealis-Server.exe # Misc Files/Folders .vs/s /Update_Staging/ +/Macro_Testing/ # On-the-Fly Downloaded Dependencies /Dependencies/NodeJS/ diff --git a/Borealis.ps1 b/Borealis.ps1 index 0264ec5..5b45b1a 100644 --- a/Borealis.ps1 +++ b/Borealis.ps1 @@ -282,8 +282,8 @@ Write-Host " 4) Package Self-Contained EXE of Server or Agent " -NoNewline -Fore Write-Host "[Experimental]" -ForegroundColor Red Write-Host " 5) Update Borealis " -NoNewLine -ForegroundColor DarkGray Write-Host "[Requires Re-Build]" -ForegroundColor Red -Write-Host " 6) Perform Basic Macro Automation Testing " -NoNewline -ForegroundColor DarkGray -Write-Host "[Experimental]" -ForegroundColor Red +Write-Host " 6) Perform AutoHotKey Automation Testing " -NoNewline -ForegroundColor DarkGray +Write-Host "[Experimental - Dev Testing]" -ForegroundColor Red Write-Host "Type a number and press " -NoNewLine Write-Host "" -ForegroundColor DarkCyan $choice = Read-Host @@ -602,4 +602,40 @@ switch ($choice) { & (Join-Path $scriptDir "Borealis.ps1") Exit 0 } + + "6" { + $host.UI.RawUI.WindowTitle = "AutoHotKey Automation Testing" + Write-Host " " + Write-Host "Lauching AutoHotKey Testing Script..." -ForegroundColor Blue + + $venvFolder = "Macro_Testing" + $scriptSourcePath = "Data\Experimental\Macros\Macro_Script.py" + $scriptRequirements = "Data\Experimental\Macros\macro-requirements.txt" + $scriptDestinationFolder = "$venvFolder\Borealis" + $scriptDestinationFile = "$venvFolder\Borealis\Macro_Script.py" + $venvPython = Join-Path $scriptDir $venvFolder | Join-Path -ChildPath 'Scripts\python.exe' + + Run-Step "Create Virtual Python Environment" { + if (-not (Test-Path "$venvFolder\Scripts\Activate")) { + & $pythonExe -m venv $venvFolder + } + if (Test-Path $scriptSourcePath) { + Remove-Item $scriptDestinationFolder -Recurse -Force -ErrorAction SilentlyContinue + New-Item -Path $scriptDestinationFolder -ItemType Directory -Force | Out-Null + Copy-Item $scriptSourcePath $scriptDestinationFile -Force + Copy-Item "Dependencies\AutoHotKey" $scriptDestinationFolder -Recurse + } + . "$venvFolder\Scripts\Activate" + } + + Run-Step "Install Python Dependencies" { + if (Test-Path $scriptRequirements) { + & $venvPython -m pip install --disable-pip-version-check -q -r $scriptRequirements | Out-Null + } + } + + Write-Host "`nLaunching Macro Testing Script..." -ForegroundColor Blue + Write-Host "====================================================================================" + & $venvPython -W ignore::SyntaxWarning $scriptDestinationFile + } } diff --git a/Data/Experimental/Macros/Macro_Script.py b/Data/Experimental/Macros/Macro_Script.py new file mode 100644 index 0000000..62d0da2 --- /dev/null +++ b/Data/Experimental/Macros/Macro_Script.py @@ -0,0 +1,43 @@ +# ---------------------- Information Gathering ---------------------- +import os +from ahk import AHK + +# Get the directory containing this script (cross-platform) +script_dir = os.path.dirname(os.path.abspath(__file__)) + +# Build the path to the AutoHotkey binary (adjust filename if needed) +ahk_bin_path = os.path.join(script_dir, 'AutoHotKey', 'AutoHotkey64.exe') + +# ---------------------- Information Analysis ---------------------- +# Confirm that the AHK binary exists at the given path +if not os.path.isfile(ahk_bin_path): + raise FileNotFoundError(f"AutoHotkey binary not found at: {ahk_bin_path}") + +# ---------------------- Information Processing ---------------------- +# Initialize AHK instance with explicit executable_path +ahk = AHK(executable_path=ahk_bin_path) + +window_title = '*TargetWindow - Notepad' # Change this to your target window + +# Find the window by its title +target_window = ahk.find_window(title=window_title) + +if target_window is None: + print(f"Window with title '{window_title}' not found.") +else: + # Bring the target window to the foreground + target_window.activate() + + # Wait briefly to ensure the window is focused + import time + time.sleep(1) + + # Send keystrokes/text to the window + text = "Hello from Python and AutoHotkey!" + for c in text: + ahk.send(c) + import time + time.sleep(0.05) # slow down for debugging + ahk.send('{ENTER}') + + print("Sent keystrokes to the window.") diff --git a/Data/Experimental/Macros/macro-requirements.txt b/Data/Experimental/Macros/macro-requirements.txt new file mode 100644 index 0000000..ce12d8f --- /dev/null +++ b/Data/Experimental/Macros/macro-requirements.txt @@ -0,0 +1,4 @@ +#////////// PROJECT FILE SEPARATION LINE ////////// CODE AFTER THIS LINE ARE FROM: /Data/Experimental/Macros/macro-requirements.txt + +# Macro Automation +ahk # AutoHotKey \ No newline at end of file