-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New scripts for reactivate window scenario.
- Loading branch information
Showing
3 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# https://github.com/sw3103/movemouse/wiki/Scenarios#reactivate-previous-active-window-on-pausestop | ||
|
||
$TextFilePath = Join-Path -Path:$env:TEMP -ChildPath:"MoveMouseWindowPid.txt" | ||
|
||
if (Test-Path -Path:$TextFilePath) { | ||
$WindowPid = Get-Content -Path:$TextFilePath | ||
|
||
if (![System.String]::IsNullOrWhiteSpace($WindowPid)) { | ||
Add-Type -AssemblyName:"Microsoft.VisualBasic" | ||
[Microsoft.VisualBasic.Interaction]::AppActivate([int]$WindowPid) | ||
} | ||
else { | ||
throw "$TextFilePath was empty." | ||
} | ||
} | ||
else { | ||
throw "$TextFilePath does not exist. You need to run this script with the -Capture parameter first." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# https://github.com/sw3103/movemouse/wiki/Scenarios#reactivate-previous-active-window-on-pausestop | ||
|
||
Add-Type -TypeDefinition @" | ||
using System; | ||
using System.Runtime.InteropServices; | ||
public class NativeMethods | ||
{ | ||
[DllImport("user32.dll")] | ||
public static extern IntPtr GetForegroundWindow(); | ||
[DllImport("user32.dll", SetLastError=true)] | ||
public static extern uint GetWindowThreadProcessId( | ||
IntPtr hWnd, | ||
out uint lpdwProcessId); | ||
} | ||
"@ | ||
|
||
$TextFilePath = Join-Path -Path:$env:TEMP -ChildPath:"MoveMouseWindowPid.txt" | ||
$Hwnd = [NativeMethods]::GetForegroundWindow() | ||
$WindowPid = 0 | ||
|
||
if ([NativeMethods]::GetWindowThreadProcessId($Hwnd, [ref]$WindowPid) -gt 0) { | ||
$WindowPid | Out-File -FilePath:$TextFilePath -Append:$false -Force | ||
} | ||
else { | ||
throw "Error capturing active window process ID." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters