Skip to content

Instantly share code, notes, and snippets.

@k08045kk
Last active October 12, 2022 00:42
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save k08045kk/80e46994762ae66d3a7f1219716f3ef6 to your computer and use it in GitHub Desktop.
@powershell -NoProfile -ExecutionPolicy Unrestricted "&([ScriptBlock]::Create((cat \"%~f0\" | ?{$_.ReadCount -gt 1}) -join \"`n\"))" %* & goto:eof
# 上記の記述は、batコマンドです。 #
# ファイルの先頭行を無視してPowerShellで実行します。そして処理を終了します。 #
# AvoidScreenSaver.ps1 v2.2 #
# 移動量0のマウス移動イベントを周期的に発火してスクリーンセーバーを防止する。 #
# see https://www.bugbugnow.net/2020/10/avoid-screen-saver.html #
# see https://gist.github.com/k08045kk/80e46994762ae66d3a7f1219716f3ef6 #
# クラスの定義 #
# see https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-mouse_event #
$Signature = @'
[DllImport("user32.dll")]
public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);
'@
$MouseEvent = Add-Type -MemberDefinition $Signature -Name "Win32MouseEvent" -Namespace Win32Functions -PassThru
echo "AvoidScreenSaver.ps1 started."
echo "[Ctrl+C] Press to exit."
while ($true) {
# スリープ(50秒停止する) #
Start-Sleep -s 50
# 移動量0のマウス移動イベント(ロック画面・スクリーンセーバー・スリープ対策) #
$MouseEvent::mouse_event(1, 0, 0, 0, 0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment