最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

onkeyup - Cmd Enter keyup combination detection using javascript - Stack Overflow

matteradmin8PV0评论

I'm using a keyup detection into all my forms to detect the enter button. This is easy, when you are focused in a form's input if you hit enter and the event keyCode is equal to 13 then the form submitted.

But now I want to detect the Cmd + Enter bination, because when you are focused in a textarea, the enter button is a line break. So how my detect statement should look like?

Thank you

I'm using a keyup detection into all my forms to detect the enter button. This is easy, when you are focused in a form's input if you hit enter and the event keyCode is equal to 13 then the form submitted.

But now I want to detect the Cmd + Enter bination, because when you are focused in a textarea, the enter button is a line break. So how my detect statement should look like?

Thank you

Share Improve this question asked Feb 20, 2012 at 16:09 Andrew KordampalosAndrew Kordampalos 4231 gold badge7 silver badges11 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

You mean ctrl with Cmd? Then check if event.ctrlKey is true:

if (event.ctrlKey && event.keyCode == 13) {
    alert('now');
}

Also see this example.

P.s: there are also the booleans event.altKey for alt, event.shiftKey for shift and event.metakey

Post a comment

comment list (0)

  1. No comments so far