Script in Windows 7 having trouble in Windows 10 (#ifWinActive)

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
revel
Posts: 11
Joined: 23 Nov 2016, 17:08

Script in Windows 7 having trouble in Windows 10 (#ifWinActive)

22 Jul 2018, 13:31

Hi. I have been using a script in Windows 7 for quite some time now and it's been working great. But now I have a Windows 10 workstation and I'm running in to a problem.

The script turns a mouse button in to "enter" in 2 applications (3dsmax and Photoshop) using #ifWinActive. The issue seems to be that if I click on something else, namely something like a folder window or Chrome (most likely active on my second monitor) and then I click back to 3dsmax (on my main monitor) I lose connection to the active window / active window does not return to "3dsmax.exe". It might be remaining on that previously selected application.

Currently the only fix I've found for this is to alt+tab twice. Basically alt+tab to the folder or chrome or whatever I had clicked on previously and then alt+tab back to 3dsmax. This re-engages the active window to 3dsmax.exe

I have very limited knowledge here and am looking for a fix for this so that things run like Windows 7 where if i'm actively using 3dsmax or Photoshop the autohotkey always works.

Thanks.

Code: Select all

;========================================================================================
;--------------------------------------------------------------------3dsMax-----------------------------------------------------------------------
;========================================================================================
#ifWinActive ahk_exe 3dsmax.exe
{
Xbutton1::
Send {Enter}
Sleep, 100
return
}


;========================================================================================
;--------------------------------------------------------------------PHOTOSHOP-----------------------------------------------------------------------
;========================================================================================
#ifWinActive ahk_exe Photoshop.exe
{
Xbutton1::
Send {Enter}
Sleep, 100
return
}
gregster
Posts: 9002
Joined: 30 Sep 2013, 06:48

Re: Script in Windows 7 having trouble in Windows 10 (#ifWinActive)

22 Jul 2018, 13:44

Is this your complete and only script? Because I don't see how remappings of Xbutton1 (aka 4th mouse button) could cause this.
revel
Posts: 11
Joined: 23 Nov 2016, 17:08

Re: Script in Windows 7 having trouble in Windows 10 (#ifWinActive)

22 Jul 2018, 21:34

This is the entire script i've been using for a long time on Windows 7 and it works great.

This script on Windows 10 is having trouble with the active window. The button funcions are fine. The script works. But it looses active window at times when I click away and then click back.

So I'm wondering about a fix like perhaps there is something similar to ifWinActive that would be more reliable in Windows 10? Or if this is a known issue.

note: When the problem occurs the Xbutton1 function acts as its navite windows function. And like I said I have to alt-tab away and then alt-tab back to get it to use the scripts function again.
gregster
Posts: 9002
Joined: 30 Sep 2013, 06:48

Re: Script in Windows 7 having trouble in Windows 10 (#ifWinActive)

22 Jul 2018, 21:39

When the problem occurs the Xbutton1 function acts as its navite windows function.
Then, most likely, you will have to run the script as admin (because the apps in question probably run with elevated rights on Win10).
revel
Posts: 11
Joined: 23 Nov 2016, 17:08

Re: Script in Windows 7 having trouble in Windows 10 (#ifWinActive)

22 Jul 2018, 21:42

I have the exe for AutoHotKey set to Administrator (It didn't work at all with out that) .
If I do that is it fine or is there something else I need to do? I usually have AutoHotKey pinned to my bar and then right-click it and go to my .ahk. I figure it's running in administrator when I do that because the executable is set to.
I believe I run 3dsMax as Administrator too.

Thanks
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: Script in Windows 7 having trouble in Windows 10 (#ifWinActive)

23 Jul 2018, 03:22

Use KeyHistory immediately after the button "acts as its native windows function". I suspect the KeyHistory line for XButton1 will show # under the Type column, meaning the #IfWinActive condition was not met. In other words, neither Photoshop.exe nor 3dsmax.exe is active. The Window column will show you which window was active.
User avatar
mshall
Posts: 35
Joined: 13 Jul 2018, 16:42
Contact:

Re: Script in Windows 7 having trouble in Windows 10 (#ifWinActive)

23 Jul 2018, 08:46

We use winactive in win10 and win7 without issue. The usual solution is to try to include it as part of your function.
revel
Posts: 11
Joined: 23 Nov 2016, 17:08

Re: Script in Windows 7 having trouble in Windows 10 (#ifWinActive)

23 Jul 2018, 10:09

I put the #ifWinActive inside the {. Issue can still come up.

Whats strange is I have Window Spy up and when it broke it was still displaying ahk_exe 3dsmax.exe in the Window Title, Class and Process:
revel
Posts: 11
Joined: 23 Nov 2016, 17:08

Re: Script in Windows 7 having trouble in Windows 10 (#ifWinActive)

23 Jul 2018, 12:04

It's only when I minimize the previously selected window. So if I minimize chrome or spotify etc... and attention goes back to 3dsmax. Funny thing is the Window Spy moves to 3dsmax.exe consistently but I have to alt tab twice or rerun the script to get function back.
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: Script in Windows 7 having trouble in Windows 10 (#ifWinActive)

24 Jul 2018, 00:58

Regardless of what Window Spy says, what actually matters is what the keyboard hook detects and how it reacts. KeyHistory shows this information. Have you tried my suggestion?

Window Spy updates periodically; if a window is active for a fraction of a second, you may not see it in Window Spy.

Braces have nothing to do with the #IfWinActive directive. You may as well remove the braces.
revel
Posts: 11
Joined: 23 Nov 2016, 17:08

Re: Script in Windows 7 having trouble in Windows 10 (#ifWinActive)

24 Jul 2018, 09:38

I looked in to how to use KeyHistory and this is what I'm seeing.

When working properly.
------------
01 000 d 15.02 LButton
01 000 u 0.20 LButton Untitled - Autodesk 3ds Max 2018
05 000 h d 1.11 XButton1 Clone Options
0D 01C i d 0.00 Enter
0D 01C i u 0.00 Enter
05 000 s u 0.13 XButton1 Untitled - Autodesk 3ds Max 2018
01 000 d 0.72 LButton
01 000 u 0.11 LButton ...\BackToEnterMaxAndPS_Win10.ahk - AutoHotkey v1.1.29.01
-----------------



When it breaks (or appears to be doing "Back" instead of the scripts "Enter")

-Nothing happens. No "Xbutton1".
It will display the Window name of the application I minimized. Then when I perform the exact same actions nothing gets recorded. I can mash on XButton1 and 3dsmax will respond invalid entry and windows *ding* (same as if I wasn't running the script at all). When I F5 in KeyHistory nothing comes up or changes except the line for the application I minimized to cause the problem.
--------------
01 000 u 0.06 LButton Script in Windows 7 having trouble in Windows 10 (#ifWinActive) - AutoHotkey Community - Google Chr
--------------

In fact as far as I can tell its not even recording LButton down/up for anything after this including clicking on the AutoHotKey main menu to refresh.

Thanks

Also I tried hooking up a different mouse. Same activity.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: garry and 182 guests