Multiple options with one Hotkey.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
fona
Posts: 65
Joined: 07 Apr 2022, 06:43

Multiple options with one Hotkey.

Post by fona » 13 Jun 2022, 19:28

Hello,
I'm trying to make an unusual hotkey. I have asasigned some actions for F1. If I hold down and release F2 and then press F1, can I make the F1 do some other actions?
Last edited by BoBo on 14 Jun 2022, 22:34, edited 1 time in total.
Reason: Changed subject line from "Is it possible?” to a more specific "Multiple options with one Hotkey".

User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: Is it possible?

Post by mikeyww » 13 Jun 2022, 19:32

Code: Select all

#InstallKeybdHook
F1::
If (A_PriorKey = "F2")
     Send x
Else Send y
Return

fona
Posts: 65
Joined: 07 Apr 2022, 06:43

Re: Is it possible?

Post by fona » 13 Jun 2022, 19:38

mikeyww wrote:
13 Jun 2022, 19:32

Code: Select all

#InstallKeybdHook
F1::
If (A_PriorKey = "F2")
     Send x
Else Send y
Return
Thank you for your help, Mikey. I just found out that I can't use the F2 anyway. Is it possible to hold down the F1 and make then the F1 behave differently?

User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: Is it possible?

Post by mikeyww » 13 Jun 2022, 19:47

Code: Select all

F1::
KeyWait, F1, T.3
If ErrorLevel ; Held
     Send Held `
Else Send Normal `
KeyWait, F1
Return

fona
Posts: 65
Joined: 07 Apr 2022, 06:43

Re: Is it possible?

Post by fona » 13 Jun 2022, 20:26

mikeyww wrote:
13 Jun 2022, 19:47

Code: Select all

F1::
KeyWait, F1, T.3
If ErrorLevel ; Held
     Send Held `
Else Send Normal `
KeyWait, F1
Return
It says Duplicate hotkey. I have already assigned some action for F1. I also tried to past the other actions for F1 after else

Code: Select all

F1::
KeyWait, F1, T.3
If ErrorLevel { ; Held
ControlClick, x312 y227, ahk_class Qt5QWindowIcon,,Left,1,NA ` 
Sleep, 30
SendInput {Down} `
}
Else {  
ControlClick, x1920 y240, ahk_class Qt5QWindowIcon,,Left,1,NA `
SendInput {Down 3} `
KeyWait, F1
}
Return
Last edited by fona on 13 Jun 2022, 20:28, edited 1 time in total.

User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: Is it possible?

Post by mikeyww » 13 Jun 2022, 20:27

Use my script, which already has two actions. You can change them to be whatever you like. Alternatively, use your script instead of mine.

Code: Select all

#IfWinExist ahk_class Qt5QWindowIcon
F1::
KeyWait, F1, T.3
If ErrorLevel { ; Held
 ControlClick, x312 y227,,,,, NA
 Sleep, 30
 Send {Down}
 SoundBeep, 1500
} Else {
 ControlClick, x1920 y240,,,,, NA
 Send {Down 3}
 SoundBeep, 1000
}
KeyWait, F1
Return
#IfWinExist

fona
Posts: 65
Joined: 07 Apr 2022, 06:43

Re: Is it possible?

Post by fona » 13 Jun 2022, 20:38

fona wrote:
13 Jun 2022, 19:38
mikeyww wrote:
13 Jun 2022, 19:32

Code: Select all

#InstallKeybdHook
F1::
If (A_PriorKey = "F2")
     Send x
Else Send y
Return
Thank you for your help, Mikey. I just found out that I can't use the F2 anyway. Is it possible to hold down the F1 and make then the F1 behave differently?
Sorry :), I just didn't formulate the second question well. As I wrote in the beginning, I would like to hold the F1 and release it and when I press again the F1, it should behave differently, while I already have F1 with some actions

User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: Is it possible?

Post by mikeyww » 13 Jun 2022, 20:44

Code: Select all

F1::
KeyWait, F1
KeyWait, F1, DT.25
If ErrorLevel ; Pressed once
     Send Once `
Else Send Twice `
Return

fona
Posts: 65
Joined: 07 Apr 2022, 06:43

Re: Is it possible?

Post by fona » 13 Jun 2022, 21:28

