title: Custom React Hook on Ctrl+S keydown
body: <p>I do apologise in advance as I'm still new to ReactJS. I'm fooling around with eventListeners on keyboard press's and I've come across an example of a custom hook being used on handling keypress's. I've tried refactoring the code to suite my needs but I'm unable to do so. Currently I have the eventListener assigned on checking for the &quot;Enter&quot; key being pressed, but I'd like to change it to the use of &quot;Ctrl+S&quot; being pressed instead, how would I go about doing that and if a short explanation could be provided, I'd really appreciate that. I understand that keydown would be suited best, But I'm unable to get it working.</p>
  <p>here is what I have:</p>
  <pre><code>function useKey(key, cb){
      const callback = useRef(cb);
  
      useEffect(() =&gt; {
          callback.current = cb;
      })
  
  
      useEffect(() =&gt; {
          function handle(event){
              if(event.code === key){
                  callback.current(event);
              }
          }
  
          document.addEventListener('keypress',handle);
          return () =&gt; document.removeEventListener(&quot;keypress&quot;,handle)
      },[key])
  }
  
  function App() {
  
  const handleSubmit = () =&gt; {
     alert('submitted')
  }
  
  useKey(&quot;Enter&quot;, handleSubmit)
  
   render (
     &lt;div&gt;....&lt;/div&gt;
   )
  }
  
  </code></pre>