if in object().value not working

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
mtschwrz
Posts: 1
Joined: 27 Aug 2019, 18:30

if in object().value not working

27 Aug 2019, 18:46

Hello,

New to the forum.

I'm writing a script that constantly needs to know what window is under the mouse cursor. First I wrote a sub routine. But, since I want to improve my scripting skills, I started creating an object instead of a subroutine.

This is the object:

Code: Select all

WindowUnderMouse() {
    MouseGetPos , , , ID
    WinGetTitle Title, ahk_id %ID%
    WinGet, Process, ProcessName, ahk_id %ID%
    WinGetPos, , , WX, WY, ahk_id %ID%
	Return {Title:Title, Process:Process, WX:WX, WY:WY, ID:ID}
}
When I try to get info from it like this:

Code: Select all

if (WindowUnderMouse().Process = "notepad.exe")
{
    MsgBox Yes
}
else
{
    MsgBox No
}
It works like a charm.

But if I try to do this instead:

Code: Select all

if ("notepad.exe" in WindowUnderMouse().Process)
{
    MsgBox Yes
}
else
{
    MsgBox No
}
return
it doesn't work.

Someone has any workaround?
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: if in object().value not working

27 Aug 2019, 19:29

Code: Select all

WindowUnderMouse() {
    MouseGetPos , , , ID
    WinGetTitle Title, ahk_id %ID%
    WinGet, Process, ProcessName, ahk_id %ID%
    WinGetPos, , , WX, WY, ahk_id %ID%
	Return {"Title":Title, "Process":Process, "WX":WX, "WY":WY, "ID":ID}
}
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: if in object().value not working

28 Aug 2019, 01:06

in cannot be used in an expression, see :arrow: if var in

Cheers.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: if in object().value not working

28 Aug 2019, 02:34

Code: Select all

if InStr(WindowUnderMouse().Process, "notepad.exe")

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, Google [Bot], WAZAAAAA and 415 guests