WinActive or WinWaitActive Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
rupsyco
Posts: 2
Joined: 19 Jul 2020, 22:43

WinActive or WinWaitActive

21 Jul 2020, 03:54

Hi,

tried V2 and I use this simulation software that has 3d visualization that uses mouse in his own way. I had all working fine in V1 but now with V2 the WinActive makes it run either the window is active or not... which messes up scrolling in a portion of the screen. I tried WinWaitActive, but it does the same thing... might have something wrong in the script, thus I'm placing it below.

Thanks,
Ric

Code: Select all

;#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#InstallKeybdHook
#InstallMouseHook
#Warn  ; Enable warnings to assist with detecting common errors.
SendMode "Input"  ; Recommended for new scripts due to its superior speed and reliability.
;SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
CoordMode "Mouse", "Screen"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;              COMSOL 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;if WinActive("ahk_exe comsol.exe")
if WinWaitActive("ahk_exe comsol.exe")
{
	` & F2::
	{
		MouseClick "left", 679, 64
		Sleep 223
		MouseClick "left", 2380, 141
		Sleep 334
		Send "{Enter}"
		Sleep 345
		MouseClick "left", 767, 62
		Sleep 334
		MouseClick "left", 1654, 132
		Sleep 345
		Send "{Enter}"
		Sleep 2111
		MouseClick "left", 55, 59
		Sleep 345
		MouseClick "left", 55, 345
		Sleep 345
	}

	RButton::
	{
		MouseGetPos xpos, ypos, id, control
		if xpos > 984 ;1500
		{
			Send "{Click, WheelUp}"
		}
		if xpos <= 984 ;1500
		{
			Send "{Click, right}"
		}
	}
	+RButton::Send "{Click, WheelDown}"
	
	^MButton::Send "{Click, down, right}"

	;+MButton::MButton

	MButton::LButton

	WheelDown::
	{
		MouseGetPos xpos, ypos, id, control
		if (xpos > 984 and ypos < 863)
		{
;			DetectHiddenWindows True								;Send a Pause command to another script.
;			WM_COMMAND := 0x111
;			ID_FILE_PAUSE := 65403
;			PostMessage WM_COMMAND, ID_FILE_PAUSE,,, "C:\Users\balistreriric\$Apps\pushmouse.ahk ahk_class" AutoHotkey
			Send "{Click, down, middle}"
			shifto := ypos - 40
			MouseMove xpos, shifto, 100
			Send "{Click, up, middle}"
			MouseMove xpos, ypos, 100
		}
		else
		{
			Send "{Click, WheelDown}"
		}
	}
	WheelUp::
	{
		MouseGetPos xpos, ypos, id, control
		if (xpos > 984 and ypos < 863)
		{
			MouseGetPos xpos, ypos, id, control
			Send "{Click, down, middle}"
			shifto := ypos + 40
			MouseMove xpos, shifto, 100
			Send "{Click, up, middle}"
			MouseMove xpos, ypos, 100
		}
		else
		{
			Send "{Click, WheelUp}"
		}
	}
Return
}
Else
{
Return
}
User avatar
Ragnar
Posts: 613
Joined: 30 Sep 2013, 15:25

Re: WinActive or WinWaitActive  Topic is solved

21 Jul 2020, 07:44

You can't make hotkeys conditional like that. Use the #HotIf directive instead, e.g. #HotIf WinActive("ahk_exe comsol.exe").
rupsyco
Posts: 2
Joined: 19 Jul 2020, 22:43

Re: WinActive or WinWaitActive

22 Jul 2020, 02:01

Thanks Ragnar, works good now

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: doodles333 and 43 guests