Keypress function

Joined
Dec 19, 2022
Messages
1
Reaction score
0
Hello, my goal is to simulate keyboard presses in JavaScript and send them at regular intervals in the text input of messaging application.
However, not being a professional of JavaScript, I face several problems in my program below :

1) Being sure that the keystroke simulation is triggered.
2) Apply the right input format for the application, in my program I have "windows" but it triggers an error in the execution of the program because it does not run in an HTML page.
3) Finally, send the function of the simulated keys after "send".

Here is the end of my program in question :
JavaScript:
var keys = {};

  window.addEventListener('keydown', (e) => {
      
      keys[e.key] = true;
      
      if(keys['a'] && keys['v'])
          console.log('A + V');
      
  });
 
  window.addEventListener('keyup', (e) => {
 
      keys[e.key] = false;
      
  });

  document.dispatchEvent(
    new KeyboardEvent("keydown", {
        key: "v",
        bubbles: true
    })
);

document.dispatchEvent(
    new KeyboardEvent("keydown", {
        key: "a",
        bubbles: true
    })
);

  setInterval(() => {
    client.channels.cache.get('identifier_channel').send();
  }, 50);
});


If you have some solutions, thanks in advance for your help
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top