c语言在控制台判定鼠标左键的小例子

 更新时间:2020年4月25日 17:45  点击:1696
复制代码 代码如下:

// 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;
 } 
[!--infotagslink--]

相关文章