Ctrl+Enter jQuery in TEXTAREA

HP. picture HP. · Nov 5, 2009 · Viewed 60.6k times · Source

How do I trigger something when the cursor is within TEXTAREA and Ctrl+Enter is pressed? Using jQuery. Thanks

Answer

Yaroslav Yakovlev picture Yaroslav Yakovlev · Feb 18, 2012

Actually this one does the trick and works in all browsers:

if ((event.keyCode == 10 || event.keyCode == 13) && event.ctrlKey)

link to js fiddle.

Notes:

  • In Chrome on Windows and Linux, enter would be registered as keyCode 10, not 13 (bug report). So we need to check for either.
  • ctrlKey is control on Windows, Linux and macOS (not command). See also metaKey.