if in object().value not working

Get help with using AutoHotkey 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: 1448
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: 3987
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: 2984
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”

Who is online

Users browsing this forum: Bing [Bot], BreezeB, flyingDman, Gully, mehrez1989, peanutym, SuperFoobar, teadrinker, toralf and 202 guests