c语言在控制台判定鼠标左键

 1 // temp1.cpp : Defines the entry point for the console application.
 2 //
 3 
 4 //#include <stdafx.h>
 5 #include <windows.h>
 6 #include <conio.h>
 7 #include <stdlib.h>
 8 #include<stdio.h>
 9 int main(int argc, char* argv[])
10 {
11  SetConsoleTitle("Hello World!");
12  HANDLE hInput = GetStdHandle(STD_INPUT_HANDLE); // 获取标准输入设备句柄
13  INPUT_RECORD inRec;
14  DWORD res;
15 
16  while (1)
17  {
18   ReadConsoleInput(hInput, &inRec, 1, &res);
19   if (inRec.EventType == MOUSE_EVENT && inRec.Event.MouseEvent.dwButtonState == FROM_LEFT_1ST_BUTTON_PRESSED) //鼠标左键
20   {
21    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),inRec.Event.MouseEvent.dwMousePosition);
22    printf("Hello World!");
23   }
24   Sleep(100);
25  }
26  return 0;
27 }

 

posted @ 2013-06-18 21:34  Geekers  阅读(652)  评论(0编辑  收藏  举报