How to detect pressed keys on the click of AngularJS

Flavio Oliveira picture Flavio Oliveira · May 14, 2014 · Viewed 35.3k times · Source

I'm using angularjs on a web application that I need to figure out how can I detect is keys like ctrl, shift or alt are pressed when I click somewhere.

For example, with jQuery I can do that by accessing the Click function arguments.

Is there some out-of-the-box way to obtain that information on angular?

Answer

Flavien Volken picture Flavien Volken · Apr 23, 2015

In your html

<button ng-click="doSomething($event)"></button>

In your js

$scope.doSomething = function($event)
{
if ($event.altKey){}
if ($event.ctrlKey){}
if ($event.shiftKey){}
}