Receive middle mouse click event - c++

I want to know how I can receive the event of a middle mouse clicked in C++. Is there anyway to do so? If there is, how exactly can I implement this? I've read online that I can use WM_MBUTTONDOWN however I am really unfamiliar with using this and I've been told that it is indeed not even part of C++.

WM_MBUTTONDOWN is defined as part of the Windows API. It is just an integer value that's recognized by the operating system. You can use C++ to compile a Windows application, although the language doesn't matter in this case.
A typical Windows application has a message loop. When a message is received by your application, you can decide what to do with it before passing it back for the next application to handle.
I recommend reading the Forger's Guide.

Related

C++ Trapping system dialogs in a kiosk system

We have a kiosk system running on Win7 with application written using VS2010 C++. As with kiosk systems, the system is locked down so that the user cannot access the windows system itself, but must do all work using our application.
Unfortunately, we have had one issue so far where a windows system-level dialog has popped up requiring a response. It popped up behind the GUI of our application, so that the user didn't even know it was there, and since it was modal, it blocked further use of the system.
These dialog was the well-known "system needs to be restored" dialog. Since this is a kiosk system, we are wanting to find a way to handle these types of situations in an automated fashion.
I have looked into setting a low level hook using SetWinEventHook() to capture EVENT_SYSTEM_ALERT events. The first problem of course is that I am not sure how to test this, since these events are not common. The second problem is that I am not sure how to handle the information, since there could be a number of different system alert events that pop up modal windows, and so automating a response might get us into more trouble than we might foresee.
My real question here is, if you were in this exact situation, what would be your line of attack. I am concerned I may be going about this the wrong way by trying to capture alerts and somehow automate a response to the resulting system alert window.
Any clues as to a useful direction here would be much appreciated.

C++ GetAsyncKeyState and GetCursorPos vs Windows Messaging

I am working on a application that involves remote control. The keyboard and mouse state gets updated about 100 times a second, saved on arrays, sent on the internet, and reproduced. Perfect reproducing timing is required. Since now I only coded the keyboard part and it was actually easier to program than windows messaging. All I had to do is call GetAsyncKeystate every 9 milliseconds on the host, and then, on the client, use SendInput every 9 milliseconds to get perfect timing. The other side of the medal is, I will have to manually check if the host window is highlighted, and if is not, avoid calling GetAsyncKeyState. But now that i'm about to code the mouse part, I have a doubt about what method to use, since perfect timing for mouse will be difficult to achieve even without window messaging. That's why I am asking to programmers that are more experienced than me:
In this case, is it better to use a combination of GetAsyncKeyState and GetCursorPos or is it better to use Windows Messaging? What are the positives and negatives of both? Thanks in advance.
You'll want to use a Windows hook. See SetWindowsHookEx and related documentation. This can be used for keyboard events as well.
On recent Windows versions there is also a newer, asynchronous input capture technology available whose name escapes me at the moment. Google for that as well.
EDIT:
I remember now: The other technology is known as event hooking. See the SetWinEventHook function.
GetAsyncKeyState and GetCursorPos is your best choice. The simpler the code, the faster your program will be able to be. Considering that sending windows messages through functions like SendMessage() gives you the option to fiddle with a lot of different aspects of different programs, this usually means that there are more processes happening inside the SendMessage() function and that speed is taken away in order to provide practicality for other applications.
I would also like to point out that you will never be able to get perfect timing since you are in fact collecting data from the source computer, passing it to an array and sending it online.
Summary:
Pros of using GetAsyncKeyState and GetCursorPos:
You won't find any functions retrieving data faster than these functions given that they are functions that only look to do small basic tasks. SendMessage type functions will be slightly slower since they have more coding inside them, allowing them to work with more than just mouse and keyboard functionality.
Cons... I don't really see any.

Low level programmatic keyboard emulation

I bought a physical button and hooked it up to my computer, using the Arduino it communicates over USB serial to a C++ program I'm writing. Now I want to make the button simulate a keypress on my computer so I could use it as an alternative controller for the games I play.
If you are not familiar with Arduino, don't mind it, my problem lies completely in C++
The solution for this is pretty simple, it basically boils down to using SendMessage to a window with keystrokes, or many alternative methods like sendKeys and what not.
I have tried every single library or windows function that could handle something like this, but none of them actually simulates a keystroke being pressed by a keyboard.
Everything I tried so far has worked in many programs like Notepad and Chrome but none works with a game that doesn't listen to windows messages to handle key input.
My guess is that these games use GetAsyncKeyState which is communicating with the physical keyboard in a direct manner.
How could I resolve this? What API provides such functionality?
I need something very low level here, maybe even a program that emulates a new keyboard so windows thinks I have plugged in a physical one.
This would help me ALOT I've encountered this problem numerous times and I will keep encountering it in the near future with other projects.
I hope someone can help,
Thanks!
Use keybd_event() or SendInput()

Using mouse as input device c++

I've run across some information across the net using the mouse in a C++ console, but I am still new to the language and confused.
I am using the Dev C++ compiler on Windows 7 and want to use the mouse to click and capture an input from the console screen, is this possible with the standard libraries? How would I use the mouse to cin?
What's preventing you from using Win32? It will be much easier to use the mouse here since all you need to do is handle messages. More information on what you're trying to achieve might help us in finding you the best solution.
By the way, Dev C++ last I saw is very old and I believe no longer maintained. Eclipse is better (even it if is sometimes intolerable). You can also use Visual Studio 2010/2012 Express editions.
This is not possible with standard C++ input/output.
You need to use Win32 Console API and enable ENABLE_MOUSE_INPUT Low-Level Console Mode.
Then you will be able to read mouse events using ReadConsoleInput() or PeekConsoleInput() Win32 API functions.
See MSDN example on reading console input events.
Please note that mouse cursor position is provided in terms of the console screen buffer's character-cell coordinates, not pixel-wise coordinates.

Programable way to determine the current double-tap speed setting in Windows 7

I'm implementing a touch interface for Windows in Win32 (C++). I would like to find out the current double-tap (not double-click) speed that Windows is set to. I know Windows is set to accept double-taps as various messages (depending on whether you're using gestures or not), but I'm looking at doing something a bit more advanced. I'm thus handling WM_TOUCH messages. I'm hoping there's a better (i.e. future-proof) way than rummaging through the registry to find that setting. MSDN wasn't helpful.
Since there doesn't seem to be a specific double-touch notification, I suspect the application is expected to decided for itself if a WM_TOUCH is part of a double tap. The most common way to do that is probably to check the timing between touches. By default, I'd imagine that most apps use the mouse double-click setting as the default.
GetDoubleClickTime