# JavaScript and keyboard shortcuts

**URL:** https://forum.kirupa.com/t/javascript-and-keyboard-shortcuts/638550
**Category:** web dev
**Created:** [July 27, 2018, 7:59pm UTC](https://forum.kirupa.com/t/javascript-and-keyboard-shortcuts/638550 "2018-07-27T19:59:34Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![travis](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/travis/32/13217_2.png) [@travis](https://forum.kirupa.com/u/travis)
#### Post date: [July 27, 2018, 7:59pm UTC](https://forum.kirupa.com/t/javascript-and-keyboard-shortcuts/638550/1 "2018-07-27T19:59:34Z")

</div>

I’ve been scouring the internet all day trying to find an answer, and I believe it’s no but I turn to the trusty old Kirupa forms for the definitive answer.

Is it possible to create a function that is triggered when a user presses Ctrl + F? I’ve created custom keyboard shortcuts with JavaScript before and I’m not trying to disable the find feature I’d just like it to be accompanied by something else.

The specific use case: I have several drop downs on a page with content, when clicked they open up and the content is shown. However when the drop downs are closed the content is not searchable. So I was thinking it would be nice if all the drop downs opened when the user hit Ctrl + F so that everything on the page was searchable.  
I realize there may be more effective ways to do this but I’m implementing this on a fairly closed corporate network so it really has to be a front end solution.

---

<div class="post-metadata">

### Author: ![krilnon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/krilnon/32/34_2.png) [@krilnon](https://forum.kirupa.com/u/krilnon)
#### Post date: [July 27, 2018, 8:28pm UTC](https://forum.kirupa.com/t/javascript-and-keyboard-shortcuts/638550/2 "2018-07-27T20:28:32Z")

</div>

Yes. Listen for keyup and keydown events, then read the events’ key property.

---

<div class="post-metadata">

### Author: ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)
#### Post date: [July 27, 2018, 8:51pm UTC](https://forum.kirupa.com/t/javascript-and-keyboard-shortcuts/638550/3 "2018-07-27T20:51:58Z")

</div>

This tutorial covers how to detect multiple keyboard presses as well: [https://www.kirupa.com/html5/keyboard\_events\_in\_javascript.htm](https://www.kirupa.com/html5/keyboard_events_in_javascript.htm)

---

<div class="post-metadata">

### Author: ![travis](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/travis/32/13217_2.png) [@travis](https://forum.kirupa.com/u/travis)
#### Post date: [July 30, 2018, 1:44pm UTC](https://forum.kirupa.com/t/javascript-and-keyboard-shortcuts/638550/4 "2018-07-30T13:44:07Z")

</div>

Oh duh! Thanks you two. I was using the “keypress” listener vs “keydown” so I couldn’t get the Ctrl to work.
