Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

rapid fire hotkey help


  • Please log in to reply
9 replies to this topic
Homsikpanda
  • Members
  • 6 posts
  • Last active: Nov 21 2012 03:58 AM
  • Joined: 17 Nov 2012
hi! Posted Image i'm newish, to AHK and i'm trying to create a hotkey for my arrow keys so i can press and hold them to rapid fire that key.
i.e. pressing and hold the UP key pushes the UP key rapidly with a 1-0.5 second interval
up,up,up,up,up,up.
i've read thru the rapid fire thread and i think the last one is kind of what i'm looking for

up::
KeyWait up, T0.5	 ; Wait 1 second for user to
release "up" key
If ErrorLevel	 ; Still held down
While GetKeyState("up","p"){ ; While it's held down
Send {UP down}
sleep 1
}
Else	 ; They let go in
time
Send {UP down}
return

this is what i have so far, and pretty much what i'm looking for, but i run into the issue that it keeps pressing, almost like a toggle instead of a press and hold, and to toggle it off i have to press and hold shift+ up?
another problem i'm running into is that when pressing the key it activates it, but i only want it to activate when i press and hold it.... and i also can't seem to get the timing right

dmg
  • Members
  • 2395 posts
  • Last active: Nov 04 2015 06:46 AM
  • Joined: 19 Nov 2010
If you want the script to repeatedly send a key while it is held down, as if the key were being tapped rapidly, this example may be useful:
#usehook ;*1



hotkey, left, spam ;*2

hotkey, up, spam ;*3

hotkey, right, spam ;*4

hotkey, down, spam ;*5

return



spam: ;*6

 {

   while getkeystate(a_thishotkey, "p") ;*7

    {

	  sleep, 50 ;*8

	  sendinput, {%a_thishotkey%} ;*9

    }

 }

return



end::exitapp ;*10



/*

1 Directs subsequent hotkeys to use the keyboard hook.

2 Uses Hotkey Command to create a left button hotkey tied to the spam subroutine.

3 Uses Hotkey Command to create a up button hotkey tied to the spam subroutine.

4 Uses Hotkey Command to create a right button hotkey tied to the spam subroutine.

5 Uses Hotkey Command to create a down button hotkey tied to the spam subroutine.

6 Spam subroutine label. When called, any code below it will run.

7 While loop and getkeystate, will loop as long as the originating hotkey is held.

8 50ms sleep between loops.

9 Each loop run sends whichever hotkey originated the subroutine.

10 Emergency shutdown.

*/
To adjust the timing change the sleep interval (item number 8).
"My dear Mr Gyrth, I am never more serious than when I am joking."
~Albert Campion

-----------------------------------------------------------------------------------------------
Website | Demo scripts | Blog | External contact

Homsikpanda
  • Members
  • 6 posts
  • Last active: Nov 21 2012 03:58 AM
  • Joined: 17 Nov 2012
i see! =o

ok, i understand how it SHOULD work, but testing it, it does not do what i'm wanting, not sure if the game i'm using it for has time delay between key strokes or not but when i press and hold any of the keys i just stand there, and i've tried adjusting the sleep from 2 seconds to 1/4th of a second =/

pretty much in game i'm trying to use the arrows keys and simulate tapping them (as opose to press and hold )
but after trying the script above i don't move at all, or if i'm lucky i'll turn in the direction i'm wanting to move

dmg
  • Members
  • 2395 posts
  • Last active: Nov 04 2015 06:46 AM
  • Joined: 19 Nov 2010
It sounds like it is either not recognizing the send method or it needs the keys to be held down longer. try this:
#usehook

setkeydelay, , 5



hotkey, left, spam

hotkey, up, spam

hotkey, right, spam

hotkey, down, spam

return



spam:

 {

   while getkeystate(a_thishotkey, "p")

    {

	  sleep, 50

	  sendinput, {%a_thishotkey%}

    }

 }

