c语言在控制台判定鼠标左键的小例子_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;
 } 

时间: 2024-08-01 21:52:19

c语言在控制台判定鼠标左键的小例子_C 语言的相关文章

大咖们,请问如何用C语言实现检测到鼠标左键按下时,等效于按下printscreen键

问题描述 大咖们,最近公司要截很多图,按printscreen键按到手软求教如何用c语言实现,按下鼠标左键的时候,同步实现按下printscreen,多谢.我知道以下代码可实现鼠标左键按下的检测,#include<stdio.h>#include<windows.h>#include<conio.h>#include<stdlib.h>intmain(intargc,char*argv[]){SetConsoleTitle("1111111111&

C语言数组指针的小例子_C 语言

1.功能:输入6个学生的5门课程成绩,计算出每个学生的平均分和每门课程的平均分.2.C语言实现代码:(其实就是用二维数组来实现的,二维数组的引用传递使用数组指针来完成) 复制代码 代码如下: #include <stdio.h>#define STUDENT 5#define SCORE 6void input_array(float (*score)[STUDENT]);void avg_score(float (*score)[STUDENT]);void avg_course(float

C语言获得电脑的IP地址的小例子_C 语言

复制代码 代码如下: #include <stdio.h> #include <winsock2.h>  #pragma comment(lib, "WS2_32.lib")  int main() {     char host_name[256]; // define host name (for example:xxx-PC)     int WSA_return, i;     WSADATA WSAData;     HOSTENT *host_ent

C/C++语言中结构体的内存分配小例子_C 语言

当未用 #pragma 指令指定编译器的对齐位数时,结构体按最长宽度的数据成员的宽度对齐:当使用了 #pragma 指令指定编译器的对齐位数时,结构体按最长宽度的数据成员的宽度和 #pragma 指令指定的位数中的较小值对齐. #pragma 指令格式如下所示:#pragma pack(4)     // 或者 #pragma pack(push, 4) 举例如下:(机器字长为 32 位)    struct    {        char a;    }test;    printf("%d

C语言判断回文数的小例子_C 语言

复制代码 代码如下: #include<stdio.h>#include<stdlib.h> int is_palindrome(char* para_str , int len); int main(int argc , char* argv[]){   int n = atol(argv[2]);     if (is_palindrome(argv[1],n))       printf("this string is palindrome !\n"); 

异步http listener 完全并发处理惩罚http恳求的小例子_C 语言

复制代码 代码如下: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.Net.Sockets; using DevSDK.Net.Sockets; using System.IO;  namespace ConsoleApplication1 {     class Program     {         s

short与int转换的小例子_C 语言

复制代码 代码如下: #include <stdio.h> int main(){    short a=-1;    unsigned int b=a;    int c=a;     printf("%x\n", b);    printf("%d\n", c);     a=1;    b=a;    c=a;     printf("%x\n", b);    printf("%d\n", c);    

c语言读取obj文件转换数据的小例子_C 语言

复制代码 代码如下: // hello.cpp : Defines the entry point for the console application.// #include "stdafx.h"#include "stdio.h" int _tmain(int argc, _TCHAR* argv[]){    FILE *file1,*file2;    file1=fopen("047facesmall.obj","r&quo

C 字符串数组排序的小例子_C 语言

复制代码 代码如下: #include<stdio.h>#include<string.h>#include <malloc.h>void q_sortB(char str[20][20], int n);void qs(char str[20][20],int n); void main() {    int i, n;    char str[20][20] = { { "Adam" }, { "Bob" }, { "