Prevent text input from listening to keystrokes as modal opens [closed]

I have something like the following markup:

<dialog>
   <div>
      <input type="text">
      <input type="text">
   <div>
</dialog>

I also have an event listener on the parent element that opens the dialog/modal when a particular key is pressed. The trouble is, however, that, when the modal opens, the first input element comes into focus and the key that was used to open the dialog gets recorded in the input as well.

Is there a way to prevent this? Thanks.