使用Autoit3制作小程序实现自动移动鼠标防止进入屏保

脚本语言打包方式容易引起一些安全提示,我就想那为啥不干脆换个方式。我简单翻了翻之前的帖子,发现主流的防屏保主要是动鼠标和动键盘,于是整合了一下,用C#复刻了一版,框架用的3.5,当时考虑win7自带3.5,后来发现win10默认不带3.5,就有点尴尬,所以有需要自行取用。

程序包后239K,对一个.NET程序来说当然有点大,主要原因是我为了提升体验,用了224K的大图标,如果想换成公司logo潜伏,可以自己改

方案一和方案二看起来没啥区别,其实写的时候有调用过不同的API,后来实测发现sendkeys对防屏保没用,就都切换成keybd_event,所以现在实际就是没啥区别,看着不舒服可以自己改

间隔时间我嫌麻烦就做成整数秒了,需要一呼一吸之间点下18次鼠标的,可以自己改

点鼠标本意是挂公司培训课时用的,可是我现在没啥需要点鼠标的挂课时的,所以写的很随意,暂时我也不打算完善,就这样先

虽然程序就等于源码,但由于我写的比较糙

using System;

using System.Windows.Forms;

using System.Threading;

using System.Runtime.InteropServices;

using System.Drawing;

namespace NoSleep_NET

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

this.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);

notifyIcon1.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);

}

static int timespan_sec = 200;

static bool scheme_1 = false;

static bool scheme_2 = false;

static bool scheme_3 = false;

static bool scheme_4 = false;

Thread othread = new Thread(No_Sleep);

[DllImport("user32")]

public static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);

[DllImport("user32")]

public static extern void keybd_event(byte bVk,byte bScan,int dwFlags,int dwExtraInfo);

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)

{

//允许输入:数字、退格键(8)、全选(1)

if (!Char.IsDigit(e.KeyChar) && e.KeyChar != 8 && e.KeyChar != 1)

{

e.Handled = true;

}

}

private void button1_Click(object sender, EventArgs e)

{

timespan_sec = Convert.ToInt32(textBox1.Text);

scheme_1 = checkBox1.Checked;

scheme_2 = checkBox2.Checked;

scheme_3 = checkBox3.Checked;

scheme_4 = checkBox4.Checked;

othread.Abort();

this.Hide();

othread = new Thread(No_Sleep);

othread.Start();

}

private void button2_Click(object sender, EventArgs e)

{

this.Hide();

textBox1.Text = Convert.ToString(timespan_sec);

checkBox1.Checked = scheme_1;

checkBox2.Checked = scheme_2;

checkBox3.Checked = scheme_3;

checkBox4.Checked = scheme_4;

}

private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)

{

if (Visible)

{

this.Hide();

}

else

{

Show();

WindowState = FormWindowState.Normal;

}

}

private void 参数设置ToolStripMenuItem_Click(object sender, EventArgs e)

{

Show();

WindowState = FormWindowState.Normal;

}

private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)

{

othread.Abort();

Application.Exit();

}

private static void No_Sleep()

{

while (true)

{

Thread.Sleep(timespan_sec * 1000);

if (scheme_1)

{

keybd_event(0x91, 0, 0, 0);

keybd_event(0x91, 0, 2, 0);

Thread.Sleep(10);

keybd_event(0x91, 0, 0, 0);

keybd_event(0x91, 0, 2, 0);

}

if (scheme_2)

{

keybd_event(0x90, 0, 0, 0);

keybd_event(0x90, 0, 2, 0);

Thread.Sleep(10);

keybd_event(0x90, 0, 0, 0);

keybd_event(0x90, 0, 2, 0);

}

if (scheme_3)

{

mouse_event(0x0001, 1, 0, 0, 0);

mouse_event(0x0001, -1, 0, 0, 0);

}

if (scheme_4)

{

mouse_event(0x0002, 0, 0, 0, 0);

mouse_event(0x0004, 0, 0, 0, 0);

}

}

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值