javascript - How to tell if key is held down at click -
this question has answer here:
i want able tell if user holding down "shift" key (or key, really) when user clicks something.
i'm able tell if user clicks (by using .click() method on element in directive) , if user presses key, can't figure out how tell if user holding down key @ click time in angular.
any appreciated.
try use ngkeydown directive. calling on view this.
ng-keydown="myfunct($event)"
myfunct this.
$scope.myfunct = function(keyevent) { if (keyevent.which === 16) {// 16 == shift. guess; $scope.shift_is_been_pressed = true; } }
so. same ngkeyup directive.
ng-keyup="myfunct($event)" $scope.myfunct = function(keyevent) { if (keyevent.which === 16) {// 16 == shift. guess; $scope.shift_is_been_pressed = false; } }
now, able use shift_is_been_pressed determine if shift been pressed or not.
Comments
Post a Comment