0

I use a WS_EX_LAYERED window and receive a WM_MOUSEMOVE message when the mouse moves over non-transparent areas. So far so good.

  • When I press and hold SHIFT or CTRL and move the mouse, WM_MOUSEMOVE/wParam doesn't indicate the key state.

  • When I press and hold SHIFT or CTRL and ANY mouse buttons while moving the mouse, WM_MOUSEMOVE/wParam does indicate the key state.

  • When I click into the window (assuming to set focus) and hold SHIFT or CTRL, again, WM_MOUSEMOVE / wParam doesn't indicate the key state.

Any idea what's up here? I have the suspicion that it has something to do with the active focus state of the window.

  • 2
    Please provide a [mcve] – Remy Lebeau Feb 28 '21 at 18:44
  • Not the answer to your question afaik, but if the Window doesn't have focus, you can't expect any keyboard state to change. This is because all the regular ("synchronized") key state access methods give you the key state *as of your application's current message queue processing state*. That means, if your application hasn't seen a WM_KEYDOWN in its message loop, it won't report the key as pressed, even if the key is physically pressed. Exceptions are the `...Async` functions. That doesn't explain your third point though, although I can't reproduce that one either. – dialer Mar 02 '21 at 20:02
  • Hmm interestingly on my system it *sometimes* reports shift in the wParam even though the window doesn't have focus, which it shouldn't (it doesn't report it in GetKeyState). It never reports Ctrl though. That alone is enough evidence for me personally to just never use the wParam tbh. – dialer Mar 02 '21 at 20:09
  • The problem was, using Go, that sometimes my MOUSEMOVE handler ran in parallel trying to update the mouse modifier key states. As soon as I added a locking around that change, things worked. – Robert M. Münch Apr 07 '21 at 18:31

1 Answers1

-1

I believe that if you need to get input when your window isn't in focus you would have to use this:

https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowshookexa?redirectedfrom=MSDN

other than that, if you're just moving the mouse you can assume that the key state hasn't changed, can't you?