CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Hybrid View

  1. #1
    Join Date
    May 2009
    Posts
    14

    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.

  2. #2
    Join Date
    Feb 2009
    Location
    India
    Posts
    444

    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)
    «_Superman
    I love work. It gives me something to do between weekends.

    Microsoft MVP (Visual C++)

  3. #3
    Join Date
    May 2009
    Posts
    14

    Talking 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.

  4. #4
    Join Date
    May 2009
    Posts
    14

    Unhappy Re: Check if mouse was pressed

    Some help?

  5. #5
    Join Date
    Feb 2009
    Location
    India
    Posts
    444

    Re: Check if mouse was pressed

    I think you should use the debugger to find the problem.
    «_Superman
    I love work. It gives me something to do between weekends.

    Microsoft MVP (Visual C++)

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
  •  





Click Here to Expand Forum to Full Width

Featured