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

后端 未结 3 1326
我寻月下人不归
我寻月下人不归 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:27

    I basically solved this exact problem yesterday :) My code is in C#, but it mostly consists of win32 API calls via p/invoke, so it should translate directly to C++.

    The solution is to use a Low-Level Keyboard Hook to intercept the initial Windows key KeyDown event (and tell the OS that you handled it so that it won't be passed to other Applications and/or the OS). Then, depending on OS, simulate the Windows key KeyUp event before your input. It sounds like you're half-way there, you just need to intercept the initial KeyDown.

    My solution is targeted at Windows Vista and Windows 7, so if you're in XP or below, it's possible that you don't need to send the KeyUp. That's what I'll be testing soon, it may work in both; however, Vista and 7 intercept the windows key more aggressively than XP, hence my suspicions.

提交回复
热议问题