How to prevent mouse click event on Windows - windows

I record the mouse events on windows by using robotgo package. Package provides to get bitmap of clicked area but the latency of having bitmap is super sensitive situation here.
For example:
If I click any checkbox which is unchecked on the screen, provided bitmap must contains the state of unchecked but it provides me checked state and cannot simulate it with robotgo or cannot trigger click by using bitmap.
Solution to this scenario is that I need to prevent windows mouse click event until bitmap provided by the package (or adding some delay for click event) then trigger the click event on windows.
I made some research online but couldn't find a proper solution. How prevent click event on Windows in Go? Is it possible or is there any other way to make it happen?

A low-level mouse hook can eat mouse events. SendInput can generate mouse input events.
You would have to set a flag somewhere so you don't eat your own fake input events.
Keep in mind that SendInput is not perfect (can be detected by other hooks) and playing with the input system like this is usually not the best solution. Adding 500ms (or some other delay) to every mouse click is going to be very annoying for your users.
It is better to use UI Automation to get information about UI element states in other applications...

Related

Simulate mouse hover in windows application using win32 api

With a game application (may have been minimized or hidden), I have a button that only shows up when I hover over it. I need to write an script (by c# or python) that can click that button without moving my cursor. I was able to simulate click event with SendMessage(hWnd, WM_LBUTTONDOWN, ...), but i don't know how to make that button show up.
I have seen a tool that can do it, I don't know how they do it.
My problem seems similar to this problem.
I won't need SendInput or mouse_event because it will move my cursor.
Any one can help? Is there another unrelated way?

Is it possible to suppress single-click events during a double-click?

Our application supports single click and double-click events on a window which do different things. However we always get a single-click event during the double-click which causes undesired effects.
Our application is in Qt but really this is a question about underlying Windows/Mac APIs - is this a fundamental detail that the OS detects a single click as soon as you lift your finger since it can't possibly know you are going to click a second time, or can it be prevented?
If it can't be prevented, is their an accepted best practice how to handle it?
Start a timer when you get WM_LBUTTONDOWN (or Qt equivalent). If you get WM_LBUTTONDBLCLK (or Qt equivalent) before the timer expires, cancel the timer and execute your double-click action. Otherwise, when the timer expires, execute your single-click event.
On Windows, you can get the double-click time using GetDoubleClickTime().
That's about the best you can do - you can't prevent the single click message being generated in the first place on either platform.

VC++ mouse events

I want to write a console program for mouse events (Only mouse scroll). How do I do it in VC++? The application will listen only to scroll events.
Description: If the user scrolls down, the Desktop window fades down, and fades-in when user scrolls up.
Here I just need to know to to listen to mouse events in console app.
Note: I am developing using win32 API, and for development environment I am using VS2010.
I've never actually done this myself. It seems that a console application responding to mouse events almost belies its nature and intended purpose. Generally, you would only need to respond to keyboard input from a console app and leave the mouse stuff to a GUI app.
That being said, this tutorial indicates that it is in fact possible to capture these mouse events from a Win32 console application. Generally, the suggestion is to use the ReadConsoleInput function and extract the information of interest from the INPUT_RECORD structure that it fills. The only tricky thing is that the call to ReadConsoleInput is a blocking call, which means it will not return until there is an input event fired. You'll need to structure your application's code accordingly. Mouse events are covered in detail about 3/4 of the way down the page.

The "Default Zoom Level" Mouse Button

Many mice and keyboards have "zoom" buttons on them. These almost always generate Ctrl+Mouse Wheel messages to the applications, so they are easily accounted for by us programmers.
But my current Logitech mouse has an additional feature. The zoom wheel indeed sends Ctrl+Mouse Wheel messages when scrolled (or, actually, tilted), but when I depress the zoom wheel, most programs restore the zoom level to the default, i.e. 100 %. What kind of message does the mouse send to the application in this case? I cannot find a suitable virtual key code for it.
I should probably say that I have tried to capture this event. In my Delphi application, I wrote handlers for the KeyDown, MouseDown, and MouseWheel events, but non of them are triggered by this mysterious button.
Applications that support this button:
Google Chrome 5.0.375.127
Microsoft Word 2010
Applications that seem not to support this button:
Microsoft WordPad in Windows 7
Microsoft Paint in Windows 7
There is no dedicated shortcut key-stroke or Windows message. Odds are pretty good that the mouse helper has specific awareness of the process that has the focus. And generates the specific command that this program needs to reset the zoom, possibly a WM_COMMAND message. Use a tool like Microsoft's Spy++ to see what messages are generated, if any.
I have a Logitech M570 and downloaded 'set point'.
Not all mice / trackballs have this feature, dead giveaway is having a 'forward / back' button on your mouse or trackball. If you can get 'set point', there are programmable button / wheel options.
find your mouse or trackball on their product page, then, > support > (your mouse), > downloads
If your device can use 'set point', see download button window on the left, insure your Windows version.
Select 'set point'
at the bottom of the window, hit download, go through wizard steps. Download may be fast or take a while.
If it looks like it successfully downloaded, > control panel > mouse. You will see 'mouse properties', look for set point tab.
Try programming 'ctrl' on your 'depress' mouse wheel or 'tilt' button.
I'm a writer, I love my M570 wireless trackball!

Cocoa accessibility API, can I click a window in the background without activating it?

I've been searching forever for a solution to this, so I thought I'd seek out the brainpower of greater minds than mine. I'm developing a Cocoa app that uses the Accessibility API to manipulate another program (it's a hotkey app). The app I'm controlling typically has multiple windows open, with some hidden behind others. What I would like to do, if it's possible, is to send mouse events to windows using the Accessibility API in a way that presses a button in the window without bringing it to the foreground (interact with the window but don't activate it). The reason I'm trying to do this is that sending the mouse event to this other window will force it to the foreground and disrupt the user's interaction with the foremost window.
This is possible on Windows - apparently, because apps similar to mine do it there - but I'm getting the feeling that this isn't possible with Cocoa, given the way the window manager works. Am I mistaken?
Accessibility is higher-level than that. You send, for example, AXPress actions to AXButton objects, but “press” is not necessarily a click—pressing the space bar while a view is focused, for example, is also a “press”. AXPress is a high-level action that means “do your thing”, which obviously has meaning for some views (such as buttons) and not others (such as fields).
Accessibility activating the application does make sense when you look at it from its intended purpose: Assistive devices for disabled users. If the user “presses” something by whatever means, they probably intend to activate the application and work in it.
Quartz Event Services will get you almost there: You can create an event tap for the process you want to control, and you can forge events and send them to a tap. The catch is that you can only send events to a tap when the tap fires—i.e., when the application already has an event to deal with. When it doesn't, you're stuck.

Resources