AutoHotkey Community

It is currently May 26th, 2012, 3:47 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 15 posts ] 
Author Message
 Post subject: Mouse Icon
PostPosted: April 4th, 2009, 8:19 pm 
Hi.

I need to check if the mouse is using a specific Icon. I found Seans ScreenCapture (http://www.autohotkey.com/forum/topic18 ... eencapture) 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.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 4th, 2009, 8:51 pm 
And by the way, I have tried using ImageSearch, but it looks like it dosn't include the mouse in the search.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 5th, 2009, 7:49 am 
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.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 5th, 2009, 8:04 am 
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 :(

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.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 5th, 2009, 11:19 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 5th, 2009, 12:16 pm 
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?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 5th, 2009, 2:10 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 6th, 2009, 10:26 am 
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.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 6th, 2009, 10:43 am 
Just to be sure.
Did you try the A_Cursor built in var?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 6th, 2009, 1:17 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
You have to set the size yourself. Add after VarSetCapacity
Code:
NumPut(546, ni)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 8th, 2009, 8:11 pm 
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?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 9th, 2009, 9:20 am 
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.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 13th, 2009, 10:39 am 
Maybe something can be used from
http://www.codeguru.com/forum/showthrea ... &p=1181025
Im thinking I can check what the bits are, and if they are something speciel, the cursor must be that special cursor?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 6th, 2009, 10:41 am 
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 !


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 18th, 2009, 7:04 pm 
h::
VarSetCapacity(mi, 20, 0)
mi := chr(20)
DllCall("GetCursorInfo", "Uint", &mi)
hCursor:= NumGet(mi, 8)
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.


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, Exabot [Bot], notsoobvious and 21 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group