MATLAB实现控制鼠标移动和点击

本文介绍了如何使用MATLAB结合C++代码实现对鼠标的控制,包括移动和点击功能。提供的代码可以直接在MATLAB环境中编译运行,为用户提供了实现简单自动化任务的基础。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

有了这两个代码,再加上刚刚的matlab截图功能,基本上可以实现一些简单的功能了。

这两个代码可以直接在matlab里面编译。

mousemove.cpp:

#include<windows.h>
#include "mex.h"

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
	if (nrhs != 2)
		mexErrMsgTxt("需要两个参数!\m");
	if (nlhs > 1)
		mexErrMsgTxt("返回值太多!\m");
	if (!mxIsDouble(prhs[0]) || !mxIsDouble(prhs[1]))
		mexErrMsgTxt("输入参数必须为数字!\m");
	bool flag;
	int X, Y;
	X = int(*(double*)(mxGetData(prhs[0])));
	Y = int(*(double*)(mxGetData(prhs[1])));
	flag = SetCursorPos(X, Y);
	double *r;
	plhs[0] = mxCreateDoubleMatrix(1, 1, mxREAL);
	r = mxGetPr(plhs[0]);
	
	if (flag)
		*r = 1;
	else 
		*r = 0;
}

mouseclick.cpp:

#include<windows.h>
#include "mex.h"

#define CLICK 1
#define DOWN 2
#define UP 3
#define LEFT 1
#define MIDDLE 2
#define RIGHT 3
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
	void
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值