Returning to running program with WinActivate not working

Get help with using AutoHotkey and its commands and hotkeys
Posts: 1
Joined: 01 May 2017, 08:13

Returning to running program with WinActivate not working

01 May 2017, 18:17

HI all,

I am very much a novice with scripting with AHK so apologies if I ask silly questions. I have searched the forums and tried a few things but nothing seems to be getting WinActivate working for me properly and consistently. My script is below and is very simple. All it is is a toggle to connect or disconnect to a VPN using a elevated shortcut (toggle pia) and then should return to the active window (kodi). The problem is that it does not consistently make kodi active again, and sometimes when it does it appears to press a button (not sure what button...). It appears to always make kodi seem to be on top, but it is not active (i.e. pressing buttons does nothing on the kodi screen).

Code: Select all

#SingleInstance force
Run, toggle pia, C:\Program Files\pia_manager\noUAC\
Sleep, 500
WinActivate, kodi
I have also tried a method by moving the mouse cursor to the bottom right of screen and clicking to reactivate kodi (below) but this also doesn't appear to work.

Code: Select all

CoordMode, Mouse, Screen
MouseMove, (A_ScreenWidth // 1.05), (A_ScreenHeight // 1.05)
Sleep, 2500
Any help would be greatly appreciated, apologies for my coding ignorance!

User avatar
Posts: 404
Joined: 30 Sep 2014, 10:32

Re: Returning to running program with WinActivate not working

02 May 2017, 15:26

In your first script, you should use WinWaitActive. Unless you absolute trust your OS/disk is capable to fully load the program in a half of a second every time.

Canot help with your bottom code because the term "doesn't appear to work" doesn't explain the problem in an apropriate manner.

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], DizzyDuck, JKnight_xbt33, moowee, rnodern and 53 guests