Is there a way to explain what the actual goal here is in another way? What are you trying to do overall?
And do you want your solution to work just on a console or do you want a window?
PS: I have not used mouse_event before, but from a google search it sounds like it's a very outdated function.
Still not exactly sure what what that means. Do you just want a console window that waits for input and then when it detects particular input combinations, it then simulates a click in another application?
And you want a Left mouse button to cause a click event to happen (but only after previously pressing Left mouse + R?)
To start, if you want to simulate a left click (left mouse down and up events), this will automatically do a double-click on global coordinate (20, 20) of your screen. (So on my Windows machine, it double-clicks and opens the Recycle bin).
#include <iostream>
#include <windows.h>
// Partially copied from http://www.cplusplus.com/forum/lounge/17053/
//
// Desc : Clicks the left mouse button down and releases it.
// Returns : Nothing.
//
void LeftClick()
{
INPUT Input={0}; // Create our input.
Input.type = INPUT_MOUSE; // Let input know we are using the mouse.
Input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN; // We are setting left mouse button down.
SendInput( 1, &Input, sizeof(INPUT) ); // Send the input.
ZeroMemory(&Input,sizeof(INPUT)); // Fills a block of memory with zeros.
Input.type = INPUT_MOUSE; // Let input know we are using the mouse.
Input.mi.dwFlags = MOUSEEVENTF_LEFTUP; // We are setting left mouse button up.
SendInput( 1, &Input, sizeof(INPUT) ); // Send the input.
}
//
// Desc : Gets the cursors current position on the screen.
// Returns : The mouses current on screen position.
// Info : Used a static POINT, as sometimes it would return trash values
//
POINT GetMousePosition()
{
static POINT m;
POINT mouse;
GetCursorPos(&mouse);
m.x = mouse.x;
m.y = mouse.y;
return m;
}
//
// Desc : Sets the cursors position to the point you enter (POINT& mp).
// Returns : Nothing.
//
void SetMousePosition(POINT& mp)
{
long fScreenWidth = GetSystemMetrics( SM_CXSCREEN ) - 1;
long fScreenHeight = GetSystemMetrics( SM_CYSCREEN ) - 1;
// http://msdn.microsoft.com/en-us/library/ms646260(VS.85).aspx
// If MOUSEEVENTF_ABSOLUTE value is specified, dx and dy contain normalized absolute coordinates between 0 and 65,535.
// The event procedure maps these coordinates onto the display surface.
// Coordinate (0,0) maps onto the upper-left corner of the display surface, (65535,65535) maps onto the lower-right corner.
float fx = mp.x * ( 65535.0f / fScreenWidth );
float fy = mp.y * ( 65535.0f / fScreenHeight );
INPUT Input = { 0 };
Input.type = INPUT_MOUSE;
Input.mi.dwFlags = MOUSEEVENTF_MOVE|MOUSEEVENTF_ABSOLUTE;
Input.mi.dx = (long)fx;
Input.mi.dy = (long)fy;
SendInput(1, &Input,sizeof(INPUT));
}
int main()
{
POINT point;
point.x = 20;
point.y = 20;
SetMousePosition(point);
// double click
LeftClick();
LeftClick();
}
For your purposes, the above code probably has to be combined with some button-handling logic from your post.
I want an app what works in background, and when I toggling bool (press LMB and R) that will spam LMB (bool active - holding only LMB, released R), while LMB released (bool disabled) will not clicking.
It does not matter if it will click in the Minecraft window or globally.
But you will just create confusion if you continue to write windows code.
As far as I understand it, one writes everything with Qt classes and functions, no need to write any windows code at all. And Qt does have functions and classes for everything, even to the point of using QString rather than std::string.
As long as you understand that those two things are completely different. And it will be probably be easier in Qt, in the same way that .NET is easier than Win32.