How to ignore mouse cursor in image search

Ask gaming related questions (AHK v1.1 and older)
Fbc
Posts: 11
Joined: 01 Aug 2021, 00:39

How to ignore mouse cursor in image search

04 Aug 2021, 17:26

Has something that I can do with my code to my image search ignore my mouse cursor, if it goes in front of my image, that I'm searching? My image is small and sometimes when my cursor is ahead of it, the image search can't find it anymore.

[Mod edit: Topic moved to 'Gaming'.]
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: How to ignore mouse cursor in image search

04 Aug 2021, 17:36

Fbc wrote:
04 Aug 2021, 17:26
Has something that I can do with my code to my image search ignore my mouse cursor, if it goes in front of my image, that I'm searching? My image is small and sometimes when my cursor is ahead of it, the image search can't find it anymore.
It's likely not an issue with your cursor, but rather a problem with the image changing when you mouse over it.

Like this for example:
Temp (1).gif
(23.78 KiB) Downloaded 191 times
Fbc
Posts: 11
Joined: 01 Aug 2021, 00:39

Re: How to ignore mouse cursor in image search

04 Aug 2021, 21:58

Hellbent wrote:
Fbc wrote:
04 Aug 2021, 17:26
Has something that I can do with my code to my image search ignore my mouse cursor, if it goes in front of my image, that I'm searching? My image is small and sometimes when my cursor is ahead of it, the image search can't find it anymore.
It's likely not an issue with your cursor, but rather a problem with the image changing when you mouse over it.

Like this for example:
Temp (1).gif
No. My cursor doesn't change my image. My cursor is bigger than my image that I'm searching, then when my cursor is over my image, the img search can't find it anymore. it isn't something that will happen always, but I would like to have a solution before it can turn into a problem to me.
User avatar
rommmcek
Posts: 1473
Joined: 15 Aug 2014, 15:18

Re: How to ignore mouse cursor in image search

05 Aug 2021, 12:26

Try:

Code: Select all

SystemCursor("Off")
ImageSearch OutputVarX, OutputVarY, X1, Y1, X2, Y2, ImageFile
SystemCursor("On")


;https://autohotkey.com/board/topic/42561-hide-mouse-cursor-when-idle/
SystemCursor(OnOff=1)   ; INIT = "I","Init"; OFF = 0,"Off"; TOGGLE = -1,"T","Toggle"; ON = others
{
    static AndMask, XorMask, $, h_cursor, c, b:= [], h:= [] ; c-sys cur., b-blank cur., h-hwnd of default cur.
    if (OnOff = "Init" || OnOff = "I" || $ = "")         ; init when requested or at first call
    {
        VarSetCapacity(h_cursor,4444, 1), VarSetCapacity(AndMask, 32*4, 0xFF), VarSetCapacity(XorMask, 32*4, 0)
      , system_cursors:= "32512,32513,32514,32515,32516,32642,32643,32644,32645,32646,32648,32649,32650"
      , c:= StrSplit(system_cursors, ","), $:= "h" ; active default cursors
        for i, j in c
            h_cursor   := DllCall( "LoadCursor", "Ptr",0, "Ptr",j )
          , h[i] := DllCall( "CopyImage", "Ptr",h_cursor, "UInt",2, "Int",0, "Int",0, "UInt",0 )
          , b[i] := DllCall( "CreateCursor", "Ptr",0, "Int",0, "Int",0
                                                 , "Int",32, "Int",32, "Ptr",&AndMask, "Ptr",&XorMask )
    }
    $:= (OnOff=0||OnOff="Off"||$="h"&&(OnOff<0||OnOff="Toggle"||OnOff="T"))? "b": "h" ; b-blank cur., h-saved cur.
    for i, j in c
        h_cursor := DllCall( "CopyImage", "Ptr",%$%[i], "UInt",2, "Int",0, "Int",0, "UInt",0 )
      , DllCall( "SetSystemCursor", "Ptr",h_cursor, "UInt",j )
}
Alternatives:
https://www.autohotkey.com/boards/viewtopic.php?f=6&t=92834
https://www.autohotkey.com/boards/viewtopic.php?t=75867
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: How to ignore mouse cursor in image search

05 Aug 2021, 13:24

Fbc wrote:
04 Aug 2021, 21:58
No. My cursor doesn't change my image. My cursor is bigger than my image that I'm searching, then when my cursor is over my image, the img search can't find it anymore. it isn't something that will happen always, but I would like to have a solution before it can turn into a problem to me.
If it cant find it with the mouse over the image its changing whats on the screen.
You may not see it but it doesn't take much when running 0 variation.

You can move the mouse away to 0,0 before performing the ImageSearch.
example:

Code: Select all

CoordMode, Mouse, Screen
MouseMove, 0, 0, 0
Fbc
Posts: 11
Joined: 01 Aug 2021, 00:39

Re: How to ignore mouse cursor in image search

05 Aug 2021, 14:39

Xtra wrote:
05 Aug 2021, 13:24
Fbc wrote:
04 Aug 2021, 21:58
No. My cursor doesn't change my image. My cursor is bigger than my image that I'm searching, then when my cursor is over my image, the img search can't find it anymore. it isn't something that will happen always, but I would like to have a solution before it can turn into a problem to me.
If it cant find it with the mouse over the image its changing whats on the screen.
You may not see it but it doesn't take much when running 0 variation.

You can move the mouse away to 0,0 before performing the ImageSearch.
example:

Code: Select all

CoordMode, Mouse, Screen
MouseMove, 0, 0, 0
Problem is that it's a script that will be running and searching the image for long periods of time. I can't disable my cursor or move to another pixel. If the image shows in the screen the script will do something, but if for any cause my cursor is over there where the image will appear my script will not find it and will not execute my code. What I was thinking was to make my cursor invisible only for the image search, but i think it shouldn't be possible to do that.
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: How to ignore mouse cursor in image search

05 Aug 2021, 19:21

You could also try something like this to keep your cursor away from that spot.

https://www.autohotkey.com/boards/viewtopic.php?f=76&t=69013&p=297586#p297316
Fbc
Posts: 11
Joined: 01 Aug 2021, 00:39

Re: How to ignore mouse cursor in image search

06 Aug 2021, 08:20

Hellbent wrote:
05 Aug 2021, 19:21
You could also try something like this to keep your cursor away from that spot.

https://www.autohotkey.com/boards/viewtopic.php?f=76&t=69013&p=297586#p297316
I was reading the documentation and here they say that cursor is ignored, however gamer cursor doesn't, I think I might set my cursor to use the default cursor not a game cursor and my script is running in a game. Here's what is saying:

"The region to be searched must be visible; in other words, it is not possible to search a region of a window hidden behind another window. By contrast, images that lie partially beneath the mouse cursor can usually be detected. The exception to this is game cursors, which in most cases will obstruct any images beneath them."

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: ppu-pro_Res, Shoobis and 45 guests