Windows で画面オフイベントをリッスンしてマウスを無効にする

Windows で画面オフイベントをリッスンしてマウスを無効にする

マウスで画面が起動しないようにしたい (PC はオンだが画面がオフの場合、またはスクリーンセーバーがオンの場合)。

私は「それができない」と正確に述べているすべてのリソースを読みました。例えばこの質問または、マウスを抜く、マウスを逆さまにする、マウスが PC をスリープ状態から復帰させないようにする、といったもの。 - それらには興味がありません。

この解決策を見つけるのを手伝ってくれる人がほしいです:

  • モニターのオフ イベント、またはスクリーンセーバーのオン イベントをインターセプトする方法。
  • そうでない場合は、monitorsOff.bat ファイル、nircmd コマンド、または AutoHotkey AHK コマンドを実行して、送信する明示的なモニター オフ コマンドを少なくとも傍受します。
  • 次に、マウス/キーボード以外の周辺機器を直ちに無効にするスクリプトを実行します。
  • その後、画面が再び起動するか、スクリーンセーバーが閉じられるか、少なくともキーボードのキーが押されたら、マウスを再度有効にします。

乾杯。

[編集]

user3419297 による AHK を使用した優れたソリューションが 1 つあります。理想的には、Windows がロックされている (ログオフではなくロックされている) 場合でも、機能が動作するはずです。

おそらく、DaaBoss が言ったように固定キーを使用するか、Windows アクセシビリティの他の部分を使用するのでしょう。

答え1

この AHK スクリプトを試してください:

$F1 Up::  ; or whatever combination you want
    Keyboard_Blocked := true   ; assign the Boolean value "true" or "1" to this variable
    BlockInput On   ; disable keyboard and mouse
    SendMessage, 0x112, 0xF170, 2,, Program Manager ; turn the monitor off, similar to power saving mode
    ; or:
    ; Run path of your screensaver 
return


; The #If directive creates context-sensitive hotkeys:

#If (Keyboard_Blocked) ; If this variable has the value "true" 

    $F1 Up::  ; press F1 to re-enable keyboard and mouse and turn the monitor on
        BlockInput Off
        Keyboard_Blocked := false
    return

#If ; turn off context sensitivity

編集:

電源オプションで、モニターの電源をオフにした後の非アクティブ時間を設定するか、Win+L を押してシステムをロックする代わりに、永続的に実行される AHK スクリプトを使用してこれを行うことができます。このスクリプトでは、作業を容易にするその他のもの (ホットキー、ホットストリング、関数など) を追加できます。

#NoEnv
#SingleInstance Force
SetTimer, DetectTimeIdle, 50
return

DetectTimeIdle:
; lock the computer automatically after 20 seconds of inactivity.
; Replace 20000 with 60000 for 1 minute etc.
If (A_TimeIdle > 20000) ; as long as there is no input within the last 20 seconds
    GoSub !F1 Up ; jump to this hotkey definition
return


; Press Alt+F1 to manually lock the computer
!F1 Up::
    Keyboard_Blocked := true   ; assign the Boolean value "true" or "1" to this variable
    BlockInput On   ; disable keyboard and mouse
    SendMessage, 0x112, 0xF170, 2,, Program Manager ; turn the monitor off, similar to power saving mode
return


#If (Keyboard_Blocked) 

    ; press F1 or F2 or Space ... to re-enable keyboard and mouse and turn the monitor on
    $F1 Up:: 
    $F2 Up::
    $Space Up::
    ; ...
        BlockInput Off
        Keyboard_Blocked := false
        ; Move the mouse  (speed 10) by 20 pixels to the right and 30 pixels down from its current location to unlock the computer:
        MouseMove, 20, 30, 10, R
        reload
    return

#If

関連情報