return



end::exitapp
This version uses SetKeyDelay to make the simulated keystrokes last longer.
"My dear Mr Gyrth, I am never more serious than when I am joking."
~Albert Campion

-----------------------------------------------------------------------------------------------
Website | Demo scripts | Blog | External contact

Homsikpanda
  • Members
  • 6 posts
  • Last active: Nov 21 2012 03:58 AM
  • Joined: 17 Nov 2012
no saddly still not working, though making some progress, i atleast move now but it's very spotty at best =/

reading the tutorial does setkeydelay in this instance work with sendinput?

"SetKeyDelay is not obeyed by SendInput; there is no delay between keystrokes in that mode. This same is true for Send when SendMode Input is in effect." ?

tried some more tweaking adjusting the delay time, the sleep time, i even removed the sleep time and replaced the "sendinput," to just "send," and tried testing it with just 1 direct i.e. "send, {left}"
still not operating properly =/
it's almost as if its going too fast for it to recognized and only kicks in ever could of seconds, oorr it's going too slow (even when i have it set to 250-1000 )
it's not fluid at all and not moving really, i take half a step at most and then anywhere from 3-10 seconds later another half step, very sporadic, and it also still seems to keep getting "stuck" on, like i'll let go of the keep but keep moving, and have to tap the key again to turn it off, sometimes needing to tap it 2-3 times to get it to stop.

dmg
  • Members
  • 2395 posts
  • Last active: Nov 04 2015 06:46 AM
  • Joined: 19 Nov 2010
The fact that it is responding at all means the game is receiving the input. I have to ask, why are you wanting to repeat the key instead of hold it down? In most games movement is based on holding a key not rapid firing it.
"My dear Mr Gyrth, I am never more serious than when I am joking."
~Albert Campion

-----------------------------------------------------------------------------------------------
Website | Demo scripts | Blog | External contact

Homsikpanda
  • Members
  • 6 posts
  • Last active: Nov 21 2012 03:58 AM
  • Joined: 17 Nov 2012
the game is DCU online, and while holding down does cause movement ,they game is based on a console control instead of a keyboard and doesn't have a "walk" fuction (since console controls are pressure sensative and keyboards are not )
to walk you need to rapid tap the movement keys....
and i'm a big roleplayer so i do alot of walking in game instead of running, so it'd be 1000 times easyer if i could just press and hold to walk instead of having to rapid tap...my finger gets sore :c

dmg
  • Members
  • 2395 posts
  • Last active: Nov 04 2015 06:46 AM
  • Joined: 19 Nov 2010
OK. This version simulates holding the keys down for a fraction of a second:
#usehook



hotkey, left, spam

hotkey, up, spam

hotkey, right, spam

hotkey, down, spam

return



spam:

 {

   while getkeystate(a_thishotkey, "p")

    {

	  sleep, 100

	  sendinput, {%a_thishotkey% down}

	  sleep, 50

	  sendinput, {%a_thishotkey% up}

    }

 }

return



end::exitapp
You will probably need to adjust the sleep times.
"My dear Mr Gyrth, I am never more serious than when I am joking."
~Albert Campion

-----------------------------------------------------------------------------------------------
Website | Demo scripts | Blog | External contact

Homsikpanda
  • Members
  • 6 posts
  • Last active: Nov 21 2012 03:58 AM
  • Joined: 17 Nov 2012
AWESOME! IT WORKS PERFECTLY! didn't even need to adjust the sleep times! =o thanks for the help Posted Image
still has the problem of "sticking" some times but i can work with this :D

dmg
  • Members
  • 2395 posts
  • Last active: Nov 04 2015 06:46 AM
  • Joined: 19 Nov 2010
Yay! Glad it is working. Posted Image
"My dear Mr Gyrth, I am never more serious than when I am joking."
~Albert Campion

-----------------------------------------------------------------------------------------------
Website | Demo scripts | Blog | External contact