Chi*_*nke 122 remapping keyboard-layout key-binding capslock windows-10
在 Windows 8 中,我曾经使用注册表脚本重新映射我的大写锁定键以进行控制
REGEDIT4
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,1d,00,3a,00,00,00,00,00
Run Code Online (Sandbox Code Playgroud)
升级到 Window 10 后,这不再起作用。
怎么做到呢?
小智 130
如果有人需要通过 PowerShell 完成此操作:
$hexified = "00,00,00,00,00,00,00,00,02,00,00,00,1d,00,3a,00,00,00,00,00".Split(',') | % { "0x$_"};
$kbLayout = 'HKLM:\System\CurrentControlSet\Control\Keyboard Layout';
New-ItemProperty -Path $kbLayout -Name "Scancode Map" -PropertyType Binary -Value ([byte[]]$hexified);
Run Code Online (Sandbox Code Playgroud)
以管理员身份运行并重新启动。
小智 103
你记得重启吗?它对我来说很好用,就像在 Windows 7 和 8 中一样。
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,1d,00,3a,00,00,00,00,00
Run Code Online (Sandbox Code Playgroud)
小智 52
现在有一个直接来自 Microsoft 的解决方案,用于将大写锁定映射到名为PowerToys的控制键。PowerToys 不涉及使用第三方工具或手动修改注册表(如果操作不当,可能会导致严重问题)。PowerToys 中处理此问题的工具是默认安装的,称为键盘管理器。它完全按预期工作 - 这是映射到 Ctrl 键的 Caps Lock 键的图像。
小智 23
我使用以下命令为 CAPS LOCK 键发送 CTRL,为 CTRL 键发送 ALT,并为 ALT 键发送 CAPS LOCK。CTRL 位于“A”的左侧,这是上帝想要的,ALT 在 SHIFT 下方,完全无用的 CAPS LOCK 键安全地藏在我必须打破手腕才能击中它的地方。
Windows Registry Editor Version 5.00
; The hex data is in five groups of four bytes:
; 00,00,00,00,\ header version (always 00000000)
; 00,00,00,00,\ header flags (always 00000000)
; 04,00,00,00,\ # of entries (3 in this case) plus a NULL terminator line.
; Entries are in 2-byte pairs: Key code to send & keyboard key to send it.
; Each entry is in "least significant byte, most significant byte" order,
; e.g. 0x1234 becomes `34,12`
; 1d,00,3a,00,\ Send LEFT CTRL (0x001d) code when user presses the CAPS LOCK key (0x003a)
; 38,00,1d,00,\ Send LEFT ALT (0x0038) code when user presses the LEFT CTRL key (0x001d)
; 3a,00,38,00,\ Send CAPS LOCK (0x003a) code when user presses the LEFT ALT key (0x0038)
; 00,00,00,00 NULL terminator
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,\
00,00,00,00,\
04,00,00,00,\
1d,00,3a,00,\
38,00,1d,00,\
3a,00,38,00,\
00,00,00,00
Run Code Online (Sandbox Code Playgroud)
我曾经使用 AutoHotKey 来做到这一点。
我会在启动目录中有一个链接来运行一个非常基本的 ahk 脚本:
Capslock::Ctrl
Run Code Online (Sandbox Code Playgroud)
问题是,Autohotkey 不以管理员身份运行,因此它不会影响特权窗口,除非您使用任务调度程序而不是启动目录在登录时以更高的权限运行脚本。第二个问题是,有时候,在恢复睡眠时脚本挂起,因此您可能需要重新加载它,这很烦人。
AutoHotKey 更适合更复杂的任务,比如编写宏。
小智 6
这是用于交换 CTRL 和 CAPS LOCK 键的脚本:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,03,00,00,00,1d,00,3a,00,3a,00,1d,00,00,00,00,00
Run Code Online (Sandbox Code Playgroud)
小智 5
如果出于某种原因,您不想运行第三方工具,则可以使用一些 C 语言自己完成此操作。感谢 Susam Pal 的精彩回答,我将下面的代码片段放在一起。
它实际上是一个键盘记录器。它监听按键,捕获按键,并根据映射构建键盘输入。下面的控制台应用程序需要运行才能工作。
您将需要以某种方式编译它。我使用 msys2.org 并pacman -S mingw-w64-x86_64-gcc
使用/mingw64/bin/gcc nocaps.c -o nocaps.exe
.
#include <stdio.h>
#include <windows.h>
HHOOK hook;
#define KEYCODE_CAPSLOCK 20
#define KEYCODE_LCTRL 162
LRESULT CALLBACK keyboardHook(int nCode, WPARAM wParam, LPARAM lParam)
{
KBDLLHOOKSTRUCT *p = (KBDLLHOOKSTRUCT *) lParam;
INPUT input = {.type = INPUT_KEYBOARD };
printf("nCode=%d\t wParam=%d\t p->vkCode=%lu \t p->scanCode=%d\t\n", nCode, wParam, p->vkCode, p->scanCode);
if (wParam == WM_KEYUP || wParam == WM_SYSKEYUP) {
input.ki.dwFlags = KEYEVENTF_KEYUP;
}
if (p->vkCode == KEYCODE_CAPSLOCK && (p->flags & LLKHF_INJECTED) == 0) {
input.ki.wVk = KEYCODE_LCTRL;
SendInput(1, &input, sizeof (INPUT));
return 1;
} else if (p->vkCode == KEYCODE_LCTRL && (p->flags & LLKHF_INJECTED) == 0) {
input.ki.wVk = KEYCODE_CAPSLOCK;
SendInput(1, &input, sizeof (INPUT));
return 1;
}
return CallNextHookEx(hook, nCode, wParam, lParam);
}
int main(int argc, char **argv)
{
MSG messages;
hook = SetWindowsHookEx(WH_KEYBOARD_LL, keyboardHook, NULL, 0);
if (hook == NULL) {
printf("Error %d\n", GetLastError());
return 1;
}
printf("Mapping CAPSLOCK=>LCTRL and LCTRL=>CAPSLOCK..\n");
while (GetMessage (&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
166902 次 |
最近记录: |