Two shortcuts for the same key

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
kaishi10
Posts: 8
Joined: 30 Apr 2021, 11:30

Two shortcuts for the same key

Post by kaishi10 » 28 Jun 2022, 10:31

For example, the F2 key executes the ctrl v shortcut, and the F2 + F3 shortcut opens the download folder, but when I execute F2 + F3, the ctrl v shortcut also executes first and then the download folder opens, my question is the following, how translates to that when clicking only F2 should execute only the shortcut ctrl v and when clicking F2 + F3 execute only the opening of the download folder without executing both shortcuts at the same time when you click F2

CptRootBeard
Posts: 26
Joined: 16 Nov 2020, 14:47
Contact:

Re: Two shortcuts for the same key

Post by CptRootBeard » 01 Jul 2022, 08:59

For such a simple case (two key combos->two actions), I would use something like the following:

Code: Select all

F2::{
	;;Add a slight delay before the check for F3's keystate
	;;(This improved consistency for me, personally)
	sleep 100
	if GetKeyState("F3") {
		msgbox("F2 & F3 pressed.")
	} else {
		msgbox("F2 pressed.")
	}
}

You can also use #HotIf with GetKeyState (and for more complex combinations, I would recommend it), but things like key-press order can be more important in those cases.
See the Custom Combinations section of the Hotkeys docs for more examples: https://lexikos.github.io/v2/docs/Hotkeys.htm#combo

Post Reply

Return to “Ask for Help (v2)”