LoginSignup
0
0

More than 1 year has passed since last update.

画面のロックを抑止する

Posted at
nolock.bat
@(echo '> NUL
echo off)
setlocal enableextensions
:: ref: https://www.inasoft.org/mousefr.html
set "HERE=%~f0"
set LINE[1]=     dBBBBb  dBBBBP dBP    dBBBBP dBBBP  dBP dBP
set LINE[2]=        dBP dBP.BP        dBP.BP        d8P.dBP
set LINE[3]=   dBP dBP dBP.BP dBP    dBP.BP dBP    dBBBBP
set LINE[4]=  dBP dBP dBP.BP dBP    dBP.BP dBP    dBP BB
set LINE[5]= dBP dBP dBBBBP dBBBBP dBBBBP dBBBBP dBP dBP
echo.
echo %LINE[1]%
echo %LINE[2]%
echo %LINE[3]%
echo %LINE[4]%
echo %LINE[5]%
echo.
powershell.exe -Command "iex -Command ((gc \"%HERE:`=``%\") -join \"`n\")"
exit /b %ERRORLEVEL%
') | sv -Name nolock

add-type -AssemblyName System.Windows.Forms

$signature=@'
    [DllImport("user32.dll",CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
    public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);
'@

$SendMouseEvent = Add-Type -memberDefinition $signature -name "Win32MouseEventNew" -namespace Win32Functions -passThru

echo "Press Ctrl + C to terminate this process."

$MOUSEEVENTF_MOVE = 0x00000001

$SleepSec = 50

$MoveMouseDistance = 1
$MoveMouseDistanceX = 1

$Flag = $true

while ($true) {
    Start-Sleep $SleepSec
    
    $x = [System.Windows.Forms.Cursor]::Position.X
    $y = [System.Windows.Forms.Cursor]::Position.Y
    
    $SendMouseEvent::mouse_event($MOUSEEVENTF_MOVE, -$MoveMouseDistance, 0, 0, 0)
    $SendMouseEvent::mouse_event($MOUSEEVENTF_MOVE,  $MoveMouseDistance, 0, 0, 0)
    
    if ($Flag) {
        $x += $MoveMouseDistanceX
        $Flag = $false;
    } else {
        $x -= $MoveMouseDistanceX
        $Flag = $true
    }
    [System.Windows.Forms.Cursor]::Position = new-object System.Drawing.Point($x, $y)
    $x = [System.Windows.Forms.Cursor]::Position.X
}

実行結果は以下のとおりです。
nolock.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0