Get the mouse click when you click on the console

-1

I'm in a school project, I need to get the click when I hit the console. Where you press save the coordinates X, Y and put them in void GotoXY(int x, int y); for the program to continue printing at that point. Then wait for another point to start the cycle again.

Is there a method type GetCursorPosition(); ?

Although it is generated as gotoxy.

Edit:

I have this

BOOL WINAPI GetConsoleScreenBufferInfo(
  _In_  HANDLE                      hConsoleOutput,
  _Out_ PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo
);

int main(){
    int r = 0;
    int i = 0;
    int j = 0;
    int vuelta = 0;
    int sleep = 50;

    while(true){
        if(vuelta!=1){
            irA(i,j);
            r = rand()%11+1;
            pon_color(r);
            printf("Jose ");
            Sleep(100);
            //j = j+1; //esto mueve izquierda o derecha
            i = i+1; //esto mueve arriba o abajo
            if(i==25)
                vuelta = 1;

            irA(lpConsoleScreenBufferInfor.x, lpConsoleScreenBufferInfor.y);

    }

but it does not work for me, it gives me this error:

  

name colors.cpp [Warning] 'BOOL GetConsoleScreenBufferInfo (HANDLE,   PCONSOLE_SCREEN_BUFFER_INFO) 'redeclared without dllimport attribute:   previous dllimport ignored [-Wattributes]

    
asked by Jose Luis 20.02.2018 в 19:40
source

2 answers

0

The function is:

BOOL WINAPI GetConsoleScreenBufferInfo(
  _In_  HANDLE                      hConsoleOutput,
  _Out_ PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo
);

Where:

  

hConsoleOutput is the console handler

     

lpConsoleScreenBufferInfor contains the coordinates of the cursor

lpConsoleScreenBufferInfor.x and lpConsoleScreenBufferInfor.y contain the coordinates in x and y respectively.

More detailed information in GetConsoleScreenBufferInfo function (English) and an example in Scrolling to Screen Buffer's Window (English).

    
answered by 21.02.2018 в 02:04
0
  

name colors.cpp [Warning] 'BOOL GetConsoleScreenBufferInfo (HANDLE, PCONSOLE_SCREEN_BUFFER_INFO)' redeclared without dllimport attribute: previous dllimport ignored [-Wattributes]

The function is declared in windows.h . This header represents the gateway to the Windows API and, unlike the standard library, its functions are distributed in DLLs.

To be able to link to a function that is in a DLL it is necessary that, in the DLL, the function be marked as exportable ( __declspec(dllexport) ), while in the client it must be declared as imported ( __declspec(dllimport) ).

The error occurs because you are including the declaration of the function in your program directly without including the import clause. Then the compiler sees that the declaration of the function overlaps with one that already exists in the DLL and throws an error because you can not have two functions with the same name, same type of return and same arguments. It is also giving you a lot of information by indicating that a statement is labeled with dllimport .

The solution is as simple as erasing the declaration of the function in your program:

#include <windows.h>

// 
/* Esto fuera
vvvvvvvvvvvvvvvvvvvvv
 BOOL WINAPI GetConsoleScreenBufferInfo(
  _In_  HANDLE                      hConsoleOutput,
  _Out_ PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo
);
^^^^^^^^^^^^^^^^^^^^^
  Hasta aqui */

int main(){
 // ...
    
answered by 21.02.2018 в 07:11