How to make KeyWait ignore another hotkey? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
rdllngr
Posts: 54
Joined: 22 Sep 2017, 09:39

How to make KeyWait ignore another hotkey?

14 Feb 2019, 08:10

My KeyWait is sending the contents of another hotkey (Example 1),

AND

The KeyWait is consuming the key itself (Example 2).

My question: How to make KeyWait just wait for the key to be pressed, without triggering another hotkey or sending the key itself? Thanks.


Please run this script you will understand my point:

Code: Select all

; How to make KeyWait ignore another hotkey?

#SingleInstance Force

$a::
Send, B{Enter}
ToolTip, A was pressed`, B was sent.
return

$1::
ToolTip, Please press A
KeyWait, a, D
Send, {BackSpace}{Space 5}<----- See? A was pressed, B was sent.{Enter}
ToolTip,
return

$2::
ToolTip, Please press A
Hotkey, $a, Off
KeyWait, a, D
Send, {Space 5}<----- See? A was pressed, A was sent.{Enter}
Hotkey, $a, On
ToolTip,
return

$3::
Send, {Space 6}<----- I wish that by pressing A, neither A nor B were sent, and the content after KeyWait was executed.{Enter}
return

Esc::
ExitApp
return


 /*
Test here:

|
v







 */
GEV
Posts: 1002
Joined: 25 Feb 2014, 00:50

Re: How to make KeyWait ignore another hotkey?  Topic is solved

14 Feb 2019, 09:32

Try

Code: Select all

Send_B := true

$a::
	If (Send_B)
	{
		Send, B{Enter}
		ToolTip, A was pressed`, B was sent.
	}
	else
		Send, a
return

$1::
	Send_B := false
	ToolTip, Please press A
	KeyWait, a, D
	Send, {BackSpace}{Space 5}
	ToolTip
	Send_B := true
return

$2::
	Send_B := false
	; ...

	ToolTip
	Send_B := true
return

; ...
Rohwedder
Posts: 7645
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: How to make KeyWait ignore another hotkey?

14 Feb 2019, 12:08

Hallo,
try:

Code: Select all

; How to make KeyWait ignore another hotkey?

#SingleInstance Force

$a::
Send, B{Enter}
ToolTip, A was pressed`, B was sent.
return

$1::
Suspend
BlockInput, On
ToolTip, Please press A
KeyWait, a, D
Send, {Space 5}<----- See? A was pressed, neither A nor B were sent{Enter}
ToolTip,
BlockInput, Off
Suspend, Off
return
rdllngr
Posts: 54
Joined: 22 Sep 2017, 09:39

Re: How to make KeyWait ignore another hotkey?

14 Feb 2019, 12:29

Thank you, guys. The GEV's solution gave me several ideas and I used the variables as the best alternative. Works fine. Thank you.

Code: Select all

; How to make KeyWait ignore another hotkey?

#SingleInstance Force

myKey := "2"

$a::
if (myKey = "0") ; Ignore (A = nothing)
	return
if (myKey = "1") ; As key (A = A)
	Send, a
if (myKey = "2") ; As hotkey (A = hotkey)
	{
	Send, b
	ToolTip, A was pressed`, B was sent.
	}
return

Esc::
ExitApp
return

; Examples:

$1::
ToolTip, Please press A
myKey := "2"
KeyWait, a, D
myKey := "1"
Send, <--- A pressed, B sent
ToolTip,
Send, {Enter}
return

$2::
ToolTip, Please press A
Hotkey, $a, Off
KeyWait, a, D
Send, <--- A pressed, A sent
Hotkey, $a, On
ToolTip,
Send, {Enter}
return

$3::
ToolTip, Please press A
myKey := "0"
KeyWait, a, D
myKey := "1"
Send, {Space}
Send, <--- A pressed, nothing sent
ToolTip
return

 /*
Try here:

|
v




 



 */

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb, Google [Bot], mikeyww and 352 guests