Keywait for one of two keys

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
scriptor2016
Posts: 854
Joined: 21 Dec 2015, 02:34

Keywait for one of two keys

15 Mar 2017, 11:59

Hi. When I hold down insert, I want a keywait command to wait for either insert or lbutton to be released - doesn't matter which one is released first. I have 2 consecutive keywaits, but it won't work. Is there an easy way to do something like this?

Code: Select all

~insert::
sendinput {i down}
keywait, insert
keywait, lbutton
sendinput {i up}
return
4GForce
Posts: 553
Joined: 25 Jan 2017, 03:18
Contact:

Re: Keywait for one of two keys

15 Mar 2017, 13:43

( UNTESTED )

Code: Select all

~insert::
	sendinput {i down}
	while(GetKeyState("insert", "P") AND GetKeyState("LButton", "P")) {
		Sleep 1
	}
	sendinput {i up}
Return
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: Keywait for one of two keys

15 Mar 2017, 14:00

(TESTED)

Code: Select all

Keys := ["lbutton", "insert"]
var := false
return

~insert::
Loop {

Sleep, 10

	Loop, 2
	{
	
		if (var) {
			if not (GetKeyState(Keys[var]))
		break, 2
		}
		Loop, 2
		if (GetKeyState(Keys[a_index])) {
			var := a_index
			ToolTip % var
		break, 1
		}
	
	}
}
MsgBox,
var := false
return
update var := false before return
Last edited by A_AhkUser on 15 Mar 2017, 15:30, edited 2 times in total.
my scripts
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Keywait for one of two keys

15 Mar 2017, 15:01

Another one :roll:

Code: Select all

#if !getkeystate("i")
~insert::Send,{i down}
#if getkeystate("i")
insert up::Send,{i up}{insert up}
LButton up::Send,{i up}{lbutton up}
scriptor2016
Posts: 854
Joined: 21 Dec 2015, 02:34

Re: Keywait for one of two keys

16 Mar 2017, 00:48

thank you to everyone's replies - infact everyone of them works well! :)

I was thinking the wrong way - by maybe using dual keywaits (which I don't think works at all), but now it makes sense to use a loop with getkeystate inside. I'm using each one until I can decide which suits the software I'm using best and then adjust it to my specific needs. Excellent, thanks again guys :)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, jameswrightesq and 287 guests