I have automated keyboard/mouse controls into a macro that is an EXE that can trigger as a scheduled event for stuff like this. But the software to do it costs money. There are some keyboard/mouse macro creators out there that are free, but I haven't had any good luck with the free ones. I use Jitbit Macro Recorder which allows me to record keyboard/mouse actions and create stand alone compiled macros as EXE's that can be called by scheduled task or batched instructions. It also has a very good editor that allows you to create macros without recording the process if you want to create something from scratch without running it on the system to create it.
The cool thing with the Jitbit software is that I bought it over 10 years ago and when I went to use the older version on a newer computer I ran into an issue with Windows 10 and the old version. Vlad at support once I sent him a copy of my original purchase invoice sent me a link to the newest version of it and a new key that would work with the latest version which worked flawless with Windows 10. So their support is really good for the fact that I had assistance by e-mail quickly when proving that I bought the software in the past.
In addition to automated stuff like what your trying to do, I have also used it to automate redundant boring processes of games where I don't need to grind it out, I can set my computer to grind it out for me while I sleep etc. Some games will ban you for doing that, but you have to get caught to get banned from automated farming in games.
Only games like World of Warcraft etc have memory sniffers for automated keyboard and mouse controls. Using it with WoW would pretty quickly get you banned when the sniffer picks up on the macro. I haven't tested this as for I don't want to be banned, but I am aware of what they have running in the background to keep the game as bot free as possible.