当前位置: 首页 > news >正文

10-鼠标操作的处理

左键右键双击移动

同样在ServerSocket.h中需要一个函数捕捉鼠标事件

这里在ServerSocket.h 就需要一个结构体来接收鼠标事件,之前文件只用接收打开的文件路径,这里client需要传多个参数到sever端

	bool GetMouseEvent(MOUSEEV& mouse) {if (m_packet.sCmd == 5) {memcpy(&mouse, m_packet.strData.c_str(), sizeof(MOUSEEV));return true;}return false;}
typedef struct MouseEvent{MouseEvent() {nAction = 0;nButton = -1;ptXY.x = 0;ptXY.y = 0;}WORD nAction;// 点击、移动、双击WORD nButton;// 左键、右键、中键POINT ptXY;// 坐标
}MOUSEEV,*PMOUSEEV;

然后就是server端响应这个事件

int MouseEvent() {MOUSEEV mouse;if (CServerSocket::getInstance()->GetMouseEvent(mouse)) {DWORD nFlags = 0;switch (mouse.nButton) {case 0: //左键nFlags = 1;break; case 1: //右键nFlags = 2;break;case 2: //中键nFlags = 4;break; case 4: //无按键按下,单纯的鼠标移动nFlags = 8;break;}if (nFlags != 8) SetCursorPos(mouse.ptXY.x, mouse.ptXY.y);switch (mouse.nAction){case 0: //单击nFlags |= 0x10;break;case 1: //双击nFlags |= 0x20;break;case 2: //按下,可能要拖动一些东西nFlags |= 0x40;break;case 3: //放开nFlags |= 0x80;break;default:break;}switch (nFlags) {case 0x21: //左键双击mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, GetMessageExtraInfo()); //获取当前线程的额外信息,有没有额外按下按键mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, GetMessageExtraInfo()); //case 0x11: //左键单击mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, GetMessageExtraInfo()); //获取当前线程的额外信息,有没有额外按下按键mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, GetMessageExtraInfo()); //break;case 0x41: //左键按下mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, GetMessageExtraInfo()); //获取当前线程的额外信息,有没有额外按下按键break;case 0x81: //左键放开mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, GetMessageExtraInfo()); //break;case 0x22: //右键双击mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, GetMessageExtraInfo()); //获取当前线程的额外信息,有没有额外按下按键mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, GetMessageExtraInfo()); //case 0x12: //右键单击mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, GetMessageExtraInfo()); //获取当前线程的额外信息,有没有额外按下按键mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, GetMessageExtraInfo()); //break;case 0x42: //右键按下mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, GetMessageExtraInfo()); //获取当前线程的额外信息,有没有额外按下按键break;case 0x82: //右键放开mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, GetMessageExtraInfo()); //break;case 0x24: //中键双击mouse_event(MOUSEEVENTF_MIDDLEDOWN, 0, 0, 0, GetMessageExtraInfo()); //获取当前线程的额外信息,有没有额外按下按键mouse_event(MOUSEEVENTF_MIDDLEUP, 0, 0, 0, GetMessageExtraInfo()); //case 0x14: //中键单击mouse_event(MOUSEEVENTF_MIDDLEDOWN, 0, 0, 0, GetMessageExtraInfo()); //获取当前线程的额外信息,有没有额外按下按键mouse_event(MOUSEEVENTF_MIDDLEUP, 0, 0, 0, GetMessageExtraInfo()); //break;case 0x44: //中键按下mouse_event(MOUSEEVENTF_MIDDLEDOWN, 0, 0, 0, GetMessageExtraInfo()); //获取当前线程的额外信息,有没有额外按下按键break;case 0x84: //中键放开mouse_event(MOUSEEVENTF_MIDDLEUP, 0, 0, 0, GetMessageExtraInfo()); //break;case 0x08: //单纯鼠标移动mouse_event(MOUSEEVENTF_MOVE, mouse.ptXY.x,mouse.ptXY.y,0, GetMessageExtraInfo());break;}CPacket pack(4, NULL, 0); //表明收到这个消息了,并且执行完成了CServerSocket::getInstance()->Send(pack);}else {OutputDebugString(_T("获取鼠标操作参数失败"));return -1;}return 0;
}

这里的处理方式是定义一个8位flag,将flag前4位区分哪个键按下,后四位当单双击行为`

GetMessageExtraInfo() 当鼠标事件发生时候,可能出现其他事件,比如按下了ctrl按键


文章转载自:

http://QXId4afS.qsmmq.cn
http://JPtX0oX6.qsmmq.cn
http://vRe974dX.qsmmq.cn
http://it7jLnxl.qsmmq.cn
http://wmVQ5xsP.qsmmq.cn
http://X47ii3lI.qsmmq.cn
http://tI14T2hu.qsmmq.cn
http://xEBJBaA3.qsmmq.cn
http://B7Yy1eEf.qsmmq.cn
http://Nu8YDKqS.qsmmq.cn
http://6FxAS0YS.qsmmq.cn
http://DAzD8Yn0.qsmmq.cn
http://Qd3A7JfX.qsmmq.cn
http://KnCEp3Fi.qsmmq.cn
http://E4hZRxR3.qsmmq.cn
http://ort86WNX.qsmmq.cn
http://8WceUBqW.qsmmq.cn
http://eWhdvsEs.qsmmq.cn
http://P1Unm8Dn.qsmmq.cn
http://wNgDutEQ.qsmmq.cn
http://oW7Tc4sf.qsmmq.cn
http://7YJBuacg.qsmmq.cn
http://OhJZD2K2.qsmmq.cn
http://yGMmjHTN.qsmmq.cn
http://QKLiHgnE.qsmmq.cn
http://4UEEqBrG.qsmmq.cn
http://qVjGdl4R.qsmmq.cn
http://KXdOvPsP.qsmmq.cn
http://72DUCIpT.qsmmq.cn
http://XNb9RF3a.qsmmq.cn
http://www.dtcms.com/a/383419.html

相关文章:

  • efcore 对象内容相同 提交MSSQL后数据库没有更新
  • Docker 容器化
  • 玩转Docker | 使用Docker部署OmniTools自托管IT工具箱
  • 类的组合(对比继承)
  • python爬虫的逆向技术讲解
  • Cookie 和 Session
  • 【WebSocket✨】入门之旅(四):WebSocket 的性能优化
  • 40分钟的Docker实战攻略
  • JavaScript 运算符完全指南:从基础到位运算
  • visual studio快捷键
  • 第21课:成本优化与资源管理
  • 5【鸿蒙/OpenHarmony/NDK】应用太卡?用 Node-API 异步任务解决:从卡顿根源到流畅方案
  • 利用OpenCV进行对答题卡上的答案进行识别的案例
  • 如何用 Rust 实现的基础屏幕录制程序?
  • 认知语义学隐喻理论对人工智能自然语言处理中深层语义分析的赋能与挑战
  • 常见索引失效场景及原因分析(含示例)
  • 嵌入式Linux常用命令
  • xtuoj Rectangle
  • C++内存管理:new与delete的深层解析
  • Nginx 实战系列(十)—— 搭建LNMP环境与部署Discuz!社区论坛指南
  • 计算机视觉案例分享之答题卡识别
  • 端口打开与服务可用
  • 如何解决 pip install 安装报错 ModuleNotFoundError: No module named ‘requests’ 问题
  • 使用Docker和虚拟IP在一台服务器上灵活部署多个Neo4j实例
  • Web前端面试题(2)
  • 硬件开发_基于物联网的仓鼠饲养监测系统
  • 资产负债表、利润表、经营现金流、统计指标计算程序
  • JWT简介
  • Week1:类,类与类之间的关系,继承,封装,多态
  • PostgreSQL 上的向量搜索实践