Cursor/Mouse API help

tl;dr: Is there a wow api that will return what the mouse pointer type is that works in combat? Is it the “sword” icon that appears when I mouse over an enemy I can attack or anything else? GetCursorInfo() doesn’t do this.

I’m trying to get some code to work when I mouseover an enemy unit, have it show its name in a box so I can more clearly identify the unit but I’m running into an order of events situation that ends up leaving the text on the screen even when my mouse isn’t over a unit anymore. I think I can resolve this if there was an API to tell me if mouse cursor was the “sword” (which appears when I hover a unit that I can attack) or it’s default “gauntlet” (or anything but the sword), but I can’t seem to find an API for that.

The two events that seem applicable are: UPDATE_MOUSEOVER_UNIT (no payload/parameters) and CURSOR_UPDATE (also no payload).
NOTE: CURSOR_CHANGED only applies to when I pick up or interact with objects.

The problem is that UPDATE_MOUSEOVER_UNIT is only triggered when I move my mouse over a unit’s body or the unit’s nameplate but not when I move the mouse off the unit. CURSOR_UPDATE is triggered when I move the mouse over the unit’s body (but not nameplate) and when I move off the unit but it occurs before UnitExists(“mouseover”) becomes false (that’s actually not a bug but in its documentation as how its supposed to work).

Using /eventtrace there doesn’t seem to be any other events triggered during the mouse movement that I can use. I could use CURSOR_UPDATE if there was an API that returned what the cursor type was, but the only I found, GetCursorInfo, is for something else.

Regardless of intent. The code is most likely protected to help stop botting.
Reverse engineering is not allowed as well.
Have fun.

I have a workaround by handling COMBAT_LOG_EVENT_UNFLITERED as well as UPDATE_MOUSEOVER_UNIT AND CUSOR_UPDATE. It’s just less efficient than I want. I wouldn’t need to handle CLEU if I could find the API I needed.

I have a solution for you.

local function MouseOverName(unitID, unitExists)
    <insert your frame code here for displaying/hiding mouseover name>
end

In your “PLAYER_ENTERING_WORLD” event handler add this line.

    C_Timer.NewTicker(0.1, MouseOverName('mouseover', UnitExists('mouseover'))

That’ll check every 1/10th of a second and call your display routine with the information you’ll need to either display the frame with the unit name at your cursor or hide it - I think.

Obviously I haven’t tested this because I don’t have the rest of your addon to work with, but this is how I get around the “no UPDATE_NOMOUSEOVER_UNIT event” issue in some of my code.

It seems to me that you could make this a bit more efficient by tracking what you currently have for a mouseover unit (even if it’s “none”) and testing before you make the call, but that might not really matter.

If your frame creates on first call and only hides or updates the name on “I have a valid (that I care about) mouseover unit” and hides otherwise, this may already be as good as it gets.

If you want to be able to CANCEL that timer, replace the line I gave you with this:

    local myTimer = C_Timer.NewTicker(0.1, MouseOverName('mouseover', UnitExists('mouseover'))

Then myTimer.Cancel() will shut it off.

1 Like
local f = CreateFrame("Frame")
f:RegisterEvent("UPDATE_MOUSEOVER_UNIT")
f:SetScript("OnEvent", function(self, event, ...)
	if UnitIsPlayer("mouseover") then
		local name = UnitName("mouseover")
		print(name)
	end
end)

Assumes you’re lookinig for Player units but can be addapted for others.

You would probably want to use a timer to fade/hide the “tooltip” after a certain time if not reset with a new unit rather than a “mouse leaving” because that would be unpredictable with mouse/unit movment creating fit enducing flickler.

1 Like

Those are useful tries but they don’t work as well as my current workaround so I’ll just stay where I’m at. Thanks though.