Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Detect Mouse Hover


  • Please log in to reply
5 replies to this topic
DJxxMidnight
  • Members
  • 3 posts
  • Last active: Dec 08 2011 06:13 PM
  • Joined: 08 Dec 2011
Hi guys, I havn't coded in a VERY long time since highschool but i'm trying to write a program where it detects my mouse hovering over an icon and the mouse "changes" to the hand with the finger pointed. Is there a way to do that?

I tried reading the Auto/Raise and other stuff on mouse hover thread but it's a bit complicated to understand and i'm not too sure if what I want is actually there.

Can anyone help me with this? TY in advance.

Thread with mouse hover
<!-- m -->http://www.autohotke...pic.php?t=22763<!-- m -->

jpjazzy
  • Members
  • 800 posts
  • Last active: Dec 17 2014 07:22 AM
  • Joined: 16 Feb 2010

A_Cursor - The type of mouse cursor currently being displayed. It will be one of the following words: AppStarting, Arrow, Cross, Help, IBeam, Icon, No, Size, SizeAll, SizeNESW, SizeNS, SizeNWSE, SizeWE, UpArrow, Wait, Unknown. The acronyms used with the size-type cursors are compass directions, e.g. NESW = NorthEast+SouthWest. The hand-shaped cursors (pointing and grabbing) are classified as Unknown.

Known limitation on Windows 95: If this variable's contents are fetched repeatedly at a high frequency (i.e. every 500 ms or faster), it will probably disrupt the user's ability to double-click. There is no known workaround.


You said the cursor changes, so use that within an if statement and a timer or loop to check it.
AutoHotkey Basic - Windows 7
Posted Image

DJxxMidnight
  • Members
  • 3 posts
  • Last active: Dec 08 2011 06:13 PM
  • Joined: 08 Dec 2011
thats the thing I dunno how to do the check for that. How do u let the script know to check if the cursor changes from a pointer to a hand with the finger?

jpjazzy
  • Members
  • 800 posts
  • Last active: Dec 17 2014 07:22 AM
  • Joined: 16 Feb 2010
You can check the cursor with this:

#Persistent ; Used so the script does not exit
SetTimer, CheckCursor, 20 ; Turns on a timer which will display your cursor every 20 milliseconds in a tooltip

CheckCursor: ; Displays the cursor in a tooltip
ToolTip, Your cursor is %A_Cursor%.
return

Esc::ExitApp ; Exits the application

Once you know the cursor you need you use an if statement to determine if a cursor is a certain icon. Example:

If (A_Cursor = "IBeam")
{
; Run this code
}

If you need too, you can also use hCursor and GetCursorInfo, but I would try to avoid that if you can because I doubt you wish to spend a while learning how to use DLL calls properly.
AutoHotkey Basic - Windows 7
Posted Image

Alpha Bravo
  • Members
  • 1687 posts
  • Last active: Nov 07 2015 03:06 PM
  • Joined: 01 Sep 2011
I found this a while ago
Gui, add, button,,button1

Gui, add, button,,button2

Gui, add, text,,text

Gui, show,w200, AHK Rocks



OnMessage(0x200, "MsgHandler")

return



MsgHandler(wParam, lParam, msg, hwnd)

{

	hhh := DllCall("LoadCursor","Int",0,"Int", 32649,"Uint")

	MouseGetPos,,,,Control

	;~ ToolTip % control

	

	if Control in Button1,Button2,static1

		DllCall("SetCursor","UInt",hhh)

	

	if  (control = "Button1") 

	ToolTip, this is Button1

	

	else if  (control = "Button2") 

	ToolTip, this is Button2

	

	else if  (control = "static1") 

	ToolTip, this is text1

	

	else 

		ToolTip

}

return



GuiClose:

#X::

ExitApp


DJxxMidnight
  • Members
  • 3 posts
  • Last active: Dec 08 2011 06:13 PM
  • Joined: 08 Dec 2011
Thanks for both the replies, the last one might be a bit too heavy on coding for me to understand. but the first one I will definitely give it a shot tomorrow when I get the time to code.