halilcakar
halilcakar

Reputation: 1648

How can i capture Keyboard and Mouse events at same time AS3

When i watch some video's about starling i saw a triggered event. That event capture both keyboard and touch events.

I wonder is there any way to capture Mouse and Keyboard Events at the same time ?

You can check this video for an example: https://vimeo.com/109564325

Upvotes: 0

Views: 480

Answers (2)

Gerrit Bertier
Gerrit Bertier

Reputation: 4221

Can't you add listeners for both keyboard and mouse events, and call a shared 'handler' from there on?

...

stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
stage.addEventListener(MouseEvent.CLICK, clickHandler);

private function clickHandler(e:MouseEvent):void {
   inputHandler(e, 'mouse');
}

private function keyDownHandler(e:KeyboardEvent):void {
   inputHandler(e, 'keyboard');
}

private function inputHandler(e:Event, type:String):void {
   // Do logic here
}

Upvotes: 1

Mark Dolbyrev
Mark Dolbyrev

Reputation: 2007

In my experience, usually, it might be done with implementing some common used InputManager, which can save information about pressed keys/mouse buttons and other classes might get this information through methods, something like:

checkIfKeyPressed(keyCode:int):boolean
{
}

Also, if you need to know about only some specific keys (e.g. alt, ctrl, cmd, shift, etc.), there are some public properties in the MouseEvent objects, which can help you (e.g. altKey, ctrlKey, shiftKey, etc.). See: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/MouseEvent.html

Upvotes: 1

Related Questions