mikeyww wrote:
13 Jun 2022, 20:44

Code: Select all

F1::
KeyWait, F1
KeyWait, F1, DT.25
If ErrorLevel ; Pressed once
     Send Once `
Else Send Twice `
Return
Unfortunately, couldn't solve the problem. This code turns the F1 into single and double press hotkey. Indstead of the single one, I wished that I could hold down the F1 and release it and I when I press it again immediately after that it could do some stuff, while I also can keep the normal F1 with else. Anyway, thank you for your time, Mikey

User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: Is it possible?

Post by mikeyww » 14 Jun 2022, 05:15

This seems to be an exercise in how to describe a goal. A detailed example would go a long way in helping.

Another flavor is below.

Code: Select all

#InstallKeybdHook
F1::
If (A_PriorKey = "F1" && on) {
 Send 2
 on := False
} Else {
 Send 1
 on := True
}
Return

RussF
Posts: 1311
Joined: 05 Aug 2021, 06:36

Re: Is it possible?

Post by RussF » 14 Jun 2022, 06:55

@mikeyww, I have to give you kudos for your patience. :salute:
When I see things like this, I usually just wonder, "WHY?!?" :facepalm:

A keyboard typically has 12 function keys. Add to that the standard modifier keys Ctrl, Alt, Shift, Ctrl-Alt, Ctrl-Shift, Alt-Shift, Ctrl-Alt-Shift and you have 96 possible function keys to choose from (and I didn't even mention the Windows key! Add those modifiers to all the rest of the keys on the keyboard and you have, well, I'm not going to do the math, but, A LOT of possible combinations!

And yet, some want to put a dozen functions on one key, depending on how many milliseconds it's held down, or how many times it's pressed in rapid succession, or if I hold my mouth just the right way when pressing it. Why not just have a keyboard with one key and learn Morse Code?

Climbing down off my soapbox now. :oops:

Russ

User avatar
boiler
Posts: 17383
Joined: 21 Dec 2014, 02:44

Re: Is it possible?

Post by boiler » 14 Jun 2022, 07:18

RussF wrote: When I see things like this, I usually just wonder, "WHY?!?" :facepalm:

And yet, some want to put a dozen functions on one key, depending on how many milliseconds it's held down, or how many times it's pressed in rapid succession, or if I hold my mouth just the right way when pressing it. Why not just have a keyboard with one key and learn Morse Code?
You might want to consider that not everyone uses a keyboard like you do, and your approach isn’t right, it’s just your preference. Others have their own valid preferences.

Your facepalm is directed at someone like me. I am one that really doesn’t like having to use modifier keys for most hotkeys, except perhaps the Shift key and the occasional Ctrl key (but not both together), and I really don’t like multiple-modifier keys. Especially for touch typists, these types of key combinations require removing one or both hands from home row, which is really disruptive compared to being able to press one key a bit longer or to double-tap it.

I personally don’t have a lot of hotkeys that I use while I’m typing, but if I did, I would much prefer to use one of the approaches you are so confounded by than one that requires performing all kinds of hand contortions to execute, then finding my fingers back to ASDF/JKL;

Your post comes off as ridiculing people who ask for strawberry ice cream when it doesn’t make sense for anyone to want to eat anything but chocolate because it’s your favorite.

Off my soapbox.

User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: Is it possible?

Post by mikeyww » 14 Jun 2022, 07:31

My favorite key is F3. Everyone should use it frequently! Down with F1!

:)

RussF
Posts: 1311
Joined: 05 Aug 2021, 06:36

Re: Is it possible?

Post by RussF » 14 Jun 2022, 07:59

My sincerest apologies. "In the moment", my post didn't seem so bad, but upon re-reading it and reflecting, it does seem a bit harsh. So sorry.
boiler wrote: I personally don’t have a lot of hotkeys that I use while I’m typing, but if I did, I would much prefer to use one of the approaches you are so confounded by than one that requires performing all kinds of hand contortions to execute, then finding my fingers back to ASDF/JKL;
Nor do I, but the ones I use all the time use modifiers. Before I even discovered AHK, I found a simple registry hack that swaps the CapsLock key with the Left-Ctrl key, effectively putting Ctrl back up where it belongs - next to the A key and very easy to reach. Early aftermarket keyboards even had a physical switch to swap those keys. @boiler, I think we are close in age, so you can probably relate when I tell you I wrote code for years in WordStar, where every command required the Ctrl key and I became accustomed to it's location next toA.

