1

我有非常著名的 WinAPI 函数:

BOOL WINAPI RegisterHotKey(
  __in_opt  HWND hWnd,
  __in      int id,
  __in      UINT fsModifiers,
  __in      UINT vk
);

我看到我应该只能使用MOD_ALT, MOD_CONTROL, MOD_SHIFT,MOD_WIN键以及MOD_NOREPEAT.

因此,我可以使用以下内容为组合的A键创建系统范围的热键:Shift+A

RegisterHotKey(NULL,1,MOD_SHIFT,0x41);

现在重要的问题:

如何使用 NUM LOCK / SCROLL LOCK / CAPS LOCK 的状态(就像和其他的一样)作为我将注册的系统范围MOD_SHIFT热键的修饰符,以便组合键的注册键表现为打开任何此类“LOCK”键时的热键,并且在关闭任何“LOCK”键时也充当正常的非陷阱键?

我认为使用诸如GetKeyState(VK_NUMLOCK)&0xFFFF注册/取消注册热键之类的计时器和监视将是一个过于草率的解决方案,可能会减慢或干扰系统性能,这听起来像是一种不完整的方式,因为它与系统有关-wide 键行为。

有什么更好的方法?

4

1 回答 1

1

Depending on the situation I would probably just check for the state of a "LOCK" key at the beginning of your event code.

Otherwise if you really wanted to you can use SetWindowsHookEx to create a keyboard hook to do your monitoring.

于 2011-05-16T05:29:51.690 回答