windows 重新分配/覆盖热键 (Win + L) 以锁定窗口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/301053/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Re-assign/override hotkey (Win + L) to lock windows
提问by Mohit
Is it possible to re-assign the Win+Lhotkey to another executable/shortcut?
是否可以将Win+L热键重新分配给另一个可执行文件/快捷方式?
Use-case - I would like to switch off the monitor of my laptop as soon as it is locked. I know of a executable which can lock and turn off the monitor but I do not want to change the way the system is locked (by running the program explicitly or by some other shortcut). It would be best if Win+Lcan be assigned to this executable.
用例 - 我想在笔记本电脑被锁定后立即关闭它。我知道一个可以锁定和关闭监视器的可执行文件,但我不想更改系统锁定的方式(通过显式运行程序或通过其他一些快捷方式)。如果Win+L可以分配给这个可执行文件,那将是最好的。
回答by franc0is
You need to set the following registry key to completely disable the Windows locking feature:
您需要设置以下注册表项以完全禁用 Windows 锁定功能:
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System] "DisableLockWorkstation"=dword:00000001
And restart the computer.
并重新启动计算机。
This works on Win7, Win8 and Win10
这适用于 Win7、Win8 和 Win10
回答by efotinis
The Win+Lis a system assigned hotkey and there's no option to disable it. This means there's no way for an application to detect it, unless you use a low-level global keyboard hook(WH_KEYBOARD_LL
). This works in XP SP3; haven't tested it in Vista though:
该Win+L是系统分配的热键,有没有选项来禁用它。这意味着应用程序无法检测到它,除非您使用低级全局键盘钩子( WH_KEYBOARD_LL
)。这适用于 XP SP3;不过还没有在 Vista 中测试过:
LRESULT CALLBACK LowLevelKeyboardProc(int code, WPARAM wparam, LPARAM lparam) {
KBDLLHOOKSTRUCT& kllhs = *(KBDLLHOOKSTRUCT*)lparam;
if (code == HC_ACTION) {
// Test for an 'L' keypress with either Win key down.
if (wparam == WM_KEYDOWN && kllhs.vkCode == 'L' &&
(GetAsyncKeyState(VK_LWIN) < 0 || GetAsyncKeyState(VK_RWIN) < 0))
{
// Place some code here to do whatever you want.
// ...
// Return non-zero to halt message propagation
// and prevent the Win+L hotkey from getting activated.
return 1;
}
}
return CallNextHookEx(0, code, wparam, lparam);
}
Note that you need a low-levelkeyboard hook. A normalkeyboard hook (WH_KEYBOARD
) won't catch hotkey events.
请注意,您需要一个低级键盘钩子。一个正常的键盘钩子(WH_KEYBOARD
)不会赶上热键事件。
回答by Kyle Strand
The registry-based solution on its own completely disables locking the system (even via the Start
menu).
基于注册表的解决方案本身完全禁用锁定系统(甚至通过Start
菜单)。
Here is a method that actually provides a way to lock the computer without the Win-Lchord. Locking can either be done via a shortcut on the taskbar or by pressing them in sequence followed by Enter.
这是一种方法,它实际上提供了一种无需Win-L和弦即可锁定计算机的方法。锁定可以通过任务栏上的快捷方式完成,也可以按顺序按它们,然后按Enter。
First, create a batch file that can toggle system locking and trigger the lock itself; instructions for doing this are taken from a forum post:
首先,创建一个可以切换系统锁定并触发锁定本身的批处理文件;执行此操作的说明取自论坛帖子:
Create reg-edit files for turning system locking on or off. This is the same as in Brent Foust's answer.
In
DisableLockWorkstation.reg
:Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System] "DisableLockWorkstation"=dword:00000001
In
EnableLockWorkstation.reg
:Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System] "DisableLockWorkstation"=-
Runthe reg-edit script for disablingthe system lock.
Create a batch file to toggle the feature using the
.reg
files:regedit /S EnableLockWorkstation.reg rundll32.exe user32.dll,LockWorkStation regedit /S DisableLockWorkstation.reg
创建用于打开或关闭系统锁定的 reg-edit 文件。这与布伦特福斯特的回答相同。
在
DisableLockWorkstation.reg
:Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System] "DisableLockWorkstation"=dword:00000001
在
EnableLockWorkstation.reg
:Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System] "DisableLockWorkstation"=-
运行reg-edit 脚本以禁用系统锁定。
创建一个批处理文件以使用以下
.reg
文件切换功能:regedit /S EnableLockWorkstation.reg rundll32.exe user32.dll,LockWorkStation regedit /S DisableLockWorkstation.reg
Now, you can create a shortcut and pin it to the taskbar:
现在,您可以创建一个快捷方式并将其固定到任务栏:
- Right-click on the batch file and create a shortcut.
- Right-click on the new shortcut, edit the shortcut properties, and change target to
cmd.exe /C "<path>\lock.bat"
, where<path>
is the full path to thelock.bat
file. - The shortcut should now be pinnable to the taskbar (this is nottrue prior to manually changing the target); it can be dragged there as normal.
- (Note that you may also want to change the icon to something like a padlock beforepinning the shortcut to the taskbar.)
- 右键单击批处理文件并创建快捷方式。
- 右键单击新快捷方式,编辑快捷方式属性,并将目标更改为
cmd.exe /C "<path>\lock.bat"
,其中<path>
是lock.bat
文件的完整路径。 - 快捷方式现在应该可以固定到任务栏(在手动更改目标之前不是这样);它可以像往常一样拖到那里。
- (请注意,在将快捷方式固定到任务栏之前,您可能还想将图标更改为类似于挂锁的图标。)
As mentioned above, once you've completed the above procedure, you should be able to lock the computer using Win, L, Enterin sequence (notas a chord--though see below for a solution using Ctrl-Alt-Las a chord). This is because that sequence is interpreted as follows:
正如上面提到的,一旦你完成了上述步骤,你应该能够锁定使用计算机Win,L,Enter在序列(不为和弦-虽然见下文使用的解决方案Ctrl- Alt-L为和弦)。这是因为该序列被解释如下:
- Win-- brings up the Start menu, although you don't actually need to wait for it to load
- L-- searches for the custom lock-script; on my machine, the
lock.bat
shortcut was always the first Lresult ifit was the only shortcut on my taskbar starting with L. (Verify thisbefore attempting to lock your computer this way!) - Enter-- once the search finds an item, it will be launched--i.e. the shortcut will be called, and your computer will lock. You do notneed to wait for the search to load; you can quickly press Win, L, Enterin sequence and walk away. The screen will not lock immediately, but it should lock within a few seconds.
- Win-- 调出开始菜单,尽管您实际上并不需要等待它加载
- L-- 搜索自定义锁定脚本;我的机器上,该
lock.bat
快捷方式总是第一个L结果,如果这是对我的任务栏与开始的唯一捷径L。(在尝试以这种方式锁定您的计算机之前验证这一点!) - Enter-- 一旦搜索找到一个项目,它就会被启动——即会调用快捷方式,并且您的计算机将被锁定。你不会需要等待搜索到负载; 您可以快速按Win, L,Enter并走开。屏幕不会立即锁定,但应在几秒钟内锁定。
Below is a picture of the taskbar shortcut I made (using this icon):
下面是我制作的任务栏快捷方式的图片(使用这个图标):
EDIT: Using a chord, such as Ctrl-Alt-L
编辑:使用和弦,例如Ctrl- Alt-L
In the comments below, user lub094 suggests a way to assign the shortcut to the chordCtrl-Alt-L(or whatever shortcut you'd like). I have not taken the time to test this because I've re-enabled the system shortcut, but I assume that it works.
在下面的评论中,用户 lub094 建议了一种将快捷方式分配给和弦Ctrl- Alt- L(或您喜欢的任何快捷方式)的方法。我没有花时间测试这个,因为我已经重新启用了系统快捷方式,但我认为它可以工作。
Use the built-in shortcut-creation feature to assign the chord:
Place the shortcut itself in the Start Menu folder:
"C:\Users\ [user_name]\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\ [custom_folder]\"
回答by Brent Faust
The @FrancoisB method works for Win8 and Win7. To automate the solution:
@FrancoisB 方法适用于 Win8 和 Win7。要自动化解决方案:
Create a text file with the .reg suffix (DisableWinL.reg, for example)
Paste the following content and save the file:
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System] "DisableLockWorkstation"=dword:00000001
Open that file with RegEdit (double-click should work) to execute the change.
This file can be copied to a new machine to repeat the process. And another one named something like "EnableWinL.reg" could be created that re-enables the Win+Lkey:
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System] "DisableLockWorkstation"=dword:00000000
创建一个带有 .reg 后缀的文本文件(例如 DisableWinL.reg)
粘贴以下内容并保存文件:
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System] "DisableLockWorkstation"=dword:00000001
使用 RegEdit 打开该文件(双击应该可以)以执行更改。
可以将此文件复制到新机器以重复该过程。可以创建另一个名为“EnableWinL.reg”的文件来重新启用Win+L键:
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System] "DisableLockWorkstation"=dword:00000000
回答by ine
Looks like you can't.
好像不能
You can disable all built-in Windows hotkeys except Win+Land Win+U by making the following change to the registry (this should work on all OSes but a reboot is probably required):
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer NoWinKeys REG_DWORD 0x00000001 (1)
您可以通过对注册表进行以下更改来禁用除 Win+L和 Win+U之外的所有内置 Windows 热键(这应该适用于所有操作系统,但可能需要重新启动):
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer NoWinKeys REG_DWORD 0x00000001 (1)
(http://www.autohotkey.com/docs/misc/Override.htm)
( http://www.autohotkey.com/docs/misc/Override.htm)
But you could try using Tweak UI. Under the Explorer tree view item, uncheck "Enabled Windows+X" hotkeys. Hoekeyalso might work, haven't tried it. Source.
但是您可以尝试使用 Tweak UI。在资源管理器树视图项下,取消选中“启用 Windows+X”热键。Hoekey也可以,没试过。来源。