EVENT_PLAYER_MOUSE_MOVE
- comment
Event is triggered when player moves mouse cursor within the game window.
The event and cursor position is synchronized between all players.
- bug
(confirmed v2.0.3.23175) Mouse events crash when registered and used during map initialization. The crash is highly irregular, happens after loading screen finishes and takes many attempts to reproduce with 8 people in a lobby. Recommendation: Delay all mouse event registration until after the game starts.
- bug
(tested v2.0.4.23546) Mouse move event is also triggered when any of the 5 mouse buttons is released (button up) even when not moved:
mouseMove_t = CreateTrigger() mouseMove_p = GetLocalPlayer() -- for testing only otherwise desync! mouseMove_e = TriggerRegisterPlayerEvent(mouseMove_t, mouseMove_p, EVENT_PLAYER_MOUSE_MOVE) mouseMove_func = function() local mx,my = BlzGetTriggerPlayerMouseX(), BlzGetTriggerPlayerMouseY() print("MOUSE_MOVE Pos: ".. mx ..",".. my ..", ".. (os.date and os.date("%H:%M:%S") or "n/a")) end mouseMove_a = TriggerAddAction(mouseMove_t, mouseMove_func)- note
Example (Lua, 2.0.3):
-- Creates a unit and makes it follow your cursor position on map followMouse_player = Player(0) -- red followMouse_unit = nil if followMouse_t then -- clean up if run multiple times DestroyTrigger(followMouse_t) followMouse_t = nil end followMouse_func = function() if not followMouse_unit then followMouse_unit = CreateUnit(followMouse_player, FourCC("Otch"), -100, 0, 90) end local unit = followMouse_unit local mx,my = BlzGetTriggerPlayerMouseX(), BlzGetTriggerPlayerMouseY() local loc = BlzGetTriggerPlayerMousePosition() local locx, locy, locz = GetLocationX(loc), GetLocationY(loc), GetLocationZ(loc) SetUnitX(unit, mx); SetUnitY(unit, my) print(string.format( "MousePos: \x25.2f,\x25.2f; loc=\x25.2f,\x25.2f,\x25.2f;\x25s", mx, my, locx, locy, locz, tostring(loc) )) RemoveLocation(loc) end followMouse_t = CreateTrigger() followMouse_e = TriggerRegisterPlayerEvent(followMouse_t, followMouse_player, EVENT_PLAYER_MOUSE_MOVE) followMouse_a = TriggerAddAction(followMouse_t, followMouse_func)- note
See:
BlzGetTriggerPlayerMouseX,BlzGetTriggerPlayerMouseY,BlzGetTriggerPlayerMousePosition- patch
1.29.0.8803
- Source
- common.j (raise an issue to discuss on Github or submit a PR)
- Source code
constant playerevent EVENT_PLAYER_MOUSE_MOVE = ConvertPlayerEvent(307)