c言語がコンソールでマウスの左ボタンを判定する例



// temp1.cpp : Defines the entry point for the console application.
 //

 //#include <stdafx.h>
 #include <windows.h>
 #include <conio.h>
 #include <stdlib.h>
 #include<stdio.h>
 int main(int argc, char* argv[])
 {
  SetConsoleTitle("Hello World!");
  HANDLE hInput = GetStdHandle(STD_INPUT_HANDLE); //
  INPUT_RECORD inRec;
  DWORD res;

  while (1)
  {
   ReadConsoleInput(hInput, &inRec, 1, &res);
   if (inRec.EventType == MOUSE_EVENT && inRec.Event.MouseEvent.dwButtonState == FROM_LEFT_1ST_BUTTON_PRESSED) //
   {
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),inRec.Event.MouseEvent.dwMousePosition);
    printf("Hello World!");
   }
   Sleep(100);
  }
  return 0;
 }