Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Can Autohotkey hold down a key?


  • Please log in to reply
13 replies to this topic
Stephypoooo
  • Guests
  • Last active:
  • Joined: --
Hi, i'm trying to do something for in a game, so that I walk when I scroll my wheel down, it works if I assign the key to attack, but I would like it to walk instead.
I understand that the key needs to be held down.

This is my script so far.

WheelDown::Send {W}
Sleep, 100
Return

I figured the sleep command could maybe be used to hold down a key for a certain amount of time that is specified, any help would be Appreciated.

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
The answer is YES, I suppose.

...

See the Hotkeys page. Look for "UP", which also explains "DOWN"...
[EDIT] Wrong, the UP is, obviously, for the hotkey... But well, the example here uses Up and Down in Send and is clear...

Also notice in the same page:

if a hotkey needs to execute only a single line, that line can be listed to the right of the double-colon.

The corollary is that if you have several lines to execute with a hotkey, don't put the first line on the same line as the hotkey...

I still believe it should go in the Faq, under the title "Why do some lines in my script never execute?"...
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

Kerry
  • Members
  • 144 posts
  • Last active: Sep 25 2006 07:33 PM
  • Joined: 20 Jul 2006
Edit: @PhiLHo: lol, the reason why I edit so many of my posts are because when I do make sure they're correct, someone posts before me, when I don't, I have corrections to make. :)

Hi Stephy,

This is straight from the manual - I haven't done much with pressing keys more than once, but this looks pretty simple.

To hold down or release a key: Enclose in braces the name of the key followed by the word Down or Up. For example:

Send {b down}{b up}
Send {TAB down}{TAB up}
Send {Up down}  ; Press down the up-arrow key.
Sleep 1000  ; Keep it down for one second.
Send {Up up}  ; Release the up-arrow key.

Hope this helps,
Kerry

BoBo
  • Guests
  • Last active:
  • Joined: --

To hold down or release a key, enclose in braces the name of the key followed by the word Down or Up.

Well, I found this at - yes - c'mon you know it - yeah, YEssss you're damn right ---> the help!!! Even better - OK I know that you won't believe it - at the section about Send *partysound* 8)

Why not replace your bible, koran, ... with the AHK help for, let's say 2 days ?? To make positive things happen. :wink: (just kiddin :))

Stephypoooo
  • Guests
  • Last active:
  • Joined: --
Thanks, i'll give these a try, I did look in the help section and document section, but I didn't see anything that could help to hold down a key, as you guys have pointed it out to me, i'll give these examples a try.
Thanks.

VigK
  • Members
  • 3 posts
  • Last active: Dec 31 2006 03:26 AM
  • Joined: 20 Jun 2006
Does the script above really work with you ? I dont know why, but I cant make ahk hold a key (not in games). I tried something as simple as :
a::
   send {b down}
   sleep 2000
   send {b up}
return
Then 'a' key sould send me a bunch of 'b' , but no, just 1 b. Please someone explain to me why it doesnt work ?
Thanks, pardon my english.

BoBo
  • Guests
  • Last active:
  • Joined: --

Please someone explain to me why it doesnt work ?

ou gave yourself the answer:

cant make ahk hold a key (not in games)

Something we've to accept. Eg. The key of my Chevrolet Matiz doesn't not work with my wifes Ferrari F430 Spider :lol:

dash
  • Members
  • 54 posts
  • Last active: May 24 2010 01:24 PM
  • Joined: 29 Nov 2006

Does the script above really work with you ? I dont know why, but I cant make ahk hold a key (not in games). I tried something as simple as :

a::
   send {b down}
   sleep 2000
   send {b up}
return
Then 'a' key sould send me a bunch of 'b' , but no, just 1 b. Please someone explain to me why it doesnt work ?
Thanks, pardon my english.



if you want "a" key to send you "bbbbbb" & etc until you release it, use
a::b  ;will work on keyboard, but not on mouse (such as RButton::b)


or the loop (works with any input device):
a::
loop
{
   if getkeystate("a", "p") ;if a button is Physically held down by the user.
    {
      send, {b DOWN}
      sleep, 50
      send, {b UP}
    }
  else
    {
      break
    }
}
return


PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005

Then 'a' key sould send me a bunch of 'b' , but no, just 1 b.

Simulated keystrokes don't trigger the autorepeat feature (managed at keyboard or driver level). dash provided a workaround. I guess this code snippet (or similar) is among the most repeated (!) ones...
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

Markis
  • Guests
  • Last active:
  • Joined: --
Ok i'm trying to do the samething.

This is what I want.

Push Alt = HOLD
Push alt again= let go

Can someone write it for me? I can't figure it out

I've read the faqs and scripts over and over but I can't figure it out =[

Thanks!

kuniva
  • Guests
  • Last active:
  • Joined: --
hi, the best i can do is this. i have tried to have the up and down on the same command button but i just cant do it. but 2 isnt exactly bad

Numpad1::
{
Send {TAB down}
return
}

Numpad2::
{
Send {TAB up}
return
}

Crash&Burn
  • Members
  • 228 posts
  • Last active: Jul 16 2014 10:10 PM
  • Joined: 02 Aug 2009

hi, the best i can do is this. i have tried to have the up and down on the same command button but i just cant do it. but 2 isnt exactly bad

Numpad1::
{
Send {TAB down}
return
}

Numpad2::
{
Send {TAB up}
return
}

Came across this thread while researching a similiar issue.
Just do this:
NumPad1::Send, {TAB Down}
NumPad1 UP::Send {TAB UP}

And Since I am here already:
W_WheelDown:
{
	SetKeyDelay, -1
	if( scrolledWheelDown )
		Send, {Blind}{w DownTemp}
	else
	{
		SetTimer, W_WheelDown, OFF
		Send, {Blind}{w UP}
	}
return
}

WheelDown::
{
	scrolledWheelDown := ( scrolledWheelDown ? 0 : 1 )
	SetTimer, W_WheelDown, 40
return
}


A
  • Guests
  • Last active:
  • Joined: --
Congratulations Crash&Burn, you crashed and burned.

Your script doesn't work, as was already mentioned earlier in the thread. Neither does kuniva's. Did you even test it?

Crash&Burn
  • Members
  • 228 posts
  • Last active: Jul 16 2014 10:10 PM
  • Joined: 02 Aug 2009
Works perfectly fine, when NumLock is on. I test anything I post. Thanks.

And doesn't stop "End" from working when NumLock is not on.

And the latter/extra script example will repeat "w" when wheelDown and stop the "w" when wheelDown a second time.