So, yes, as you stated, it is my preference to use modifiers, because by relocating Ctrl I DON'T have to move my fingers from the home row to reach any modifier or combination thereof.

Again, please accept my apologies - I never meant to ridicule anyone.

russ

RussF
Posts: 1311
Joined: 05 Aug 2021, 06:36

Re: Is it possible?

Post by RussF » 14 Jun 2022, 08:20

mikeyww wrote:
14 Jun 2022, 07:31
My favorite key is F3. Everyone should use it frequently! Down with F1!

:)
Especially since most applications use F1 to call up the "Help" screens - and boy, do I use THAT a lot! :?: :D

Russ

fona
Posts: 65
Joined: 07 Apr 2022, 06:43

Re: Is it possible?

Post by fona » 14 Jun 2022, 08:51

I believe it would be too much time-consuming to make such a complicated hotkey. Than you for your efforts, Mikey.
RussF wrote:
14 Jun 2022, 06:55
@mikeyww, I have to give you kudos for your patience. :salute:
When I see things like this, I usually just wonder, "WHY?!?" :facepalm:
As boiler pointed out, everyone has their own workflow. So it fits to my weird workflow :).

User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: Is it possible?

Post by mikeyww » 14 Jun 2022, 09:06

Try the last one that I posted.

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Is it possible?

Post by BoBo » 14 Jun 2022, 09:54

@fona
Part of the main workflow in this forum, creating a meaningful, problem-related subject line... so your potential supporters will have an idea of what's your main issue.

Your current subject line is fine in a forum discussing Area 51, a mail to your lottery agency after you've heard you've cracked the jackpot but can't find the ticket, the moment Paul Simon thought about leaving a lover, or the moment you stumbled over that Wikipedia article about gonorr... :crazy:

So no, it's not the "Subject Line of the Week", and yes, please be more specific once you create a follow-up thread.
Thx for listening & happy scripting. 8-)

Descolada
Posts: 1201
Joined: 23 Dec 2021, 02:30

Re: Is it possible?

Post by Descolada » 14 Jun 2022, 14:35

RussF wrote:
14 Jun 2022, 06:55
Why not just have a keyboard with one key and learn Morse Code?
Should've done this ages ago :)

Code: Select all

#SingleInstance, force

shortPresses := 0, longPresses := 0, morse := ""
$F1::
	if (A_TimeSincePriorHotkey > 2000)
		shortPresses := 0, longPresses := 0, morse := ""
	t1 := A_TickCount
	KeyWait, F1
	if (A_TickCount - t1 < 150) { ; short press
		if ((longPresses == 0 && shortPresses < 3) || (longPresses == 3 && shortPresses < 6)) {
			shortPresses++, morse .= "."
			ToolTip, %morse%
			SetTimer, RemoveToolTip, -2000
		} Else {
			shortPresses := 0, longPresses := 0, morse := ""
			ToolTip
		}
	} else if (!shortPresses && !longPresses) {
		Send, {F1}
		ToolTip
	} else { ; long press
		if (shortPresses == 3 && longPresses < 3) {
			longPresses++, morse .= "-"
			ToolTip, %morse%
			SetTimer, RemoveToolTip, -2000
		}
	}
	if (shortPresses == 6 && longPresses == 3) {
		ToolTip
		Run, https://www.autohotkey.com/boards/viewforum.php?f=76
		shortPresses := 0, longPresses := 0, morse := ""
	}
	return

RemoveToolTip:
	ToolTip
	return

fona
Posts: 65
Joined: 07 Apr 2022, 06:43

Re: Is it possible?

Post by fona » 14 Jun 2022, 14:41

mikeyww wrote:
14 Jun 2022, 09:06
Try the last one that I posted.
Idk why but it acts like a toggle. I hear different soundbeeps (2000 and 1000) each time I press F1

Code: Select all

#InstallKeybdHook
F1::
If (A_PriorKey = "F1" && on) {
 SoundBeep 2000
 on := False
} Else {
SoundBeep 1000
 on := True
}
Return

Post Reply

Return to “Ask for Help (v1)”