Hotkey within IF clause?

Get help with using AutoHotkey and its commands and hotkeys
scriptor2016
Posts: 515
Joined: 21 Dec 2015, 02:34

Hotkey within IF clause?

24 Aug 2019, 01:58

Hi, how do I create a new hotkey inside an if clause? For example, this is my code:

Code: Select all

#Persistent
SetTimer, WatchCursor, 100
return

WatchCursor:

SetTitleMatchMode, 2
MouseGetPos, , , id, control
WinGetTitle, title, ahk_id %id%
WinGetClass, class, ahk_id %id%


if title contains MyWindow  
{
RButton::
Msgbox, Right Button
}
else
{
tooltip, keep searching...
}
return
 
How do I do this so that the RButton will show the messagebox *only* when the wintitle under the cursor contains MyWindow?
Odlanir
Posts: 532
Joined: 20 Oct 2016, 08:20

Re: Hotkey within IF clause?

24 Aug 2019, 02:56

Code: Select all

#if (title ~= "MyWindow") ; ~= is a shorthand for RegExMatch
   RButton::
      MsgBox, Right Button
   return
#If
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
scriptor2016
Posts: 515
Joined: 21 Dec 2015, 02:34

Re: Hotkey within IF clause?

24 Aug 2019, 03:09

thanks Odlanir!!! This will be perfect :)
scriptor2016
Posts: 515
Joined: 21 Dec 2015, 02:34

Re: Hotkey within IF clause?

24 Aug 2019, 13:39

well that's strange. This was working perfectly last night but today it just stopped working.

Right clicking acts as normal now, it does not show the messagebox.


Is there anything wrong with this code?

Code: Select all


#if (title = "Untitled - Notepad") ; ~= is a shorthand for RegExMatch
   RButton::
      MsgBox, Right Button
   return
#If
gregster
Posts: 3254
Joined: 30 Sep 2013, 06:48

Re: Hotkey within IF clause?

24 Aug 2019, 13:44

The ~ of ~= is missing in your code.

( ~= is a shorthand for RegExMatch )
scriptor2016
Posts: 515
Joined: 21 Dec 2015, 02:34

Re: Hotkey within IF clause?

24 Aug 2019, 13:50

believe it or not, it still isn't working

it was running perfectly last night and this morning it just stopped . I've closed all other scripts to troubleshoot and no dice - a right click just acts normally when ontop of the untitled notepad window.

here it is again,

Code: Select all

#if (title ~= "Untitled - Notepad") ; ~= is a shorthand for RegExMatch
   RButton::
      MsgBox, Right Button
   return
#If
gregster
Posts: 3254
Joined: 30 Sep 2013, 06:48

Re: Hotkey within IF clause?

24 Aug 2019, 14:09

It is believable. title still needs to be determined somehow (you used a timer in your original script) - I don't see how you do it in your new script.

Please post your complete script, if in doubt. (If this is already your complete script, it cannot work - that's clear.)

You could try:

Code: Select all

#if IsWintitle("Untitled - Notepad")
   RButton::
      MsgBox, Right Button
   return
#If

IsWintitle(title){
	SetTitleMatchMode, 2			; or some other mode 
	MouseGetPos, , , id
	WinGetTitle, wintitle, ahk_id %id%
	return (title = wintitle) ? true : false	; or just:      return (title = wintitle)
}
scriptor2016
Posts: 515
Joined: 21 Dec 2015, 02:34

Re: Hotkey within IF clause?

25 Aug 2019, 02:40

gregster - thanks - its working now.

I think I changed something along the lines overnight which caused this to stop working. I've got it going now. I'll revisit this topic if I run into other problems :)

Return to “Ask For Help”

Who is online

Users browsing this forum: asad41163, BreezeB, kentpachi, malcev, RogerWilcoNL, Zudegia, zvit and 213 guests