弄了一个项目,要求纯软件实现互相控制,所以写了一个扩展屏幕:
基本功能就是,取消鼠标只能在本地屏幕的限制,可以无限制扩展。下面是扩展了一个屏幕在,本屏幕的下方。本屏幕最大只有1920x1080 而,当前位置已经虚拟到了 168:1453,落在了扩展屏上!
原理:
1. 实现鼠标hook
2. 当鼠标移出本进屏幕时,屏蔽鼠标事件
3. 累计鼠标事件,直到返回本地屏幕。
关键代码为:
if (this.MouseAtLocalScreen == true)
{
// 不在本地屏幕
mCurExMouseEvent = e;
if(this.PointAtExScreen(new Point(mCurExMouseEvent.offsetX, mCurExMouseEvent.offsetY)) == true)
{
SetCursorPos(LocalScreenCenter.X, LocalScreenCenter.Y);
iRet = 1;
this.MouseAtLocalScreen = false;
}
}
else
{
Point tmp_point = new Point(mCurExMouseEvent.offsetX, mCurExMouseEvent.offsetY);
Point offset = new Point(e.offsetX - this.LocalScreenCenter.X, e.offsetY - this.LocalScreenCenter.Y);
tmp_point.X += offset.X;
tmp_point.Y += offset.Y;
if(this.PointAtLocalScreen(tmp_point) || this.PointAtExScreen(tmp_point))
{
mCurExMouseEvent.offsetX = tmp_point.X;
mCurExMouseEvent.offsetY = tmp_point.Y;
}
if (this.PointAtExScreen(new Point(mCurExMouseEvent.offsetX, mCurExMouseEvent.offsetY)) == false)
{
this.MouseAtLocalScreen = true;
SetCursorPos(mCurExMouseEvent.offsetX, mCurExMouseEvent.offsetY);
}
iRet = 1;