Capturing a mouse click?

This is a discussion on Capturing a mouse click? within the C++ Programming forums, part of the General Programming Boards category; Scratch that, I edited my code, it is now proporely: Code: #include <iostream> #include <windows.h> using namespace std; int main() ...

  1. #1
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379

    Capturing a mouse click?

    Scratch that, I edited my code, it is now proporely:

    Code:
    #include <iostream>
    #include <windows.h>
    using namespace std;
    
    int main() {
     POINT a;
     POINT *b;
     int c=1;
     
     b=&a;
     GetCursorPos(b);
     while(c=1)
      if(!WM_RBUTTONDOWN)
       c=0;
      
     cout << a.x << " " << a.y;
    }
    Doesnt work, not sure why... Anyone got some ideas?

    I'm using WinXP Borland C++ Free Command Line Compiler.
    Last edited by Blackroot; 01-08-2006 at 04:22 AM.
    Code:
    Error W8057 C:\\Life.cpp: Invalid number of arguments in function run(Brain *)

  2. #2
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    287
    I think that the window messages (WM_...) only can be used like that after the message processing, so you shold use them in an application window; maybe you can find a way to get the messages from the console, process them and receive the results into a 'simil like' main procedure. If I'm not in error, WM_RBUTTONDOWN is one of the results of a message processing. once I found on the net a sample of mouse routines for non-window applications, but I can't remember where I foud that. maybe you can get a help from some game library, them usually have such rutines.
    niara

  3. #3
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379
    Ah, thank you for telling me that, it was driving me nuts!

    Well does anyone know of the correct function to find if a mouse button is down for the console?
    Code:
    Error W8057 C:\\Life.cpp: Invalid number of arguments in function run(Brain *)

  4. #4
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379
    I went poking around the web for about seven hours, and found some code that detects console button presses. Oddly enough, it doesnt work proporely. Because the code wasnt specificaly related to mouse clicking, I'm not sure if I copied the code correctly. I altered it a bit, looked up some other stuff, but I cant find anything else.

    Well, heres my newely revised code:

    Code:
    #include <iostream.h>
    #include <windows.h>
    #include <conio.h>
    using namespace std;
    
    int main() {
     INPUT_RECORD rec;
     DWORD evk;
     HANDLE hIn = GetStdHandle(STD_INPUT_HANDLE);
     int x_pos, y_pos;
    
     SetConsoleMode(hIn, ENABLE_MOUSE_INPUT);
     for(;;) {
      ReadConsoleInput(hIn, &rec, 1, &evk);
      if(rec.EventType == MOUSE_EVENT)
       if(rec.Event.MouseEvent.dwButtonState != FROM_LEFT_1ST_BUTTON_PRESSED) {
        x_pos = rec.Event.MouseEvent.dwMousePosition.X;
        y_pos = rec.Event.MouseEvent.dwMousePosition.Y;
        break;
      }
     }
     cout << x_pos << " " << y_pos;
    }
    For some reason, this sets off whenever you move your mouse on the console... Hmmm... Anyone?
    Last edited by Blackroot; 01-08-2006 at 07:22 AM.
    Code:
    Error W8057 C:\\Life.cpp: Invalid number of arguments in function run(Brain *)

  5. #5
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    287
    and what has happened with the loop???
    Code:
    #include <iostream.h>
    #include <windows.h>
    #include <conio.h>
    #include <stdlib.h>
    using namespace std;
    bool ok=true;
    
    int main()
     {
     INPUT_RECORD rec;
     DWORD evk;
     HANDLE hIn = GetStdHandle(STD_INPUT_HANDLE);
     int x_pos, y_pos;
     
     while(ok)
         {
         SetConsoleMode(hIn, ENABLE_MOUSE_INPUT);
         for(;;)
             {
             ReadConsoleInput(hIn, &rec, 1, &evk);
             if(rec.EventType == MOUSE_EVENT)
                 {
                 if(rec.Event.MouseEvent.dwButtonState != FROM_LEFT_1ST_BUTTON_PRESSED)
                     {
                     x_pos = rec.Event.MouseEvent.dwMousePosition.X;
                     y_pos = rec.Event.MouseEvent.dwMousePosition.Y;
                     break;
                     }
                 }
             }
         system("cls");
         cout << x_pos << " " << y_pos;
         }
    }
    I know that's a ugly implementation, only to see how that works
    I wasn't referring to those rutines to work with the console mode and windows, I think that the rutines I was talking about was to get some interrupts from the system (I'm not sure about that, but I think that was it). for the moment works with those win32 api console functions.
    niara

  6. #6
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379
    Ah, thank you very much for that, you saved my program with that!
    Code:
    Error W8057 C:\\Life.cpp: Invalid number of arguments in function run(Brain *)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 03-23-2006, 07:08 AM
  2. Using mouse click
    By kakashi in forum C++ Programming
    Replies: 10
    Last Post: 01-31-2006, 01:38 AM
  3. capturing mouse events
    By leojose in forum Windows Programming
    Replies: 7
    Last Post: 06-06-2005, 11:36 PM
  4. Making a Mouse Click
    By r0ss in forum C Programming
    Replies: 1
    Last Post: 06-03-2004, 09:55 PM
  5. mouse click coords and moving a rect
    By techrolla in forum Windows Programming
    Replies: 1
    Last Post: 03-07-2004, 09:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21