Count timer to use second button

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ilical
Posts: 9
Joined: 26 Nov 2020, 07:19

Count timer to use second button

26 Nov 2020, 07:28

G'morning u all!

I was trying to create a code the press a hotkey (example: numlock), and it starts to timer counter, so if i press the same hotkey before it's 15 seconds, it'll press shift + numlock, otherwise, would press numlock again. Could anyone help me?

I tried this but it's not working, idk why

Code: Select all

NumLock::
	If Started
	{
		SetTimer, Counter, off
		Send {NumLock}
	}
	Else
	{
		If Timer < 14000
		{
		Send +{Numlock}
		}
		Else
		{
		Send {Numlock}
		}
	}
Return
[Mod edit: [code][/code] tags added.]
User avatar
mikeyww
Posts: 26849
Joined: 09 Sep 2014, 18:38

Re: Count timer to use second button

26 Nov 2020, 07:57

Code: Select all

$x::
SetTimer, Go, -15000
Send % (running ? "+" : "") StrReplace(A_ThisHotkey, "$")
running := True
Return

Go:
SoundBeep, 1500, 20
running := False
Return
ilical
Posts: 9
Joined: 26 Nov 2020, 07:19

Re: Count timer to use second button

26 Nov 2020, 09:20

Thanks bro! It's working perfectly! But there's just one problem, idk why, i can't change de "x" for another button like home page (i don't want a letter hotkey).

I did like this, could u tell me what is wrong?

Code: Select all

$Home::
SetTimer, Go, -15000
Send % (running ? "+" : "") StrReplace(A_ThisHotkey, "$")
running := True
Return

Go:
SoundBeep, 1500, 20
running := False
Return
[Mod edit: [code][/code] tags added.]
User avatar
mikeyww
Posts: 26849
Joined: 09 Sep 2014, 18:38

Re: Count timer to use second button

26 Nov 2020, 09:56

Sending Home requires { and }.

Code: Select all

$Home::
SetTimer, Go, -15000
Send % (running ? "+" : "") "{" StrReplace(A_ThisHotkey, "$") "}"
running := True
Return

Go:
SoundBeep, 1500, 20
running := False
Return
ilical
Posts: 9
Joined: 26 Nov 2020, 07:19

Re: Count timer to use second button

26 Nov 2020, 11:26

now it's almost perfect! haha
just found out that i have another problem.
i remapped my numlock as home page, and this code doesn't work in this case. Do u have any idea? I used this code to remmap my numlock

NumLock::Browser_Home
User avatar
mikeyww
Posts: 26849
Joined: 09 Sep 2014, 18:38

Re: Count timer to use second button

26 Nov 2020, 11:47

It worked when I tried it. The sript has no effect on browser keys or NumLock directly. Remember, however, that Home itself will be sent as Shift+Home during the "running" period, regardless of which window is active.

The following version adds a message box to show you when "running" is active.

Code: Select all

$Home::
If !running
 MsgBox, 48, ON, Running, 1
SetTimer, Go, -15000
Send % (running ? "+" : "") "{" StrReplace(A_ThisHotkey, "$") "}"
running := True
Return

Go:
MsgBox, 64, OFF, Not running, 1
running := False
Return
If it does not work for you, you can post your entire script here.
ilical
Posts: 9
Joined: 26 Nov 2020, 07:19

Re: Count timer to use second button

15 Jun 2021, 06:26

sup mike or anyone else reading it!

Is there anyway of making it click several times in a row the key sent by the command?

I'm mean... When i press the hotkey, it'll send the other key 5 times with 50 ms cooldown. Is there a way of making it? I still don't get this advanced type of script.

Thanks everyone!
User avatar
mikeyww
Posts: 26849
Joined: 09 Sep 2014, 18:38

Re: Count timer to use second button

15 Jun 2021, 07:18

The Send command is sending the key. You can replicate that line any number of times in a row.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: dipahk and 247 guests