# automatic key presser (from web design and development)



## NicKeRoT (Apr 2, 2012)

i have been reading some of the tutorials on the internet for creating a program that will make my computer press a couple of times in a second but they are too complicated and hard to understand. What i need it to do is when i press the button "z" it will make it press the button "x" about 5 times in one second until i press "z" again. Is there anyone that can help me with creating this kind of program?


----------



## wmorri (May 29, 2008)

*Re: automatic key presser*

Hi,

Welcome to TSF!!

Can you link a couple of those tutorials so that I can have a look at them and see if it is possible and how hard it would be to do.


----------



## NicKeRoT (Apr 2, 2012)

*Re: automatic key presser*

I am thinking of using this program AutoHotkey - Free Mouse and Keyboard Macro Program with Hotkeys and AutoText and it doesn't look hard to do if you know how to do it . There is a quick start tutorial on the website. Also i have been looking at youtube videos such as these:
AutoHotKey Tutorial - Basics - YouTube
AutoHotKey for begginers! - YouTube
[Tutorial] How to use AHK. {Auto Hot Key} - YouTube
I see how they do theirs but i don't know how to make the one that i want...


----------



## wmorri (May 29, 2008)

*Re: automatic key presser*

Okay well this doesn't seem that difficult, but before I dive deep into how to make a script for this have you tired looking at the wiki and seeing if there is anything that can help you with it. If that isn't there I would search the forums too. If you don't find anything even similar to it then come back and I will try and find something. 

Also, I am going to move your thread to the programming section as this really doesn't have anything to do with web design and development.


----------



## NicKeRoT (Apr 2, 2012)

I have been looking for something like this for almost 2 weeks now and i can't find one that's similar to this. I have downloaded many programs like this and i found out that this is the only way to do it(by creating a script). Most of them want to press the mouse button and i'm not familiar with the commands so i really can't do it myself...


----------



## wmorri (May 29, 2008)

It is going to take me a bit to learn the syntax and then figure out how to write it. If you want a faster response you might want to post on their forums and see what they tell you.


----------



## NicKeRoT (Apr 2, 2012)

i am not in a hurry and i can see that it would take a lot of time and if you can't do it its fine...


----------



## Ninjaboi (Dec 27, 2010)

Here's an application based on your specifications ( attached to this reply in a .zip compressed format ).

You simply double-click to run the application in the background and it will simulate 5 'x' key presses whenever you press 'z' on your keyboard. It does this in less than a second, so it's very quick.

Hope this is what you were wanting!


----------



## NicKeRoT (Apr 2, 2012)

OMG thanks a lot only one thing it doesn't seem to work in the game that i want it to which is an internet game HaxBall - Play do you know why this would be?


----------



## Ninjaboi (Dec 27, 2010)

I'm not sure, I've never played that game before. Does it work inside other applications such as Notepad or another game?


----------



## NicKeRoT (Apr 2, 2012)

i figured it out. The problem was that i needed the x button to be pressed with the smallest break possible after pressing the z button. What that program does is it just pastes xx instead of x and after a couple of milliseconds another x


----------



## Ninjaboi (Dec 27, 2010)

> The problem was that i needed the x button to be pressed with the smallest break possible after pressing the z button.


I am confused as to what you meant. I just performed a benchmark on this program, and it emulated the key press 'x' 5 times in less than 1/4 of a second ( 0.212 seconds was my fastest time with it ). That seems rather fast to me, as that's roughly 16-22 key presses a second being emulated. If it needs to be faster, there might be a way to trim it down a few milliseconds, but it still won't fall under 0.150 seconds from what I can imagine.



> x and after a couple of milliseconds another x


It sounds like you were wanting it to be even quicker in emulating the 5 key presses to perhaps less than 0.050 seconds. I don't think this can be done, as it takes a certain amount of time to take an event from the Windows events stack, process what to do with it, and send the 5 emulated key pressed back to Windows to be performed. This would be up to the speed of your processor, which mine is currently not the best in the world by far. The speed isn't capped, so if you can get it to perform quicker on your system then that will solve that issue.



> What that program does is it just pastes xx instead of x and after a couple of milliseconds another x


By 'pastes', do you mean that it sends the literal character value for 'x' instead of the key press of 'x'? Both can be done, but this program specifically emulates the key press of 'x' instead of sending the character 'x' to Windows applications. If you're not wanting the program to emulate the key presses one right after another and instead have delay between each key press, that can be done.

Example:

*Key Press 'X' is sent*
-DELAY 0.100 SECONDS-
*Key Press 'X' is sent*
-DELAY 0.100 SECONDS-
*Key Press 'X' is sent*
-DELAY 0.100 SECONDS-
*Key Press 'X' is sent*
-DELAY 0.100 SECONDS-
*Key Press 'X' is sent*

The time of delay can be whatever you need though, that's just an example.


----------



## NicKeRoT (Apr 2, 2012)

This is the final product 
$LShift::
while GetKeyState("LShift", "P")
{
Send {x down}
sleep 10
Send {x up}
sleep 24
}
return

instead of z its shift and its not 5 x's in a second but that's what i was looking for. I guess the information i gave you was not so accurate...


----------



## Ninjaboi (Dec 27, 2010)

No problem, it would have been difficult for you to convey what you meant. You did the best to explain, I did the best to understand.

Glad you solved your problem though!

Happy scripting :grin:.


----------

