0

I would like to save a message when user press ctrl and enter at the same time, here is my code

if (e.ctrlKey && e.keyCode == 13)
{
    e.preventDefault();
    saveMessage();
}       

<textarea placeholder="Add a note..." id="note-content" ng-model="noteContent" ng-keyup="triggerform($event)"></textarea>

It works however, it would keep create a extra enter at the end of line which is trigger by the enter key, is there a way i can prevent the enter?

cweiske
  • 30,033
  • 14
  • 133
  • 194
Bill
  • 17,872
  • 19
  • 83
  • 131

1 Answers1

1

You should use ng-keypress instead of ng-keyup.

keydown vs keyup vs keypress

In order to understand the difference between keydown and keypress, it is useful to understand the difference between a "character" and a "key". A "key" is a physical button on the computer's keyboard while a "character" is a symbol typed by pressing a button. In theory, the keydown and keyup events represent keys being pressed or released, while the keypress event represents a character being typed. The implementation of the theory is not same in all browsers.

Community
  • 1
  • 1
Krab
  • 6,526
  • 6
  • 41
  • 78