Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Press a key every X seconds?


  • Please log in to reply
10 replies to this topic
Blue Bird
  • Guests
  • Last active:
  • Joined: --
Hello everyone. I am hoping to make an AHK script that presses a certain key every X seconds, but I have no idea where to start with this.

Also, I was wondering if it's possible to have any ONE of the following (in order of importance):

-Make the script happen "behind the scenes", meaning it would send the key press to a certain program, even if it doesn't have focus.

-Make the timer automatically deactivate when the program I'm gonna use it on loses focus, and reactivates when I give it focus again.

-Make a key that activates/deactivates the timer manually.

Any help would be greatly appreciated! D: I'm really struggling with this.

chrisj91
  • Members
  • 398 posts
  • Last active: Jun 03 2015 09:03 AM
  • Joined: 11 Apr 2011
Your description contradicts itself . . .

You say that you want it to send a certain key to the program, even if it doesn't have focus but you want the timer to deactivate whenever it doesn't have focus . . . ??

I think you need to read these in this order:
Quick Start Tutorial
Tutorial for Newbies
Send Command
Sleep Command
Loop Command
Break Command
IfWinActive / IfWinNotActive Command
#IfWinActive / #IfWinExist Command

It sounds like you still need to get some more basic knowledge on AutoHotkey so take you're time with this and post back once you've had a few goes yourself after reading these docs because they are very helpful . . .
Posted Image

Hope this helps / Thanks <-------- (Delete Appropriate)

Chris

Blue Bird
  • Guests
  • Last active:
  • Joined: --
Ahhh no, you must have misread me. I only wanted one of the three features I listed at the end. I listed all three, because I wasn't sure if they were possible.

The best would be to automatically send the key input to the program, even if it doesn't have the focus. So the input gets sent to that program while I'm doing other stuff.

If that's not possible, I want the way to deactivate the timer, so that the key doesn't get pressed while I'm doing other stuff (which is why I suggested deactivating either automatically, or manually).

Anyways, thanks for the links. I'll try reading that to see if I can do this.

Blue Bird
  • Guests
  • Last active:
  • Joined: --
OK I seem to have got this, and it works just fine the way I want it. But the way it is now, it switches focus to the window every time. Is it possible to send input to the window without switching focus? Here's what I have:

#z::
Loop, 10
{
	IfWinExist, WindowsApplication1
	{	
		WinActivate
		SendInput {Enter}
		return
	}
	Sleep, 30000
}

The goal was to start the script with Win + Z, and have it press Enter every 30 seconds. This script does this, but keeps changing focus to the window every time. Is it possible to have this happen without changing focus?

Blue Bird
  • Guests
  • Last active:
  • Joined: --
Oops sorry, I left the "return" in there in the If block. In the working version of the script, I took it off. >.< Sorry.

None
  • Members
  • 3199 posts
  • Last active: Nov 05 2015 09:55 PM
  • Joined: 28 Nov 2009
You might want to try ControlSend it can sent to inactive windows.
You should also read FAQ-Games to understand why it may not work.

Blue Bird
  • Guests
  • Last active:
  • Joined: --
Hi. Thanks to your help, it became:

#z::
Loop
{
   ControlSend, , {Enter}, WindowsApplication1
   Sleep, 30000
}

It works perfectly and doesn't change focus of the window I'm currently on! ^^ Thanks a lot!

forshire
  • Members
  • 7 posts
  • Last active: Nov 06 2012 11:30 PM
  • Joined: 19 May 2011
hi, how can i do a script like this

when i press "1" on the keyboard i wanna repeat it 2 or 3 times.

I tried

1::
Loop, 3
Return

and didn't worked :(

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
$1::

 Loop 3

  Send 1

return
ckeck my sig

forshire
  • Members
  • 7 posts
  • Last active: Nov 06 2012 11:30 PM
  • Joined: 19 May 2011

$1::
 Loop 3
  Send 1
return
ckeck my sig


Oh this is working !!! amazing , Thank you dude really thank you. Is there any way to use sleep command like this

$1::
Loop 3
Sleep 50(50ms); is that mean press "1" sleep 50ms then press "1" again
Send 1

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
<!-- w -->www.autohotkey.com/docs/commands/Block.htm<!-- w -->