Did you search the forum before asking this question? It has been asked and answered a number of times already.
Well wysota, I came to figure out that direct research on the forum is normally helpless, so normally I don't do the research anymore, but when I type the title to the new thread, the forum automatically selects 3 probable related posts, and than I look them. But this time, nothing appeared, so I move on to write and publish the thread.
This has nothing to do with Qt.
Well, I guess that since I was developing the software in Qt and wanted to use Qt functions (such as QWidget::mouseMoveEvent), my doubt would have something to do with Qt... (even if, after all, in order to capture the events while the software is running in background, I would have to use some Windows functions).
Here is a sample project which is doing hooking.
Hmm, I'm not sure it will work, since it's in C#. And I gave a look to the "Browse Code", and it looks that this is not the sort of solution that is aplicable.
Thanks for it, anyway!
Added after 1 9 minutes:
Well, as I sad; I did a research in the forum and found nothing practically useful.
Anyway, I was able to do what I wanted, though not as I expected. The only thing usefull I found in the research was a thread where wysota, I think, explained that by using Qt functions to catch a mouse or keyboard event I would be able to figure out changins in other softwares, because of the specific relathionship between the OS and the application in how on passes a mouse or keyboard event to the other. So that convinced me that I would find what I wanted using only windows functions.
So here is the resultant code:
//.h
POINT pwx;
unsigned int usage_count;
bool flag_reset;
//constructor
usage_count = 0;
flag_reset = false;
GetCursorPos(&pwx);
mouseMovement
= new QTimer(this);
connect(mouseMovement,SIGNAL(timeout()),this,SLOT(onMouseMovement()));
mouseMovement->start(1000); //Um seg
//function conected to QTimer
void MainWindow::onMouseMovement()
{
POINT pwx2;
GetCursorPos(&pwx2);
if (pwx.x != pwx2.x || pwx.y != pwx2.y)
{
pwx.x = pwx2.x;
pwx.y = pwx2.y;
usage_count = 0;
flag_reset = false;
}
else
{
usage_count++;
if (usage_count >= 10)
flag_reset = true; //10 seconds passed without any mouse event happening. Can move on.
}
}
//.h
POINT pwx;
unsigned int usage_count;
bool flag_reset;
//constructor
usage_count = 0;
flag_reset = false;
GetCursorPos(&pwx);
mouseMovement = new QTimer(this);
connect(mouseMovement,SIGNAL(timeout()),this,SLOT(onMouseMovement()));
mouseMovement->start(1000); //Um seg
//function conected to QTimer
void MainWindow::onMouseMovement()
{
POINT pwx2;
GetCursorPos(&pwx2);
if (pwx.x != pwx2.x || pwx.y != pwx2.y)
{
pwx.x = pwx2.x;
pwx.y = pwx2.y;
usage_count = 0;
flag_reset = false;
}
else
{
usage_count++;
if (usage_count >= 10)
flag_reset = true; //10 seconds passed without any mouse event happening. Can move on.
}
}
To copy to clipboard, switch view to plain text mode
Now there is the keyboard lacking.
Bookmarks