Reputation: 77
**How to write code in actionscript 3 using combinations of keys for example: If I press the key combination Ctrl + A, then `trace("You pressed the key combination Ctrl + A "); or Ctrl+B
trace("You pressed key combination of Ctrl+B");
Upvotes: 0
Views: 2121
Reputation: 9897
//add global keyboard listener somewhere in init section
stage.addEventListenter(KeyboardEvent.KEY_DOWN, onKeyDown);
function onKeyDown(event:KeyboardEvent):void
{
if (event.keyCode == 65 && event.ctrlKey)
{
trace("You pressed Ctrl-A");
}
}
Ctrl, alt and shift keys are special case, their status is sent with every keyboard event. If you need to detect something like A + Enter, you need to track pressed and released keys in an array (or vector.)
Upvotes: 3