[VBS] Introducing a script that inputs dummy keys so that you do not go to sleep or leave

Windows

Hello!This time, as one of the ways to prevent going to sleep, I tried to build a VBS that automatically inputs keys that are not normally used, so I will introduce it.

Even if you just say that you shouldn't go to sleep, you may not be able to do it well.
Of course, it's best to do it only with Windows settings, but I think there are moments when I find it annoying to open the GUI one by one. (Especially cases where you have to do multiple units, etc.

It is also affected by the peripheral devices and power settings that are unexpectedly connected, and it is often the case that the lock is locked only by setting the sleep.

So, I'd like to try it right away.

Thing you want to do

・ I want to prevent sleep and lock just by starting the script.

After all, that's all.
If you pick up the phone while you're working, you can avoid going to sleep after you're done.I would like to suppress it once the script is started.

Script example

Paste the code below into a text file, save it, and change the extension to .vbs to make it executable.

Set objShell = WScript.CreateObject("WScript.Shell")
Do
'①入力間隔
WScript.Sleep 60000*3
'②F15キーの送信
objShell.SendKeys "{F15}"
Loop

Commentary

VBS uses only fairly basic features, but I'll briefly explain each section.

① Set the input interval

This time, I'm trying to prevent it from going to sleep by letting the OS recognize that I'm pressing a keystroke that doesn't happen.This means that if you press keys at intervals shorter than the time it takes to go to sleep, it will not go to sleep as a mechanism.

WScript.Sleep 60000 * 3

Sleep is a method that temporarily stops the script and is set in milliseconds.
This time, the general sleep time is about 5 minutes, which is shorter than that, 3 minutes.

Since 60,000 milliseconds is 60 seconds and 60 seconds is 1 minute, it is in the form of multiplication for easy understanding.

② Send a key that does nothing

I used the "F15 key" as a representative of the keys where nothing happens.
What is the F15 key?It's hard to explain, but to put it simply, think of it as a key that used to exist on old keyboards.On today's Windows machines, it's a key that nothing happens unless you set some features yourself.

This time, using that characteristic, I am using the Sendkey method to input.

objShell.SendKeys "{F15}"

Similarly, there are F13 and F14 keys, but this may be a matter of hobby.Somehow 15 seemed to be good, so ...

All you have to do is loop the above process infinitely.

Afterword

This time I created a script to prevent VBS from going to sleep.

The mechanism is simple, but to be honest, I wanted to use a slightly rare key input called the F15 key.

I think that it can be used for such purposes as password lock is annoying when you go to sleep when you leave your seat while working, or you do not want to automatically leave your seat with the communication application you are using.
(It may be convenient to skip these days when working from home is popular. W Please do it at your own risk!

It's a bit of a chore, but the number of messenger applications like this has increased considerably. At my time, Yahoo messenger and MSN messenger were the mainstream. Teams, Discord, Line, KakaoTalk, Paypay's message sending function is also modest, and Skype has joined the ranks of Office.

By the way, this script does not implement the method of terminating, so please forcibly terminate it from the task manager.The point of forced termination is OK if you terminate the process of "Microsoft® Windows Based Script Host". (Simultaneous execution is not recommended as it can be easily confused with other VBS executions.

I hope it helps you.

Comment

Translate »
I copied the title and URL