Tooltip not showing, number pad not sending

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
SmithyZoomZoom
Posts: 113
Joined: 23 Aug 2019, 23:32

Tooltip not showing, number pad not sending

22 May 2024, 16:09

This subroutine is part of a larger script. All I want the script to do when I hit X button 1 is to look for the Dragon NaturallySpeaking microphone icon that's in my system tray and if it doesn't find the graphic I'll look one more time and as soon as it finds the graphic send the number pad slash key. Instead, it's clicking on the graphic, which still does what I want the program to do but in a more roundabout way. It would be more seamless if I could get it to just send the / key. I've been fiddling around with ChatGPT plus and Claude all day to get this working… It should be noted that I'm using the findclick library to simplify regular image search.

Code: Select all

  XButton1_QuickPress:
  If (IsSuspended) 
      Return
  
  ImagePath := A_MyDocuments "\autoHotkey_green_dragon_working.png" ; Silence.
  
  ; Store original mouse position
  MouseGetPos, OrigX, OrigY  
  
  ; Loop to check for image twice
  Loop, 2
  {
      FoundX := FindClick(ImagePath, "o80", "n0") 
  
      if (FoundX)
      {
           Tooltip, Image Found! Clicking Image ; Leftover error-checking.
          
          ; Click, %FoundX% ; This is what I would use if I wanted to click the image that the image search found but I disabled it because I needed to send a keyboard command
          Sleep, 100
          ;Send {NumpadDiv} ; Send slash key on the number pad
          Sleep, 100
  
          ; Return mouse to original position 
          MouseMove, %OrigX%, %OrigY% 
          break ; Exit the loop as the image has been found and action has been taken
      }
      Sleep, 250 ; Wait for 500 milliseconds before checking again
  }
  
  ; Proceed with quick press code even if image not found
  ToolTip, ===> Activate Whisperer <===
  SetTimer, ClearToolTip, -500
  ; Send {Alt Down}{Shift Down}{;}
  Send {F24 Down}
  Sleep 50
  KeyWait XButton1
  ;Send {Alt Up}{Shift Up}
    Send {F24 Up}
  SoundBeep 1000
  
  Return
  
Now, you might be saying that it looks like the line responsible for sending the numberpad / is commented out. But it doesn't matter whether I leave it in or take it out. Also, the tooltip that is not working is the one that says image found, left over error checking. This seems like it should be so simple. I would appreciate any responses. Thank you.
User avatar
boiler
Posts: 17384
Joined: 21 Dec 2014, 02:44

Re: Tooltip not showing, number pad not sending

22 May 2024, 18:08

The ToolTip would work if it found the image. The part you should be troubleshooting is whether if finds the image. Start with a simple script of a few lines long and make sure it finds the image before you put a lot of other things around it that make it harder isolate the issue.

Btw, this is not the correct way to specify more than one option:

Code: Select all

FoundX := FindClick(ImagePath, "o80", "n0")

The options all go in the same string in the second parameter. You put the "n0" where it doesn't belong. Not that it is causing your issue, but it wouldn't allow it to recognize your other option since it's not in the right place. It should be:

Code: Select all

FoundX := FindClick(ImagePath, "o80 n0")

And your variable name FoundX implies you are getting back the x value of the found location. It returns a string with both the x and y coordinates separated by a comma.
SmithyZoomZoom
Posts: 113
Joined: 23 Aug 2019, 23:32

Re: Tooltip not showing, number pad not sending

22 May 2024, 18:32

boiler wrote:
22 May 2024, 18:08
The ToolTip would work if it found the image. The part you should be troubleshooting is whether if finds the image. Start with a simple script of a few lines long and make sure it finds the image before you put a lot of other things around it that make it harder isolate the issue.

Btw, this is not the correct way to specify more than one option:

Code: Select all

FoundX := FindClick(ImagePath, "o80", "n0")

The options all go in the same string in the second parameter. You put the "n0" where it doesn't belong. Not that it is causing your issue, but it wouldn't allow it to recognize your other option since it's not in the right place. It should be:

Code: Select all

FoundX := FindClick(ImagePath, "o80 n0")

And your variable name FoundX implies you are getting back the x value of the found location. It returns a string with both the x and y coordinates separated by a comma.
Thank you. Your correction solved my problem. It was clicking when it wasn't supposed to because I was not specifying the parameters in the correct way. This is the working version of the subroutine:

Code: Select all

XButton1_QuickPress:
  If (IsSuspended)
      Return

  ImagePath := A_MyDocuments "\autoHotkey_green_dragon_working.png"
  
  ; Store original mouse position
  MouseGetPos, OrigX, OrigY  
  
  ; Loop to check for image twice
  attempts := 2
  Found := False
  while (attempts > 0) {
      FoundX := FindClick(ImagePath, "o80 n0") 
  
      if (FoundX) {
          ToolTip, Image Found! Sending key press
          Sleep, 1000 ; Display tooltip for 1 second
          
          ; Click, %FoundX% ; This is commented out as per your requirement
          Sleep, 25
          SendInput {NumpadDiv} ; Send slash key on the number pad
        
          ; Return mouse to original position 
          MouseMove, %OrigX%, %OrigY%
          Found := True
          break ; Exit the loop as the image has been found and action has been taken
      } else {
          ToolTip, Image not found on attempt %attempts%
          Sleep, 500 ; Display tooltip for debugging
      }
      attempts--
      Sleep, 250 ; Wait for 250 milliseconds before retrying
  }
  
  if (!Found) {
      ToolTip, Image not found. Proceeding with quick press code
      SetTimer, ClearToolTip, -500
  }
  
  ; Proceed with quick press code even if image not found
  ToolTip, ===> Activate Whisperer <===
  SetTimer, ClearToolTip, -500
  Send {F24 Down}
  Sleep 50
  KeyWait XButton1
  Send {F24 Up}
  SoundBeep 1000
  
  Return

You are my hero. This problem has slightly annoyed me for the past two years. Thank you!
User avatar
CoffeeChaton
Posts: 44
Joined: 11 May 2024, 10:50

Re: Tooltip not showing, number pad not sending

22 May 2024, 19:57

https://www.autohotkey.com/docs/v2/lib/_Warn.htm

I don't know where you defined it FindClick()
But from the previous discussion, it can be seen that you are trying to stuff too many parameters into a function.
I think this command can help you point out the error immediately before running the ahk script.

Code: Select all

#Warn All, MsgBox
foo(1,2,3)

foo(a, b) {
    MsgBox, % "a is" a
    MsgBox, % "b is" b
}

ahk will show it
---------------------------
Error: Too many parameters passed to function.

Specifically: foo(1,2,3)

Line#
---> 002: foo(1,2,3)
004: {
005: MsgBox,"a is" a
006: MsgBox,"b is" b
007: }
008: Exit

The program will exit.
---------------------------
User avatar
boiler
Posts: 17384
Joined: 21 Dec 2014, 02:44

Re: Tooltip not showing, number pad not sending

22 May 2024, 21:24

CoffeeChaton wrote: …it can be seen that you are trying to stuff too many parameters into a function.
That’s not what happened here. He didn’t have too many parameters for that function, which is why it didn’t produce an error. He split one of the parameters that should have been one string in the same parameter across two parameters, and that other parameter he mistakenly filled (and another that follows it) is an optional parameter that can be left blank.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], bobstoner289 and 204 guests