Temporary suspend of script during input dialog? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
User avatar
Shadrach
Posts: 18
Joined: 18 Nov 2017, 08:02

Temporary suspend of script during input dialog?

01 Jan 2020, 10:45

Hey, Happy New Year :D
I've been using a hotkey override script for a game for a couple of years now, it works fine, but one issue is one dialog that pops up and needs keyboard input. The AHK script interferes with this obviously, so I've mapped Pause to Suspend and this works but is a bit clunky.

So I was thinking I could automate the suspend somehow and I've tried the following:

b:: ;B Find Place override
Suspend, On
Send b
KeyWait, Enter
KeyWait, Esc
Suspend, Off
Return


Basically I want it to suspend *temporarily* after pressing B, then wait for Enter or ESC before turning suspend off.
But this does not seem to work so not sure what I'm doing wrong. My Pause::Suspend from earlier in the script is working fine.

Any tips appreciated :think:
aifritz
Posts: 207
Joined: 29 Jul 2018, 11:30
Location: Germany

Re: Temporary suspend of script during input dialog?

01 Jan 2020, 15:40

You could try it with the option D, means wait for the key to be pushed down.

Code: Select all

b:: ;B Find Place override
Suspend, On
Send b
KeyWait, Enter, D
KeyWait, Esc, D
Suspend, Off
Return
User avatar
Shadrach
Posts: 18
Joined: 18 Nov 2017, 08:02

Re: Temporary suspend of script during input dialog?

01 Jan 2020, 16:19

aifritz wrote:
01 Jan 2020, 15:40
You could try it with the option D, means wait for the key to be pushed down.
Thanks for the reply - I got a bit further I think :)
It looks like if I don't wait for Down, it just assumes keys are Up and proceeds.

So that worked. Problem now is, I can't make it wait for Enter OR Esc, the KeyWait seems to require BOTH to have been pressed to re-enable the script. A dialog can either be closed with Esc OR Enter. And I'm not even going to think about mouse clicks for now.

Any idea how to make the KeyWait an OR?
aifritz
Posts: 207
Joined: 29 Jul 2018, 11:30
Location: Germany

Re: Temporary suspend of script during input dialog?

02 Jan 2020, 03:58

In this case take a look to the Input command.

https://www.autohotkey.com/docs/commands/Input.htm


It could wait for the user to press a key
User avatar
Shadrach
Posts: 18
Joined: 18 Nov 2017, 08:02

Re: Temporary suspend of script during input dialog?

02 Jan 2020, 06:05

aifritz wrote:
02 Jan 2020, 03:58
In this case take a look to the Input command.

https://www.autohotkey.com/docs/commands/Input.htm


It could wait for the user to press a key
Yeah, I tried:

Input, SingleKey, L1, {Enter}{Esc}

From the example, but I think I misunderstand how that function works...
aifritz
Posts: 207
Joined: 29 Jul 2018, 11:30
Location: Germany

Re: Temporary suspend of script during input dialog?

02 Jan 2020, 13:55

For me, this code works as expected.
You could switch Suspend, off with the Enter or ESC key.

Code: Select all

b:: ;B Find Place override
Suspend, On
Send b
Input, SingleKey, L1, {Enter}{Esc}
Suspend, Off
Return
User avatar
Shadrach
Posts: 18
Joined: 18 Nov 2017, 08:02

Re: Temporary suspend of script during input dialog?

02 Jan 2020, 17:14

aifritz wrote:
02 Jan 2020, 13:55
For me, this code works as expected.
You could switch Suspend, off with the Enter or ESC key.
So weird, it should work perfectly for my use but it just won't Suspend, seems it just jumps over the Input bit and turns Suspend off again. But that dialog behaves strangely, it also disables any default in-game hotkeys while open, since it requires input, and that might account for the strange behaviour. Not sure it's a proper Windows dialog box either.

It's really got me stumped... I've put the whole script online here:

Code: Select all

https pastebin.com /ZJFQyZcX
Broken Link for safety

Do you think it might be related to the use of SendMode or UseHook? I just copied those lines from a default script a long time ago.
aifritz
Posts: 207
Joined: 29 Jul 2018, 11:30
Location: Germany

Re: Temporary suspend of script during input dialog?

05 Jan 2020, 09:39

Please a try it in this way. (Look also to the second example in the help-file)

Code: Select all

b:: ;B Find Place override
Suspend, On
Send b
Loop {
	Input, SingleKey, L1, {Enter}{Esc}
	If InStr(ErrorLevel, "EndKey:")
		break
	Sleep 200
}
Suspend, Off
Return
User avatar
Shadrach
Posts: 18
Joined: 18 Nov 2017, 08:02

Re: Temporary suspend of script during input dialog?

05 Jan 2020, 14:47

aifritz, thank you so much for coming back to this - I was really hoping this would solve it, I had looked at some loops before but figured it would be too complex for this simple need, but it did seem like what would be needed. However it still does not work, so I have no idea what it could be :cry:

What happens now is: The script is actually disabled, as the tray icon is changed to 'S' and ESC/Enter also works for closing the dialog and enabling it. But the dialog still won't properly accept input and just bugs out. I think this dialog is a real special case, probably it does some weird stuff in the background.

Using KeyWait works as expected, so it's too bad it only works for a single key. Hopefully future versions will allow us some syntax like KeyWait, Enter,D or Esc,D

Thank you so much for you effort. I'll be happy to try anything else you can think of, but at the moment I've just resigned to use KeyWait for Enter and just remember to not press Esc to close the dialog.

BTW; Do you think it matters whether the Suspend is before or after the Send? Logically Suspend should also block the Send, but I've tried both ways with no difference.
TravisQ
Posts: 21
Joined: 17 May 2015, 23:51

Re: Temporary suspend of script during input dialog?  Topic is solved

05 Jan 2020, 15:42

If you are suspending your hotkeys so you can interact with the dialog perhaps you need the visible "v" option enabled.

Code: Select all

~b::
	Suspend, On
	input,_,v,{esc}{enter}
	Suspend, Off
Return
User avatar
Shadrach
Posts: 18
Joined: 18 Nov 2017, 08:02

Re: Temporary suspend of script during input dialog?

05 Jan 2020, 16:37

TravisQ wrote:
05 Jan 2020, 15:42
If you are suspending your hotkeys so you can interact with the dialog perhaps you need the visible "v" option enabled.
Hello Travis, thank you so much for your reply! Actually this works! :bravo:
And a simple solution too, brilliant!

Just a couple of questions if you don't mind (so I can learn something too):

- I assume the underscore _ is just a variable name and could be anything?
- I've not used the tilde ~ syntax before but I assume this will just pass on the key 'b' so I don't actually need to use Send to pass it?
- Apparently the L1 is not needed, even if we're only waiting for a single input - I guess because we've specified EndKeys?

Again thank you both so much for all your help! :thumbup:

Return to “Ask For Help”

Who is online

Users browsing this forum: Axxi, Bing [Bot], BNOLI, smbs and 102 guests