Trying to recover from enhancement software that generates fake input incorrectly


A customer had a program that supported the mouse wheel, and they found that some laptops have trackpad enhancement software which supports a gesture for turning the mouse wheel. When the enhancement software recognizes the gesture, it sends a WM_MOUSE­WHEEL message to the foreground window.. This causes problems for the program because there are various things that are not allowed when processing an inbound sent message. Fortunately, they can detect whether they are in this situation, but it's not clear how they can recover from it. "We have been brainstorming and thinking that if we see this problem, we will use Post­Message to put the message 'back' into our queue."

The trackpad software is supposed to be using Send­Input so that the wheel message orders correctly with the other messages in your input queue. The Send­Message delivers the message immediately (or as immediately as possible), and messages posted with the Post­Message function are processed ahead of input, both of which are wrong when you are trying to simulate input. Even your attempt to delay processing by calling Post­Message won't help because posted messages are processed ahead of input.

Here's a diagram which is inaccurate but may help to get the point across:

Inbound sent messages
SendMessage inserts messages here
Inbound posted messages
PostMessage inserts messages here
Inbound input messages
SendInput inserts messages here

Basically, the enhancement software already screwed you with respect to message ordering. You won't be able to make a perfect recovery; all you can do is try to make the best of a bad situation.

One idea is to use the Reply­Message function in your message handler. The Reply­Message function says, "Hey, like, act like I returned from this message for the purpose of inter-thread Send­Message bookkeeping, such as unblocking the sender, but let me keep running anyway." This may be enough to get the parts of the system that normally say "No, you can't do that from inside a sent message" to realize "Oh, wait, the synchronous part is over. Carry on."

If that doesn't work, then you can use the Send­Input message to generate a wheel message back into the input queue. The wheel input will be a bit late (by the amount of time it took your window procedure to receive the message), but it'll probably be close enough to correct that most people won't notice. There's most likely already a lag in the gesture recognition in the enhancement software, so a little more lag probably isn't the end of the world.

Comments (7)
  1. DWalker says:

    And, I hope Microsoft offered to "coach" the developers of the trackpad software in the best way to do things. Most trackpads seem to be made by the same company, so if they do it right, that will have good effects across the whole laptop industry.

    1. Martin Bonner says:

      I suspect that the basic trackpad software is OK. It's some whizzy enhancement built on top of the trackpad software by a specific laptop manufacturer that is causing the grief. ICBW

      1. Based on my own experimentation with customizing my laptop's trackpad behaviour, the enhancement software is likely still provided by the trackpad vendor, and then customized by the laptop manufacturer. So the basic functionality (like scroll emulation) is probably shared.

        However, there's still a problem in that laptop manufacturers are not the most diligent in releasing updates for their customized enhancement programs, so fixing the problem would likely not fix it for existing laptops.

        1. smf says:

          I'm not entirely sure how much of it is actually ever customized by the laptop manufacturer. I thought my realtek audio drivers were modified by my laptop manufacturer, until I downloaded the generic ones from realtek and it detected the manufacturer and provided the appropriate skin. I think the manufacturers often say that the laptop manufacturers modify it, just so they don't have to offer end user support.

  2. David H says:

    Man. I hate trackpad software. It is all terrible. Mine feels the need to draw an icon underneath the mouse cursor to tell me that I'm scrolling (because a window actively scrolling isn't enough of an indicator)

    This causes problems with focus-follows-mouse enabled, as the icon underneath the mouse cursor gets focus. Sometimes, this crashes the helper program.

    Grrr...

  3. alegr1 says:

    Microsoft could not even make their Microsoft Intellipoint software play nice with Microsoft Internet Explorer. Search for "intellipoint scroll too fast problem". I still won't install Intellipoint from Windows update because of that.

  4. Scarlet Manuka says:

    Hooray for vendor enhancements! It seems the hardware enhancement programs are just as "useful" as all the other lovely additional software that comes with a typical OEM installation. Clean installs for me, thank you very much.

Comments are closed.

Skip to main content