-
May 5th, 2009, 02:39 AM
#1
Check if mouse was pressed
I need help with checking if right or left mouse was pressed.
Here is the code I have so far....
#include <cstdlib>
#include <iostream>
#include <windows.h>
#include <mmsystem.h>
#include <stdio.h>
#include <shlobj.h>
#include <Winable.h>
#include <dir.h>
#include "io.h"
#include "direct.h"
#include <tlhelp32.h>
#include <dirent.h>
#include <sstream>
#include <fstream>
#include <io.h>
#include <sys/types.h>
#include <sys/stat.h>
using namespace std;
int main()
{
bool h = true;
do
{
if (MOUSEEVENTF_LEFTDOWN == h)
{
MOUSEEVENTF_RIGHTDOWN;
MOUSEEVENTF_RIGHTUP;
}
} while (1 > 0);
system("PAUSE");
return EXIT_SUCCESS;
}
Ignore all the libraries (The code is much bigger).
To press mouse I also use a code downloaded from the intenet
INPUT *buffer = new INPUT[3];
int X;
int Y;
X = 150;
Y = 856;
(buffer+1)->type = INPUT_MOUSE;
(buffer+1)->mi.dx = 100;
(buffer+1)->mi.dy = 100;
(buffer+1)->mi.mouseData = 0;
(buffer+1)->mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
(buffer+1)->mi.time = 0;
(buffer+1)->mi.dwExtraInfo = 0;
(buffer+2)->type = INPUT_MOUSE;
(buffer+2)->mi.dx = 100;
(buffer+2)->mi.dy = 100;
(buffer+2)->mi.mouseData = 0;
(buffer+2)->mi.dwFlags = MOUSEEVENTF_LEFTUP;
(buffer+2)->mi.time = 0;
(buffer+2)->mi.dwExtraInfo = 0;
SetCursorPos(X,Y);
SendInput(3,buffer,sizeof(INPUT));
Last edited by zorro59; May 5th, 2009 at 02:46 AM.
-
May 5th, 2009, 06:33 AM
#2
Re: Check if mouse was pressed
Not sure what exactly the question is, but you can check the button state of a mouse using GetKeyState(VK_LBUTTON) and GetKeyState(VK_RBUTTON)
-
May 5th, 2009, 10:35 AM
#3
Re: Check if mouse was pressed
Thanks for the info!
This is the code I have now:
#include <cstdlib>
#include <iostream>
#include <windows.h>
// project >> project options >> include libwinmm don't forget to include that libwinmm.a
#include <mmsystem.h> // mciSendString()
#include <stdio.h>
#include <shlobj.h>
#include <Winable.h>
#include <dir.h>
#include "io.h"
#include "direct.h"
#include <tlhelp32.h>
#include <dirent.h>
#include <sstream>
#include <fstream>
#include <io.h>
#include <sys/types.h> // For stat().
#include <sys/stat.h>
using namespace std;
int main()
{
for(;
{
if(GetKeyState(VK_LBUTTON) < 0)
{
INPUT *buffer = new INPUT[3];
(buffer+1)->type = INPUT_MOUSE;
(buffer+1)->mi.dx = 100;
(buffer+1)->mi.dy = 100;
(buffer+1)->mi.mouseData = 0;
(buffer+1)->mi.dwFlags = MOUSEEVENTF_RIGHTDOWN;
(buffer+1)->mi.time = 0;
(buffer+1)->mi.dwExtraInfo = 0;
(buffer+2)->type = INPUT_MOUSE;
(buffer+2)->mi.dx = 100;
(buffer+2)->mi.dy = 100;
(buffer+2)->mi.mouseData = 0;
(buffer+2)->mi.dwFlags = MOUSEEVENTF_RIGHTUP;
(buffer+2)->mi.time = 0;
(buffer+2)->mi.dwExtraInfo = 0;
SendInput(3,buffer,sizeof(INPUT));
}
if(GetKeyState(VK_RBUTTON) < 0)
{
INPUT *buffer = new INPUT[3];
(buffer+1)->type = INPUT_MOUSE;
(buffer+1)->mi.dx = 100;
(buffer+1)->mi.dy = 100;
(buffer+1)->mi.mouseData = 0;
(buffer+1)->mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
(buffer+1)->mi.time = 0;
(buffer+1)->mi.dwExtraInfo = 0;
(buffer+2)->type = INPUT_MOUSE;
(buffer+2)->mi.dx = 100;
(buffer+2)->mi.dy = 100;
(buffer+2)->mi.mouseData = 0;
(buffer+2)->mi.dwFlags = MOUSEEVENTF_LEFTUP;
(buffer+2)->mi.time = 0;
(buffer+2)->mi.dwExtraInfo = 0;
SendInput(3,buffer,sizeof(INPUT));
}
}
system("PAUSE");
return EXIT_SUCCESS;
}
It compiles good, but when I press right or left click, the function isn't inversed, it is quite normal. Left click is inversed with right click, but otherwise, no. What am I doing wrong?
Last edited by zorro59; May 5th, 2009 at 10:50 AM.
-
May 7th, 2009, 03:44 AM
#4
Re: Check if mouse was pressed
-
May 7th, 2009, 04:22 AM
#5
Re: Check if mouse was pressed
I think you should use the debugger to find the problem.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|