Hey, could I have a little help please. What I'm trying to do is display a message if the user clicks their mouse, I have:

int main()
{
   
    mouse_event(MOUSEEVENTF_LEFTDOWN, x, y,0,0);
}

How would I get it to display a message? I'm thinking an if statement but dunno.. Help please :( thanks

mouse_event is used to emulate mouse events, not to detect them. If you want to be able to detect mouse clicks anywhere (even if your window doesn't have focus), you will have to use something like windows hooks. If your using the Windows API and just want to be able to detect a mouse click within your window, you can start with a Win32 Tutorial - then try and understand Windows Procedures. However, to do this in a console window, it's a little different, here's an example:

#include <windows.h>
#include <iostream>

int main()
{
  HANDLE hStdin; 
  DWORD cNumRead; 
  INPUT_RECORD irInBuf[1];

  if ( HANDLE(hStdin = GetStdHandle( STD_INPUT_HANDLE )) == INVALID_HANDLE_VALUE )
    return 1;

  while ( true )  { 
    if (! ReadConsoleInput( hStdin, irInBuf, 1, &cNumRead) )
      return 1;

    for (DWORD i = 0; i < cNumRead; ++i)
      if ( irInBuf[i].EventType == MOUSE_EVENT &&
           irInBuf[i].Event.MouseEvent.dwEventFlags != MOUSE_MOVED ) {
        if ( irInBuf[i].Event.MouseEvent.dwButtonState & FROM_LEFT_1ST_BUTTON_PRESSED ) {
          std::cout << "Left Click.\n";
        }
      }
  }

  return 0;
}

Sorry for the uncommented code, but either way, I think that is a little advanced for your level of programming.

Hope this helps.

Are you trying to say something there? :P lol

Eeek, the problem I am having now is I want to implement it into my own scripting language, think it would be hard? Thanks very much btw :) I am getting there.

Well, I was just judging your programming skills by how clueless you seemed to be in your question :icon_cheesygrin:
And yes, I think you will find it a little hard to implement in your own scripting language... but good luck :-)

Hey lol :') I beg to differ and yeah, it's going good actually! The only problem that I am having is the return 1; part.

1..nah..0 is good..

Returning 1 (or some value > 0) is a common way of reporting that the program did not execute correctly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.