系统相关
首页 > 系统相关> > Python修改windows键盘映射

Python修改windows键盘映射

作者:互联网

新电脑环境的处理之一是修改键盘映射,主Ctrl键使用CapsLock

CapsLock改为LeftCtrl

RightCtrl改为CapsLock

LeftCtrl改为RightCtrl

原来使用KeybMap这个软件修改,由于自己修改的映射很少,改为通过python操作注册表实现

import winreg

mapVal = b'\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x1d\x00\x3A\x00\x3A\x00\x1D\xE0\x1D\xE0\x1D\x00\x00\x00\x00\x00'

rootKey_Machine = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"SYSTEM\CurrentControlSet\Control", 0, access=winreg.KEY_ALL_ACCESS)
rootkey_Machine_Keyboard = winreg.CreateKey(rootKey_Machine, "Keyboard Layout")

#rootKey_User = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r"System\CurrentControlSet\Control", 0, access=winreg.KEY_ALL_ACCESS)
#rootkey_User_Keyboard =  winreg.CreateKey(rootKey_User, "Keyboard Layout")
winreg.SetValueEx(rootkey_Machine_Keyboard,"Scancode Map", 0, winreg.REG_BINARY, mapVal)
print("Done")

  

关于注册表中键盘映射的定义,参考其他园丁的文章,或者:

https://docs.microsoft.com/en-us/windows-hardware/drivers/hid/keyboard-and-mouse-class-drivers#scan-code-mapper-for-keyboards

问题:键盘映射写入到currentuser注册表下,不生效(之前使用KeybMap软件,应用当前用户也不生效)

标签:winreg,映射,Python,Machine,windows,Keyboard,rootKey,x00
来源: https://www.cnblogs.com/sugartomato/p/16594090.html