Mouse Input Coordinates Not Being Read in C++

Please take a look the code below, its not the complete thing obviously since that'd be too long.

Essentially the problem is that when I click the mouse, the program doesn't seem to record the coordinates. So the if statements are never executed. The problem could also be with the if statements, I'm not sure.

One thing I noticed was that when the do while loop is running and the left mouse button is not pressed then X and Y of dwMousePosition are both 0. But then if I press the left mouse button then the coordinates become x = 1 and y = 0.

Any help is appreciated

NOTE I'm on Windows 7, 64 bit, using Visual Studio Express 2013 for Windows Desktop


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <windows.h>
#include <string>
#include <new>
#include <stdio.h>

using namespace std;    

INPUT_RECORD ir[128];                                            
DWORD nRead;                                                      
COORD pos;
UINT z;
POINTER_INFO pointerInfo = {};
POINT p;

HANDLE hStdInput = GetStdHandle(STD_INPUT_HANDLE);
HANDLE hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
HANDLE hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);                  
HANDLE handles[2] = { hEvent, hStdInput };

FlushConsoleInputBuffer(hStdInput);

do
{
    Sleep(1);
    if (!wait_for_up)
    {
        if ((GetKeyState(VK_LBUTTON) & 0x100) != 0)
        {
            ReadConsoleInput(hStdInput, ir, 128, &nRead);
            pos.X = 0, pos.Y = 0;
            SetConsoleCursorPosition(hStdOutput, pos);
            if (*login == false)
            {
                if ((ir[z].Event.MouseEvent.dwMousePosition.Y) == 3)
                {
                    *choice = 1;
                    finished = true;
                }
                if ((ir[z].Event.MouseEvent.dwMousePosition.Y) == 4)
                {
                    *choice = 2;
                    finished = true;
                }
            }
        }
    }
} while (!finished);

cout << *choice;
Last edited on
What about z? Is it set somewhere or left uninitialized?
Topic archived. No new replies allowed.