AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Mouse Icon

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
IconWatcher
Guest





PostPosted: Sat Apr 04, 2009 7:19 pm    Post subject: Mouse Icon Reply with quote

Hi.

I need to check if the mouse is using a specific Icon. I found Seans ScreenCapture (http://www.autohotkey.com/forum/topic18146.html&highlight=screencapture) In there he captures the screen and you can optionally choose to have the mouse drawn into the picture as well.

I have tried his code below to see if I could find any information that is always the same when a certain Icon is displayed on the Cursor.
At first the hCursor variable seemed good, but I checked it up as a handle, which changes at restart of application or operating system.

Code:
VarSetCapacity(mi, 20, 0)
   mi := Chr(20)
   DllCall("GetCursorInfo", "Uint", &mi)
   bShow   := NumGet(mi, 4)
   hCursor := NumGet(mi, 8)
   xCursor := NumGet(mi,12)
   yCursor := NumGet(mi,16)

   VarSetCapacity(ni, 20, 0)
   DllCall("GetIconInfo", "Uint", hCursor, "Uint", &ni)
   xHotspot := NumGet(ni, 4)
   yHotspot := NumGet(ni, 8)
   hBMMask  := NumGet(ni,12)
   hBMColor := NumGet(ni,16)


Is there a way to check if a certain mouse Icon is being displayed?

I would appreciate it.
Back to top
IconWatcher
Guest





PostPosted: Sat Apr 04, 2009 7:51 pm    Post subject: Reply with quote

And by the way, I have tried using ImageSearch, but it looks like it dosn't include the mouse in the search.
Back to top
IconWatcher
Guest





PostPosted: Sun Apr 05, 2009 6:49 am    Post subject: Reply with quote

No help?

I've been trying to change the call to GetIconInfo to GetIconInfoEx ( http://msdn.microsoft.com/en-us/library/ms648071(VS.85).aspx ) but I can't get it to work. It should include more information and maybe a disk link to the Icon being used.

This is my code I use for testing and is working fine, but there is no value that's always the same when the cursor Icon is the same.
Code:
Loop
{
   Sleep 1000
   VarSetCapacity(mi, 20, 0)
   mi := Chr(20)
   DllCall("GetCursorInfo", "Uint", &mi)
   bShow   := NumGet(mi, 4)
   hCursor := NumGet(mi, 8)
   xCursor := NumGet(mi,12)
   yCursor := NumGet(mi,16)

   VarSetCapacity(ni, 20, 0)
   DllCall("GetIconInfo", "Uint", hCursor, "Uint", &ni)
   xHotspot := NumGet(ni, 4)
   yHotspot := NumGet(ni, 8)
   hBMMask  := NumGet(ni,12)
   hBMColor := NumGet(ni,16)
   
   TrayTip, test, hBMMask = %hBMMask%`nxHotspot = %xHotspot%`nyHotspot = %yHotspot%`nhBMColor = %hBMColor%`nhCursor = %hCursor%`nbShow = %bShow%, 10
}


Then I have tried the following change to the second block of code:
Code:
VarSetCapacity(ni, 28, 0)
   DllCall("GetIconInfo", "Uint", hCursor, "Uint", &ni)
   xHotspot := NumGet(ni, 4)
   yHotspot := NumGet(ni, 8)
   hBMMask  := NumGet(ni,12)
   hBMColor := NumGet(ni,16)
   wResID := NumGet(ni,20)
   szModName := NumGet(ni,24)
   szResName := NumGet(ni,28)
   TrayTip, test, hBMMask = %hBMMask%`nxHotspot = %xHotspot%`nyHotspot = %yHotspot%`nhBMColor = %hBMColor%`nhCursor = %hCursor%`nbShow = %bShow%`nwResID = %wResID%`nszModName = %szModName%`nszResName = %szResName%, 10


Now the Structure I get back should be IconInfoEx ( http://msdn.microsoft.com/en-us/library/ms648053(VS.85).aspx ) instead of IconInfo ( http://msdn.microsoft.com/en-us/library/ms648052(VS.85).aspx ).
I'm no expert using DllCall or understanding msdn, so if someone that have tried this could rig the code to work propperly, it might contain a value that does not change when the mouse Icon is something specific?

I can see that the way I extract information out of the IconInfoEx is wrong since the values are no longer presented in the same way, but I cant figure out how to address this.
Back to top
IconWatcher
Guest





PostPosted: Sun Apr 05, 2009 7:04 am    Post subject: Reply with quote

Trying to figure out why it does not work resulted in some more code that fits better I think. Specially I wanted to call GetIconInfoEx, not GetIconInfo

My code looks as follows, but its genererates alot of zeroes Sad

Code:
   VarSetCapacity(ni, 36, 0)
   DllCall("GetIconInfoEx", "Uint", hCursor, "Uint", &ni)
   cbSize := NumGet(ni, 0)
   fIcon := NumGet(ni, 4)
   xHotspot := NumGet(ni, 8)
   yHotspot := NumGet(ni, 12)
   hBMMask  := NumGet(ni,16)
   hBMColor := NumGet(ni,20)
   wResID := NumGet(ni,24)
   szModName := NumGet(ni,28)
   szResName := NumGet(ni,32)
   TrayTip, test, bShow = %bShow%`nhCursor = %hCursor%`nxCursor = %xCursor%`nyCursor = %yCursor%`ncbSize = %cbSize%`nfIcon = %fIcon%`nxHotspot = %xHotspot%`nyHotspot = %yHotspot%`nhBMMask = %hBMMask%`nhBMColor = %hBMColor%`nwResID = %wResID%`nszModName = %szModName%`nszResName = %szResName%, 10



szModName is characters, so I guess that NumGet is wrong here, same applies to szResName.
Back to top
Sean



Joined: 12 Feb 2007
Posts: 2141

PostPosted: Sun Apr 05, 2009 10:19 am    Post subject: Reply with quote

IconWatcher wrote:
szModName is characters, so I guess that NumGet is wrong here, same applies to szResName.
What OS are you in? GetIconInfoEx exists only in Vista, and likely higher. If Vista, use as the size 546, not 36. BTW, you can't retrieve szModName and szResName using NumGet. It needs would-be StrGet() which doesn't exist yet in current AHK.
Back to top
View user's profile Send private message
IconWatcher
Guest





PostPosted: Sun Apr 05, 2009 11:16 am    Post subject: Reply with quote

Hi Sean

Im running on Windows 7, so it should exist.

How come the size should be 546?

I thought that NumGet would be wrong to use on the char*. Maybe I can just use the paths anyway, but in a numerical form to see if its a specific icon?

Is there any other way to check if a specific Icon is being used? I have used lots of time on the MSDN to find a way but I haven't found anything.

Do you have any ideas?
Back to top
Sean



Joined: 12 Feb 2007
Posts: 2141

PostPosted: Sun Apr 05, 2009 1:10 pm    Post subject: Reply with quote

Quote:
I thought that NumGet would be wrong to use on the char*. Maybe I can just use the paths anyway, but in a numerical form to see if its a specific icon?
Code:
VarSetCapacity(szModName, 260)
VarSetCapacity(szResName, 260)
wResID := NumGet(ni,24,"Ushort")
DllCall("RtlMoveMemory", "str", szModName, "Uint", &ni+ 26, "Uint", 260)
DllCall("RtlMoveMemory", "str", szResName, "Uint", &ni+286, "Uint", 260)
MsgBox % wResID "|" szModName "|" szResName

Quote:
Do you have any ideas?
You got hBMColor and hBMMask, so basically all data of the icon. So, you can do (sort of) PixelSearch/ImageSearch with them.
Back to top
View user's profile Send private message
IconWatcher
Guest





PostPosted: Mon Apr 06, 2009 9:26 am    Post subject: Reply with quote

Hi again

I've tried the following, but all the values are still zero, which I don't understand. And I never get any String values.

Code:
Loop
{
   Sleep 1000
   VarSetCapacity(mi, 20, 0)
   mi := Chr(20)
   DllCall("GetCursorInfo", "Uint", &mi)
   bShow   := NumGet(mi, 4)
   hCursor := NumGet(mi, 8)
   xCursor := NumGet(mi,12)
   yCursor := NumGet(mi,16)

   VarSetCapacity(ni, 546, 0)
   DllCall("GetIconInfoEx", "Uint", hCursor, "Uint", &ni)
   cbSize := NumGet(ni, 0)
   fIcon := NumGet(ni, 4)
   xHotspot := NumGet(ni, 8)
   yHotspot := NumGet(ni, 12)
   hBMMask  := NumGet(ni,16)
   hBMColor := NumGet(ni,20)
   VarSetCapacity(szModName, 260)
   VarSetCapacity(szResName, 260)
   wResID := NumGet(ni,24,"Ushort")
   DllCall("RtlMoveMemory", "str", szModName, "Uint", &ni+ 26, "Uint", 260)
   DllCall("RtlMoveMemory", "str", szResName, "Uint", &ni+286, "Uint", 260)
   
   TrayTip, test, bShow = %bShow%`nhCursor = %hCursor%`nxCursor = %xCursor%`nyCursor = %yCursor%`ncbSize = %cbSize%`nfIcon = %fIcon%`nxHotspot = %xHotspot%`nyHotspot = %yHotspot%`nhBMMask = %hBMMask%`nhBMColor = %hBMColor%`nwResID = %wResID%`nszModName = %szModName%`nszResName = %szResName%, 10
}


Quote:
You got hBMColor and hBMMask, so basically all data of the icon. So, you can do (sort of) PixelSearch/ImageSearch with them.
I have looked into this with the GetIconInfo function. hBMColor is actually always zero in the application I want to check it in. Only hBMMask is given, and the values is changing all the time.

I appreciate your help Sean.
Back to top
Guest++
Guest





PostPosted: Mon Apr 06, 2009 9:43 am    Post subject: Reply with quote

Just to be sure.
Did you try the A_Cursor built in var?
Back to top
Sean



Joined: 12 Feb 2007
Posts: 2141

PostPosted: Mon Apr 06, 2009 12:17 pm    Post subject: Reply with quote

You have to set the size yourself. Add after VarSetCapacity
Code:
NumPut(546, ni)
Back to top
View user's profile Send private message
IconWatcher
Guest





PostPosted: Wed Apr 08, 2009 7:11 pm    Post subject: Reply with quote

Guest++ wrote:
Just to be sure.
Did you try the A_Cursor built in var?


No. Didn't know about that. But its not standard Windows Cursors, so it reports all the cursors as "Unknown". If it was just the one cursor I'm looking for that reported this, then it could be used.

Sean wrote:
You have to set the size yourself. Add after VarSetCapacity
Code:
NumPut(546, ni)

Done that. I still only get zeroes in hBMMask and hBMColor, which wasn't the case with the GetIconInfo function.

It seems like its impossible to get this information?
Back to top
IconWatcher
Guest





PostPosted: Thu Apr 09, 2009 8:20 am    Post subject: Reply with quote

I may have found a way to check if its a specific Icon that's used, but I'm quite unsure.

The function GetDIBits ( http://msdn.microsoft.com/en-us/library/dd144879(VS.85).aspx ) might be usefull. I have no idea how to implement it though.
Back to top
IconWatcher
Guest





PostPosted: Mon Apr 13, 2009 9:39 am    Post subject: Reply with quote

Maybe something can be used from
http://www.codeguru.com/forum/showthread.php?t=346517&p=1181025
Im thinking I can check what the bits are, and if they are something speciel, the cursor must be that special cursor?
Back to top
Samsara
Guest





PostPosted: Wed May 06, 2009 9:41 am    Post subject: Reply with quote

I think your problem is, that your do not have the handler adress to the mouse cursor!

so you get only zeros, because you look at the adress 0x00000000 !
Back to top
Xavin
Guest





PostPosted: Thu Jun 18, 2009 6:04 pm    Post subject: Reply with quote

h::
VarSetCapacity(mi, 20, 0)
mi := chr(20)
DllCall("GetCursorInfo", "Uint", &mi)
hCursor:= NumGet(mi, Cool
msgbox, %hCursor%


Run this, it will retrieve a specific Int value of the cursor u want and you can use that to check changes in the cursor. However, this value changes whenever you close the game or whatever your trying to identify the cursor for.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group