![在 Windows 中監聽螢幕關閉事件並停用滑鼠](https://rvso.com/image/1552786/%E5%9C%A8%20Windows%20%E4%B8%AD%E7%9B%A3%E8%81%BD%E8%9E%A2%E5%B9%95%E9%97%9C%E9%96%89%E4%BA%8B%E4%BB%B6%E4%B8%A6%E5%81%9C%E7%94%A8%E6%BB%91%E9%BC%A0.png)
我想防止滑鼠喚醒我的螢幕(當我的電腦打開但螢幕關閉或螢幕保護程式打開時)。
我已閱讀所有資源,確切地告訴我“這是不可能完成的”,例如這個問題。或者那些說拔掉滑鼠,或將滑鼠翻轉過來,或阻止滑鼠將電腦從睡眠狀態喚醒的說法。 - 對那些不感興趣。
我希望有人幫我找出這個解決方案:
- 如何攔截顯示器關閉事件或螢幕保護程式開啟事件。
- 如果沒有,那麼至少攔截我透過執行monitorsOff.bat 檔案或nircmd 命令或AutoHotkey AHK 命令發送的明確監視器關閉命令。
- 然後運行一個腳本,立即停用我的滑鼠/非鍵盤週邊。
- 然後,如果螢幕被喚醒,或者螢幕保護程式關閉,或至少按下任何鍵盤鍵,則重新啟用滑鼠。
乾杯。
[編輯]
我們透過 user3419297 的 AHK 提供了一個很棒的解決方案。理想情況下,如果/當視窗被鎖定(不是註銷,而是鎖定)時,該功能也應該起作用。
也許以某種方式使用 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
編輯:
您可以使用永久執行的 AHK 腳本來完成此操作,而不是在電源選項中配置顯示器關閉後的不活動時間或按 Win+L 鎖定係統。在此腳本中,您可以添加更多有助於您工作的內容(熱鍵、熱字串、函數等)。
#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