简体   繁体   English

使用C#使用Ctrl覆盖Caps Lock

[英]Override Caps Lock with Ctrl using C#

I'm writing ( yet another , I know) keyboard remapper using C# and Visual Studio 2008. 我正在使用C#和Visual Studio 2008编写(我知道的另一个 )键盘重映射器。

I followed this guide to learn how to snap up low-level key presses. 我按照本指南学习了如何抢购低级按键。 This works just fine for overriding eg normal alphabetical characters on my keyboard, but I seem to need a bit more to make Caps Lock act like Ctrl . 这适用于覆盖我的键盘上的普通字母字符,但我似乎需要更多一点来使Caps LockCtrl一样。

My understanding (which may be incorrect) is that Caps Lock and Ctrl are handled completely different from one another since Caps Lock is a toggling key whereas Ctrl is just a "normal" one. 我的理解(可能不正确)是Caps LockCtrl处理完全不同,因为Caps Lock是一个切换键,而Ctrl只是一个“正常”键。

So what I'm trying to understand here is how to make Caps Lock behave like a Ctrl key on the very lowest level and also how to make the normal Ctrl key act like a Caps Lock key. 所以我在这里想要了解的是如何使Caps Lock在最低级别上表现得像一个Ctrl键,以及如何使普通的Ctrl键像Caps Lock键一样。

Thanks 谢谢

Maintain a bool which represents expected state of caps lock. 维持一个bool,代表预期的大写锁定状态。 When caps lock key is hit, set the systems's Caps Lock value back to the bool's value. 当大写锁定键被命中时,将系统的大写锁定值设置回bool的值。 When Ctrl is hit, toggle the expected state of the caps lock and set the system's cap lock value to the bool's value. 按下Ctrl时 ,切换大写锁定的预期状态并将系统的上限锁定值设置为bool的值。

Use the following to set the initial expected state: 使用以下命令设置初始预期状态:

[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true, CallingConvention=CallingConvention.Winapi)] 
public static extern short GetKeyState(int keyCode); 
bool CapsLock = (((ushort)GetKeyState(0x14)) & 0xffff) != 0;

Add special logic in HookCallback (from the link you provided) for when Ctrl and Caps Lock are hit. 在HookCallback中添加特殊逻辑(来自您提供的链接),以便在命中CtrlCaps Lock时添加 Caps lock is when lParam is &H14 . 大写锁定是指lParam是&H14 Ctrl is when lParam is &H11 . 当lParam为&H11时,Ctrl为。

To get/set the system's Caps Lock value: 获取/设置系统的Caps Lock值:

http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/fb8308e5-7620-43cc-8ad8-be67d94708fa/ http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/fb8308e5-7620-43cc-8ad8-be67d94708fa/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM