如何重新映射程序以锁定 Windows(Win+L)

如何重新映射程序以锁定 Windows(Win+L)

我正在尝试将 WinLock 重新映射到新的东西。基本上,我想删除 Win+L 来锁定 Windows,并添加 Win+L 来打开要打开的特定程序。有什么帮助吗?谢谢。

附言:目前我使用#L::Run "C:\Program Files\program.exe" 返回来打开一个程序,但是它也会锁定工作站。我在注册表中找到了一种方法来禁用 Win+L 锁定 Windows 的功能,但是我不想编辑注册表,所以我很好奇是否可以使用自动热键来完成?

答案1

AHK 无法拦截这些 Windows 快捷方式。如果您不想编辑注册表值,我认为没有办法做到这一点。注册表值为HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System: DisableLockWorkstation1,则完全禁止锁定系统,无论是否有快捷方式,而为 0 则允许锁定,快捷方式 Win+L 将锁定系统,无论尝试拦截什么。注释(对于那些正在寻找有效的 Win+L 解决方案但不了解 AHK 的人)代码:

通过注册表编辑:

  ; WARNING: Programs that use User32\LockWorkStation (i.e. programmatically locking the operating system) may not work correctly! 
  ; This includes Windows itself (i.e. using start menu or task manager to lock will also not work).
  ; Script changes Win-L to show a msgbox and Ctrl-Alt-L to lock windows

  ; The following 3 code lines are auto-executed upon script run, the return line marks an end to the auto-executed code section.
  ; Register user defined subroutine 'OnExitSub' to be executed when this script is terminating
  OnExit, OnExitSub

  ; Disable LockWorkStation, so Windows doesn't intercept Win+L and this script can act on that key combination 
  SetDisableLockWorkstationRegKeyValue( 1 )
return

#l::
  MsgBox, Win-L was pressed! ; Arbitrary code here
return

^!l::
  ; Ctrl-Alt-L 
  ; Temporary enable locking
  SetDisableLockWorkstationRegKeyValue( 0 )
  ; Lock
  DllCall( "User32\LockWorkStation" )
  ; Disable locking again 
  SetDisableLockWorkstationRegKeyValue( 1 )
return

OnExitSub:
  ; Enable LockWorkStation, because this script is ending (so other applications aren't further disturbed)
  SetDisableLockWorkstationRegKeyValue( 0 )
  ExitApp
return

SetDisableLockWorkstationRegKeyValue( value )
  {
  RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Policies\System, DisableLockWorkstation, %value%
  }

相关内容