Question

I've managed to get enter keypress to work. But I can't seem to get the "shift" button keypress to work. Here is my code for enter:

<button 
    class="btn btn-primary order-input-add" 
    ui-keypress="{13:'add_plu(order.orderwindow.add_field)'}" 
    ng-click="add_plu(order.orderwindow.add_field)">Add
</button>
Was it helpful?

Solution

Since it seems that you can't capture a shift key press by itself using ui.keydown (if so, probably because it's most often used as a modifier key), you can instead create your own directive that decorates an element to listen for shift on the keydown event:

angular.module('myApp', [])
.directive('captureShift', function(){
  return {
    restrict: 'A',
    link: function(scope, elem, attrs) {
      elem[0].onkeydown = function(){
        console.log('shift pressed');
      }
    }
  }
});

Shift doesn't seem to fire on keypress but does on keydown, so onkeydown is used.

Plunker Demo

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top