Suspend function problem (LOOP) Topic is solved

Ask gaming related questions (AHK v1.1 and older)
Hajdes
Posts: 38
Joined: 30 Jul 2021, 17:29

Suspend function problem (LOOP)

Post by Hajdes » 31 Jul 2021, 17:20

In game chat start with t key and I want that after pressing t on keyboard my script will be suspend and I will can normaly write on chat but if I press enter or esc my script will be unsuspend (esc - close chat, enter - send message on chat).

I have problem with this code:

Code: Select all

t::
    Suspend On
Loop
{
    GetKeyState, state, Enter, P
	GetKeyState, state2, Escape, P
    if (state = Enter){
		Suspend Off	
		break
	}   
	else if (state2 = Escape){
		Suspend Off
		break
	}	
}
return
[Mod edit: [code][/code] tags added.]

Main problem with this code is loop which not work, and I don't know how to repair it or replace it something more useful or better solution.
Another problem is t key which work but I must click it 2 times why ? First click suspends script, secound click runs chat. I want after clicking 1 time t key chat will run and script will suspend. I want the same with enter and esc, to make 2 functions at the same time (enter - unsuspends script and send message on chat, esc - close chat and unsuspends script)

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

Re: Suspend function problem (LOOP)

Post by mikeyww » 31 Jul 2021, 20:11

Possibly something like this.

Code: Select all

~Enter::
~Esc::Suspend, Off
$t::
Suspend, Permit
Send % A_IsSuspended ? "" : "t"
Suspend, On
Return
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Suspend function problem (LOOP)  Topic is solved

Post by Xtra » 31 Jul 2021, 22:35

To not block your in game bound key t you will want to allow the normal key press by using ~t

Give this a try:

Code: Select all

~t::
    Suspend On
    Loop
        if (GetKeyState("Enter", "P") || GetKeyState("Escape", "P"))
            break
    Suspend Off
return
Edit: If this is the only hotkey you dont need to use suspend the hotkey thread will not end until Enter or Escape is pressed.

HTH
Hajdes
Posts: 38
Joined: 30 Jul 2021, 17:29

Re: Suspend function problem (LOOP)

Post by Hajdes » 01 Aug 2021, 06:14

mikeyww wrote:
31 Jul 2021, 20:11
Possibly something like this.

Code: Select all

~Enter::
~Esc::Suspend, Off
$t::
Suspend, Permit
Send % A_IsSuspended ? "" : "t"
Suspend, On
Return
After added your code to my script it works but I can't write t on chat, alsohotkeys that I have in my script which send keys combination to game don't want to work before I suspend script and after I suspend and unsuspend it.
Hajdes
Posts: 38
Joined: 30 Jul 2021, 17:29

Re: Suspend function problem (LOOP)

Post by Hajdes » 01 Aug 2021, 06:15

@Xtra
Thanks but after added your code to my script it works but hotkeys that I have in my script which send keys combination to game don't want to work before I suspend script and after I suspend and unsuspend it.
Last edited by Hajdes on 01 Aug 2021, 06:16, edited 1 time in total.
Hajdes
Posts: 38
Joined: 30 Jul 2021, 17:29

Re: Suspend function problem (LOOP)

Post by Hajdes » 01 Aug 2021, 06:16

@mikeyww
Thanks but after added your code to my script it works but I can't write t on chat, also hotkeys that I have in my script which send keys combination to game don't want to work before I suspend script and after I suspend and unsuspend it.
User avatar
mikeyww
Posts: 26939
Joined: 09 Sep 2014, 18:38

Re: Suspend function problem (LOOP)

Post by mikeyww » 01 Aug 2021, 06:39

Code: Select all

~Enter::
~Esc::Suspend, Off
~t::Suspend, On
Hajdes
Posts: 38
Joined: 30 Jul 2021, 17:29

Re: Suspend function problem (LOOP)

Post by Hajdes » 01 Aug 2021, 06:56

Xtra wrote:
31 Jul 2021, 22:35
To not block your in game bound key t you will want to allow the normal key press by using ~t

Give this a try:

Code: Select all

~t::
    Suspend On
    Loop
        if (GetKeyState("Enter", "P") || GetKeyState("Escape", "P"))
            break
    Suspend Off
return
Edit: If this is the only hotkey you dont need to use suspend the hotkey thread will not end until Enter or Escape is pressed.

HTH
Ok I made a checkbox in gui and added hotkey to it and label where I put this code and it work thank you.
Last edited by Hajdes on 01 Aug 2021, 07:27, edited 1 time in total.
Hajdes
Posts: 38
Joined: 30 Jul 2021, 17:29

Re: Suspend function problem (LOOP)

Post by Hajdes » 01 Aug 2021, 07:00

@mikeyww
thanks but I made a checkbox in gui and added hotkey to it and label where I put @Xtra code and it work in your is that problem when I suspend script manually and click enter it unsuspend I needed after click t it suspend and only enter/esc will unsuspend it. When I manually suspend it in @Xtra code enter/esc do not unsuspend it.
Post Reply

Return to “Gaming Help (v1)”