A program for pressing certain keys?

So you know those auto-clickers that click 100 times per second? Does anyone knew a program where i can, for instance press W for 1 minute, click 3 times, Press S for two seconds, etc. I can make a massive list of commands that the program will follow and activate certain keys. Does anyone know anything that can do this? If you can’t, is there anyway i can create a program that can do this? How can i activate keys i JS on my computer.

I would be interested in doing this.

Well i want to either find or make a program that i can make a list of keys to press, and each key for a certain amount of time. I could also loop it too. Just like you can make the auto clicker activate mouse click, i want to activate multiple keys.

Where could i make this?

@camperextraordinaire

Thanks, but i feel likes its a little too complicated. Is there anyway i can activate keys just in JS? Would i use repl.it or something near that? Brackets?

Thanks, ill check i out.

“How can i simulate a key being pressed or held down in JavaScript?”

Here is the first answer to “simulate key press JavaScript”: javascript - Is it possible to simulate key press events programmatically? - Stack Overflow

It provides several options, some of which may work for your (slightly unclear) use case.

However, that’s not actually what you seemed to be asking for originally, either here or on SO: you wanted to actually activate keys, which is not the same thing. You can simulate keypresses in JS, but that will only have an effect within the environment it exists, like say on your webpage. To programmatically actually simulate a person pressing keys, the code has to talk to whatever drives the interaction between keyboard and computer, which is in the operating system kernel. For fairly obvious reasons, this isn’t accessible unless the program has that privilege, which in-browser JS cannot have.

Also this:

They just want you to ask a reasonable question. You didn’t, and you were genuinely nasty (“garbage people”) on your response. These are actual real people you’re talking to, people who would be m more than happy to help if you made even a smidgen of effort, so at least make an attempt to be polite.

2 Likes

I did ask a reasonable question, but apparently they come at 1/4th my post instead of answering my question. Again just because one is human, doesn’t mean one cant be garbage. He was trying to defend people disliking and walking away, in which i called that a garbage thing to do. Hes a idiot as i stated before, saying that no one can write code for me- on a question about coding. He called my post garbage in his first comment- when instead of trying to help me he spends his time writing a comment. There is millions of questions on that site, should you really care that much about a word that you cant even try to help me.

Now how would i simulate a key press, like a auto clicker. Can it be run in the background?

This?

I should add, the problem you had on SO is that they generally prefer you come and present the work you’ve already done to solve the problem you’re having. So no, they don’t do the code for you. But they will look over code you have and suggest fixes. You have to put the work in. What you could have done was discussed what you looked up and some of the research you did and how it pertains to your question. That would have filled up your character requirement with relevant/useful information.

2 Likes

I had no idea how to do what i was asking. I did do some research, but autohotkey never showed up. Some of the things i did find were old and out of date. randelldawson did suggest this before, but it as just the download. I had no idea there was a forum, and the beginners guide looked confusing.

Thanks both of you :slight_smile:I wish i could give two solutions.

1 Like

John, he never referred to you as a garbage person. He said your question was garbage. StackOverflow is stupidly strict and get all bent out of shape over simple questions and discussions, but you calling people there idiots doesn’t help your case in any way.

Let’s just forget the name-calling, anger, and calm down (that goes for everyone) and work on getting something you can use.

First off, we aren’t going to do the code for you. What you are probably looking for is called a macro runner, or macro scripts. They are used by gamers all the time, and there are ones you can use. You can look for some on Google, here are some examples:

https://sourceforge.net/projects/minimousemacro/
http://www.mouserecorder.com/

If you want to build your own solution, it is possible with JavaScript.

If you are doing this for the browser, you can set it up as an extension. There are libraries to help you with this, one is keysim - npm.

An example of that is:

var input = document.getElementById('name');
var keyboard = Keysim.Keyboard.US_ENGLISH;
keyboard.dispatchEventsForAction('alt+backspace', input);

If you want to press keys outside of the browser, you will of course need to use electron. With electron it looks really simple to make key presses:

browserWindow.webContents.sendInputEvent({
  type: "keyDown",
  keyCode: '\u0008'
});

browserWindow.webContents.sendInputEvent({
  type: "keyUp",
  keyCode: '\u0008'
});

EDIT: not sure that electron solution would make events outside of the current electron program, but either way, you should at least have something you can use for the browser.

Thanks dude, I’ll test everything around 3pm tomorrow (after school).

In the mean time, do I have to set up anything to use that code? Like you put the link npmjs, but is that required?

Where do I run this code? Can I run it on brackets? Repl? Codepen?

The reason I can’t try it now is because my computer crashed when I tried to load repl.it, and I had to go in 5 minutes anyways. I’m typing this from a school iPad, so it wouldn’t work on here. Thanks dude. Let’s just forget about the anger and the agurment. In my heart, freecodecamp will always be better then any other forum websites. It’s focused on the user, and it’s no games, it’s actual code.

I’m glad you feel that way!

I actually can’t get the library to work :frowning: I’ll have to look at it later. I would just use autohotkey

1 Like

Yeah i am using it. I checked it out today (had a 2 hour delay) and it works great. Thanks though for your help.

Say if you make a break through in the code :slight_smile:

1 Like

Update: haven’t had the best luck

Autohotkey isn’t the best, often skips over lines of code. The forums aren’t that good either, as you can’t even view your own topics without searching them in the forum. Like there is no ‘My topics’ section. The forum mods also need to approve your posts, but they are never active. Even if they did, i would have no way of knowing. I cannot access my own topics.

The forums aren’t very active, 2- 3 topic posts a day, not too many responses. There just isn’t enough need for a programming language built around pressing keys.

What i am trying to do will take way long to make too. There’s no way AutoHotKey can track what keys you pressed, for long how and turn it into a program. Before you say it takes away from the fun and is lazy, this is how you hold down a key in this simple language:

Send, {Right down}
Sleep, 270
Send, {Right up}

Wouldn’t be that hard to auto-write that.

Send, {r down}{r up}

It was completely unnecessary to turn this into a programming language, just make a program that can auto-write, or just repeat the keys i just pressed.

Since what i am making has to be very precise, guessing and checking 30 times just for a couple lines of code, for hours at a time is very annoying. It will take me 2 1/2 months at this rate to just make a 200 line program.

The question now is…

Is there any program that can replicate the keys i pressed a certain amount of times?

Try this one. Mini Mouse Macro - Turnssoft - Software development

I downloaded it and it worked like expected. Press record, move mouse and keyboard. Press stop. You can then loop inifinite number of times or a certain number.

Okay i’ll consider it, is it safe? AVG and my basic web security says it is blocking some parts of the website for being unsafe.

I downloaded it, only issue is that the Hotkeys don’t work. So i cannot remotely start and stop it, preventing me from being able to loop it.

You’re writing a keylogger, and downloading software to help you do so, it’s going to assume nefarious intent. It needs to control the computer at a low level, so these softwares are always likely to cause the antivirus to throw a fit regardless of if they’re dangerous or not.

I did download it and it is safe. But it doesn’t track how long you hold down keys, as i mentioned before hotkeys also don’t work. Also, its only moving the mouse and not pressing the keys if it is run in the background. I am also met with it just freezing and crashing half the time.

There is no forums, as they said they would be up by January 2018, yet nothing.

Right, let me get this straight, because you’ve very slightly [but significantly] changed the question that you’re asking for every time you’ve asked it, and you’ve never actually what the aim is. I assume this is just a case of lost in translation but as of now, am I right to say:

You want a program that can record keyboard input at a high degree of accuracy and play it back. And that program should work in the background.