Skip to content Skip to sidebar Skip to footer

Javascript Simulate Hotkey Sending

I have my program in PHP and Javacript for Firefox I want to emulate on Javascript a hotkey (ALT + K) without jQuery. I want to send that hotkey to my browser pressing a created

Solution 1:

Something like that:

functionsimulateKey() {
  jQuery('input')
    .trigger({
      type: 'keypress',
      which: 'x'.charCodeAt(0),
      shiftKey: true
    })
}

$('input').on('keypress', (e) => {
  console.log(e.which, e.shiftKey);
})
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><inputtype="text"id="input" /><buttononclick="simulateKey()">trigger</button>

Post a Comment for "Javascript Simulate Hotkey Sending"