tags:

views:

174

answers:

4

Hello,

I want to test left and right buttons of mouse in C++.

I have float variable its value is 100.00f,If I click left button,its value will increase 1.5f.

When I click right button,its value will decrease 1.5f.

How can I do this?

Could you help me please?

Best Regards...

A: 

A quick Google turned up this ?

Dave Tapley
+2  A: 

There is a .NET tag, so I assume we are talking about .NET.

The event you are interested in is MouseClick

Here is a C#(I'm sorry it is not C++) example how to detect which button is pressed

public Form1()
{
    InitializeComponent();
}

private void Form1_MouseClick(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Left)
        yourVar += 1.5;
    else if (e.Button == MouseButtons.Right)
        yourVar -= 1.5;
}
Svetlozar Angelov
A: 

Ok, you'll probably want to handle the mouse button events - to do this I'd refer to plenty of examples on how to do this.

After you've added you mouse button handlers, sometimes it's a good idea to check for whether the user has swapped their mouse buttons - you do this by querying SM_SWAPBUTTON using GetSystemMetrics.

Alan
A: 

How I personally I would do this would be using SFML, since it can very easily handle mouse clicks in the GUI window. Not sure how it would be possible in a command prompt window. But I know you could use SFML to do this using C++.