How can I deal with depressed Windows logo key when using `SendInput`?

后端 未结 3 1327
我寻月下人不归
我寻月下人不归 2020-12-19 20:22

My application synthesises keystrokes in other apps by using SendInput. This almost works, except that due to circumstances I cannot change, the left Windows ke

3条回答
  •  不思量自难忘°
    2020-12-19 21:10

    "Correcting" the state of a modifier key by inserting a KEYEVENTF_KEYUP event may have side-effects, but they can be avoided by inserting additional events.

    The Start menu is triggered when the Win key is pressed and released, except when there is an intervening key event or if it was pressed in combination with another modifier. So instead of inserting just Win-up, insert Ctrl-down, Win-up, Ctrl-up.

    Aside from the Start menu, releasing modifier keys might have other side-effects:

    • Releasing Alt can activate the active window's menu (even if it doesn't appear to have one).
    • Releasing Alt or Shift can activate the Alt+Shift language hotkey.
    • Releasing Ctrl or Shift can activate the Ctrl+Shift language hotkey.
    • Releasing any modifier key can activate the Office hotkey (in Windows 1903 and later, pressing and releasing Ctrl+Alt+Shift+Win opens the Office app).

    Inserting a key-down and key-up (or possibly just a key-up without a prior key-down) with almost any other virtual keycode first will generally prevent any of these hotkeys from activating. One can use an undefined or reserved keycode such as 0xE8, although there is still a risk that another program makes use of it.

提交回复
热议问题