Cmd Enter keyup combination detection using javascript

谁都会走 提交于 2019-12-06 14:29:24

问题


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 combination, 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


回答1:


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



来源:https://stackoverflow.com/questions/9364338/cmd-enter-keyup-combination-detection-using-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!