Last active
August 23, 2020 17:44
-
-
Save nayan2/2012c600907489c5d7fd3fa57ed442f6 to your computer and use it in GitHub Desktop.
This is a script that will help you to hack your Desktime activity by moving mouse continuously
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
# Clear the host | |
Clear-Host | |
# Write/Log the starting date and time | |
Write-Host "Desktime Hack Started At" (Get-Date -Format G) -ForegroundColor Red | |
# Load assembly to manipulate mouse funationality | |
Add-Type -AssemblyName System.Windows.Forms | |
Add-Type @" | |
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using System.Runtime.InteropServices; | |
using System.Text; | |
public struct RECT | |
{ | |
public int left; | |
public int top; | |
public int right; | |
public int bottom; | |
} | |
public class pInvoke | |
{ | |
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, ExactSpelling = true, SetLastError = true)] | |
public static extern bool GetWindowRect(IntPtr hWnd, ref RECT rect); | |
[DllImport("user32.dll", SetLastError = true)] | |
public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow); | |
} | |
"@ | |
# Filter all unnecessary process | |
$currentProcess = Get-Process | Where-Object {$_.MainWindowTitle -ne "" -and $_.Path -notlike "*\SystemApps\*" -and $_.Path -notlike "*\WindowsApps\*" -and $_.Path -notlike "*\ImmersiveControlPanel\*" -and $_.Path -notlike "*\system32\*" } | |
# Declare gloabl variables | |
$addOrRemovePosition = 1; | |
$estimatedTimeForEachProcess = 1; | |
# Minimize all active windows | |
Write-Host "============================================== Minimizing All Windows ==============================================================" -ForegroundColor Green | |
$shell = New-Object -ComObject "Shell.Application" | |
$shell.minimizeall() | |
# Window count | |
Write-Host ($currentProcess.Count) "Active Processes Found" -ForegroundColor Yellow | |
# Perform mouse movement | |
while ($true) { | |
foreach($process in $currentProcess) { | |
Write-Host "====================================== Perform Operation On" ($process.MainWindowTitle) "===================================" -ForegroundColor Green | |
Start-Sleep -Seconds 3 | |
# Maximizing current window | |
Write-Host "Maximizing window" -ForegroundColor Green | |
[pInvoke]::ShowWindowAsync($process.MainWindowHandle, 4) # Maximizing window | |
# get the window bounds | |
$rect = New-Object RECT | |
[pInvoke]::GetWindowRect($process.MainWindowHandle, [ref]$rect) | |
# Moving cursor to the current window's middle position | |
$x = ($rect.Left + $rect.Right)/2 | |
$y = ($rect.Top + $rect.Bottom)/2 | |
[System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point($x, $y) | |
for ($i = 0; $i -lt $estimatedTimeForEachProcess * 15; $i++) { | |
$currentCursor = [System.Windows.Forms.Cursor]::Position | |
$x = $currentCursor.X + $addOrRemovePosition | |
$y = $currentCursor.Y + $addOrRemovePosition | |
[System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point($x, $y) | |
Start-Sleep -Seconds 3 | |
$addOrRemovePosition *= -1 | |
} | |
Write-Host "Minimizing window" -ForegroundColor Red | |
[pInvoke]::ShowWindowAsync($process.MainWindowHandle, 2) # Minimize window | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment