Last active
October 2, 2024 01:23
-
-
Save k08045kk/80e46994762ae66d3a7f1219716f3ef6 to your computer and use it in GitHub Desktop.
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
@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