Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ctrl+Enter jQuery in TEXTAREA

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

like image 572
HP. Avatar asked Nov 05 '09 22:11

HP.


1 Answers

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.
like image 85
Yaroslav Yakovlev Avatar answered Oct 26 '22 09:10

Yaroslav Yakovlev