autohotkey_如何通过使用AutoHotkey自动完成繁琐的任务来节省时间

autohotkey

autohotkey

Have you ever needed to perform the same mindless task over and over on your PC? Instead of wasting hours clicking buttons and hitting keys, this is the perfect time to use your AutoHotkey skills to make your PC do the work for you.

您是否需要一遍又一遍地在PC上执行相同的任务? 这是利用您的AutoHotkey技能使PC为您完成工作的理想时机,而不是浪费时间单击按钮和敲击键。

Note: This particular example is a real one that I used earlier today to save a small amount of time, but these are techniques that I’ve used many times over the years to literally save myself days worth of time.

注意:这个示例是一个真实的示例,我今天早些时候使用它来节省少量时间,但是这些年来,我已经使用了很多次这些技术来节省自己几天的时间。

场景 (The Scenario)

I was trying to go through and clean out a bunch of incorrect broadcast messages in our email newsletter account, when I realized that their interface required me to manually click the Delete button and then confirm it on every single message—we’re talking about 300 incorrect messages that needed to be deleted. To make matters worse, the interface is extremely slow, which means I would have spent a good 30-40 minutes just clicking and making my carpal tunnel even worse.

当我意识到他们的界面要求我手动单击“删除”按钮,然后在每一封邮件中进行确认时,我正尝试在电子邮件时事通讯帐户中清理并清理一堆不正确的广播消息,这就是说300需要删除的错误消息。 更糟糕的是,该界面非常慢,这意味着我只用了30-40分钟就可以使腕管变得更糟。

image[11]

Instead of doing that, I created a new AutoHotkey script and quickly wrote up a script to do the work for me.

我没有这样做,而是创建了一个新的AutoHotkey脚本,并Swift编写了一个脚本来为我完成工作。

The first step was to identify exactly which clicks and keys I needed to automate—obviously the first step is to click on the X button, which brings up this Ajax confirmation dialog:

第一步是准确确定我需要自动执行的单击和键-显然,第一步是单击X按钮,这将弹出此Ajax确认对话框:

image[13]

Luckily the Delete button is automatically highlighted, so you can simply hit the Space key to confirm. Once the record has been deleted, everything slides up as if the row was never there. Knowing this, we’ll move on and create a script that automates clicking the X button, waiting 3 seconds for the confirmation dialog, presses the Space bar, and then waits another 3 seconds for the row to disappear.

幸运的是,“删除”按钮会自动突出显示,因此您只需按空格键即可确认。 删除记录后,所有内容都会向上滑动,就好像该行从不存在一样。 知道了这一点,我们将继续创建一个脚本,该脚本自动单击X按钮,等待3秒等待确认对话框,按下空格键,然后再等待3秒等待该行消失。

创建脚本 (Creating the Script)

The first thing we’ll want to do is create a loop that will repeat the same actions a number of times—in this case, we’re estimating that we’ll need to repeat this 300 times, so we’ll use the Loop syntax like this:

我们要做的第一件事是创建一个循环,该循环将重复相同的动作多次–在这种情况下,我们估计需要重复300次,因此我们将使用循环语法如下:

  Loop 300  {

循环300 {

  }

}

Now we’ll need to automate the click action, which is easy in AutoHotkey—you just type click. You can use a more advanced click syntax if you want, choosing exactly where you want it to click on the screen, or choosing the button click. For our purposes, we’ll just be using the default, which leaves us with this:

现在,我们需要使click操作自动化,这在AutoHotkey中很容易-您只需键入click即可 。 如果需要,可以使用更高级的单击语法 ,选择要在屏幕上单击的位置,或者选择单击按钮。 为了我们的目的,我们将只使用默认值,这使我们有了:

  Loop 300  {     click  }

循环300 {单击}

Now our script will click 300 times in a row, but unfortunately we’ve got that confirmation dialog to deal with, so now we’ll use the Send function to send the Space bar keystroke to the active window.

现在,我们的脚本将连续单击300次,但是不幸的是,我们已经处理了该确认对话框,因此现在,我们将使用Send函数将空格键的击键发送到活动窗口。

  Loop 300  {     click     Send,{Space}  }

循环300 {单击发送,{空格}}

If you look at the documentation you’ll see all of the syntax for special keys—regular keystrokes can be entered normally—for instance, if you wanted to type test and then end it with a Space, you’d use this:

如果您查看文档,将会看到特殊键的所有语法(可以正常输入常规击键),例如,如果要键入test并以空格结尾,则可以使用以下命令:

Send, test{Space}

发送,测试{空格}

So now we’ve got a script that clicks the button and then hits the Space bar, which would be alright except the interface is slow, so we need to insert a small pause between each execution of the click and send functions. To accomplish this, we’ll use the Sleep function, which takes only one argument—the delay in milliseconds.

因此,现在我们有了一个脚本,该脚本单击该按钮然后单击空格键,除非界面较慢,否则没关系,因此我们需要在每次执行click和send函数之间插入一个小暂停。 为此,我们将使用Sleep函数 ,该函数仅接受一个参数-延迟(以毫秒为单位)。

  Loop 300  {     sleep 3000     click     sleep 3000     Send,{Space}  }

循环300 {sleep 3000 click sleep 3000 Send,{Space}}

Now we’ve got a script that will successfully delete the items, waiting 3 seconds before it starts so that you can move the mouse cursor over the first X, clicking the button, waiting 3 seconds, hitting the Space bar, and then waiting 3 seconds before it goes through the next set. You could use this simple script right now if you wanted to—but what if you want to stop the script?

现在,我们有了一个脚本,该脚本将成功删除项目,等待3秒钟,然后再将其启动,以便您可以将鼠标光标移到第一个X上,单击按钮,等待3秒钟,单击空格键,然后等待3秒钟。在经过下一组之前的秒数。 如果需要,您可以立即使用此简单脚本,但是如果要停止脚本怎么办?

What we’ll do is use the GetKeyState function to check whether you’ve hit a certain key—for testing, we’ll use the F8 key and add the following into the middle of the loop. This will detect whether the F8 key has been pressed, and then use the break to exit the loop.

我们要做的是使用GetKeyState函数检查您是否按下了某个键-为了进行测试,我们将使用F8键并将以下内容添加到循环的中间。 这将检测是否已按下F8键,然后使用换行符退出循环。

GetKeyState, state, F8   if state = D     break

GetKeyState,状态,如果状态= D中断,则为F8

最终剧本 (The Final Script)

Here’s the final script all put together, which probably won’t help you too much since it’s specific to my scenario—but you can use it to create your own scripts by simply modifying the clicks and keystroke sending.

这是所有最终脚本,它们可能对您的情况没有太大帮助,因为它特定于我的方案,但是您可以通过简单地修改单击和击键发送来使用它来创建自己的脚本。

  Loop 300  {    GetKeyState, state, F8    if state = D        break    sleep 3000    click    sleep 3000    Send, {Space}  }  Return

循环300 {GetKeyState,状态,如果状态= D,则F8中断睡眠3000单击睡眠3000发送,{空格}}返回

To illustrate how this works in practice, here’s a quick video that shows it in action:

为了说明在实际中是如何工作的,下面是一个简短的视频,展示了它的实际作用:

In this particular scenario, it took me about 3 minutes to throw together a working script—time saved: 27 minutes. Just enough time for me to record the video and write this article!

在这种特殊情况下,我花了大约3分钟的时间来整理工作脚本,从而节省了27分钟的时间。 我有足够的时间来录制视频并撰写本文!

翻译自: https://www.howtogeek.com/howto/27971/how-to-save-time-by-automating-tedious-tasks-with-autohotkey/

autohotkey

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值