Addons cannot cast spells or cancel a spell cast. Those (and a number of other) actions
require both a hardware event (key press or mouse click)
and a secure code path (either by invoking the action through the default UI without any addon being involved, or by using one of the secure templates provided by Blizzard, which are subject to the same restrictions as macros).
See also:
Things Addons/Macros Can't Do (sticky thread in the Addon Requests forum)