特投网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

(站外) 特投工作室

查看: 1986|回复: 0

C# 如何获取鼠标在屏幕上的位置,不论程序是否为活动状态

[复制链接]

2569

主题

1018

回帖

6万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
69667
QQ
发表于 2016-2-8 17:01:01 | 显示全部楼层 |阅读模式
一开始我认为应该使用HOOK来写,而且必须使用全局HOOK,结果在一次偶然的机会得到,原来其实根本没有那个必要。

直接上代码吧,一看就明白

Point ms = Control.MousePosition;
            this.label2.Text = string.Format("{0}:{1}", ms.X, ms.Y);
            MouseButtons mb=  Control.MouseButtons;

            if (mb == System.Windows.Forms.MouseButtons.Left) this.label3.Text = "Left";
            if (mb == System.Windows.Forms.MouseButtons.Right) this.label3.Text = "Right";
            if (mb == System.Windows.Forms.MouseButtons.Middle) this.label3.Text = "Middle";

这里面 Control.MouseButtons 是关键代码

将以上代码写入到 TIMER的Tick过程中,就可以实时显示鼠标所在位置,无论鼠标在哪个位置。

转自:http://www.cnblogs.com/lujin49/p/3504805.html
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

您尚未登录,请登录后浏览更多精彩内容!
 立即注册
找回密码

QQ|Archiver|手机版|小黑屋|特投网 ( 皖ICP备13010674号-1 

GMT+8, 2024-4-28 01:44 , Processed in 0.025129 second(s), 11 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表