初学EGE图形库(二)---获取鼠标详细信息

光有位置可不够

代码来自EGE官方文档 本人加以注释和修改

#include <graphics.h>

#include <stdio.h>

int main()
{
    initgraph(640, 480);

    setfont(18, 0, "宋体");

    mouse_msg msg = {0};
    /*mouse_msg是一个结构体
    typedef struct mouse_msg
    {
        UINT msg;
        INT  x;
        INT  y;
        UINT flags;
        INT  wheel;
    }mouse_msg;
    这一步操作和memset(&msg,0,sizeof(struct mouse_msg));是一个意思*/
    for ( ; is_run(); delay_fps(60))
    {

        while (mousemsg())//获取鼠标消息,这个函数会等待,等待到有消息为止
        {
            msg = getmouse();//将鼠标信息存入鼠标结构体
        }


        cleardevice();//清空前景,即清空上次的结果
        xyprintf(0, 0, "x = %10d  y = %10d",
                 msg.x, msg.y);
                 //第一行显示鼠标x,y位置.
        xyprintf(0, 20, "move  = %d down  = %d up    = %d",
                 (int)msg.is_move(),
                 (int)msg.is_down(),
                 (int)msg.is_up());
                 //第二行显示鼠标是否有动作,按键状态
        xyprintf(0, 40, "left  = %d mid   = %d right = %d",
                 (int)msg.is_left(),
                 (int)msg.is_mid(),
                 (int)msg.is_right());
                 //第三行显示鼠标被按下的按键(左,中,右)
        xyprintf(0, 60, "wheel = %d  wheel rotate = %d",
                 (int)msg.is_wheel(),
                 msg.wheel);
                 //第四行显示滚轮位置
    }

    closegraph();
    return 0;
}

这样一下就把鼠标的基本信息获取完了

主要就是使用getmouse()配合mouse_msg结构体

来实现对鼠标信息的记录和存取


  • 4
    点赞
  • 47
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值