How to script a keyboard keydown to act like a multiple keydown

Hi , I am looking for different ways to script a single keydown to act like a multiple keydown.

When i press a key i want it to be as if i pressed ten times.

Thanx .

I am the most basic beginner.

You can’t reliable simulate keypresses from javascript.

You can listen for events when keys are pressed and change an inputs value though, which sounds like what you are asking.

<!DOCTYPE html>
  <meta charset="utf-8">
  <style media="screen">
    input {
      width: 100%
  <script type="text/javascript">
    var input = document.querySelector('input')
    input.addEventListener('keydown', function(event) {
      var key = String.fromCharCode(event.keyCode);
      if (/[a-zA-Z0-9-_ ]/.test(key)) {
        var tenChars = Array(10).join(event.key)
        input.value = input.value + tenChars
    }, false)

The ugly bit in the middle /[a-zA-Z0-9-_ ]/.test(key) just checks that the character is alphanumeric key if it repeats it, and this example will break when you try and add text to the middle of the input but it’s a start at what you’re describing.

For what purpose are you wanting to press a key 10 times for every 1. I ask for there can be some situations where a known good solution can be applied.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.