• Check out the results of the Techtree Contest #19!
  • Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

Capturing "choose ability target" event

Level 6
Joined
Apr 12, 2026
Messages
18
Hi all, I write a trigger like:
Events
<lacking>
Conditions
Ablility being cast = [some ability]
Actions
For every Unit owned by Triggering player, Blahblahblah
I want this trigger to function when I order the unit to use an ability but has yet chosen a target (like press the key, the pointer appears, but haven't clicked the mouse). Is it at all possible? The "Prepare to cast an ability" event is triggered after I choose the target.
 
I want this trigger to function when I order the unit to use an ability but has yet chosen a target (like press the key, the pointer appears, but haven't clicked the mouse). Is it at all possible? The "Prepare to cast an ability" event is triggered after I choose the target.

Sure. You can do that by registering the action of pressing the skill HotKey button. The event related to that action is
JASS:
BlzTriggerRegisterPlayerKeyEvent
Here's a tutorial on how to use it: Oskey - Player Key Event
 
O_Vazio is correct about the way to register the key but... be warned this may be a difficult 'event' to actually detect properly. I say that because the Oskey event doesn't return any information about which unit the Key was used 'with/for/on'. Imagine the hotkey for the skill is K; when a player presses that key you will have to do something like the following:
  • The event will tell you which player pressed K; call this player P.
  • Find every unit currently selected by P.
  • Check if any of those units are the right unit-type that could cast the spell with hotkey K that you want to find.
  • If any units match unit-type, then that unit probably just had its hotkey invoked but...
    • If there are multiple units of the same type selected by P, there is no way to know which specific unit it was invoked for.
    • If P has selected other unit-types in addition to those found in step 3 above and those unit-types also have a non-instant-cast spell with hotkey K, then there is no way to be sure that P didn't press K to cast some other ability from those other units.
    • If P has selected the correct units that would use this K hotkey but then switched the active units in their selection (clicking on the different unit types in the UI) so that the 'correct' units are not active... you won't know that the hotkey didn't do anything.
There are also a few other major issues to resolve, and while my intuition is that some fuckery with UI Frames could tell you some relevant information I'm not sure it's enough to completely avoid these realities:
  • Any time the player presses K the event will fire. ANY TIME. That includes in chat and for other hotkeys, I believe.
  • Good luck if they type a word using the letter K while selecting a unit that COULD press K hotkey to enter spell targeting, because how could you know?
  • This also includes attempting to press K to open the spell targeting for the correct spell... but the caster is affected by crowd control that prevents casting or it doesn't have enough mana to cast the spell. The player still pressed K... it just didn't do anything.
Many years ago I attempted to build a framework that would allow spell target selection to choose an arbitrary N target points or N target units before the spell was actually cast. I had to detect something like this and then use ForceUIKey() to set up the subsequent casts. While frame natives may now be able to give more precise information, the only way I was ever able to regularly and properly determine that a spell was still in the pre-cast targeting mode was to repeatedly force a different UI key for a hidden ability on a low-timeout timer. If the cast ever went off then I knew the player left the targeting screen, since other hotkeys besides ESC won't work in the targeting screen.

It was a lot of work and didn't really get to an acceptable solution in the end.

I encourage you to think about this thing you're trying to do and see if there is a better way to go about it, like incorporating a spellbook directly or something. Since i think this is related to your other thread?
 
Back
Top