I am attempting monitor clipboard change by powershell, and never contemplate to make use of evaluating (Get-Clipboard) earlier than and after change as a result of it can’t distinguish between “two copy are equivalent” and “have not make new copy motion but”.
So I attempted to override WndProc of a dummy-control which is added to the chain of clipboard viewers by winAPI SetClipboardViewer.
But it surely appears not similar as anticipated.
#Embody script containing winAPI
.".Set-ClipboardViewer.ps1"
class MsgOnlyWin : System.Home windows.Kinds.Management{
[void] NotificationFunction()
{
Write-Host "Clipboard modified"
}
[void] WndProc($m)
{
$WM_DRAWCLIPBOARD = 0x308
if($m.Msg -eq $WM_DRAWCLIPBOARD){
NotificationFunction
break
}
}
}
$Con = [MsgOnlyWin]::new()
Set-ClipboardViewer ($Con.Deal with)
The way to repair?