Making different keys suspend and activate scripts. Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
KeyWarrior
Posts: 3
Joined: 14 Jul 2017, 07:23

Making different keys suspend and activate scripts.

19 Aug 2017, 10:12

Hello, I've been having trouble getting a script working correctly.

Here is the code I've written (it took a while for me just to get this right):
  • del::suspend
    Return

    ~w up:: Send, 0
    Return

    ~s up:: Send, 0
    Return

    End::ExitApp
    Return
It's for a simulator, "w" is forward throttle and "s" is reverse throttle and "0" is to bring throttle to zero that fires when I let go of the w or s keys.

The trouble is it interferes with in game messages which is activated with the "t" and "y" keys, typed and then sent with the "Return" key.

So messages end up looking like this "w0ould s0omeone help pleas0e".

I've been trying to write an AHK script that would mean the keys "t" and "y" and "del" would suspend the script and "del" and "Return" keys would re-activate the script (at the moment "del" toggles the script on and off).

I've been trying to sort this for weeks, one of the problems I have is that when I write a script, is that it overrides the normal "t","y" and "Return" key functions so that they only function in disabling the script and not their normal function typing messages.

I'd really appreciate any help.
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Making different keys suspend and activate scripts.  Topic is solved

19 Aug 2017, 10:23

You can stack hotkeys into doing the same action, in this case Suspend or Suspend Off or Suspend On depending on how you want it set up.

You mention that "it overrides the normal" behavior of your keys. This is what the ~ is for in your original code for w/s up -- to not override the normal action. So use the ~ modifier in your new hotkeys.

Code: Select all

~t::
~y::Suspend, On ; disables all hotkeys except those whose first command is "Suspend"

; note that a return after this is not necessary because it is a single-line hotkey. All these hotkeys are single-line actually

~enter::Suspend, Off ; I do not know if there is a ~return key name, but you can try it

~del::Suspend Toggle ; "Toggle" can be omitted here, as that is the default action

~w up:: Send, 0

~s up:: Send, 0

End::ExitApp
KeyWarrior
Posts: 3
Joined: 14 Jul 2017, 07:23

Re: Making different keys suspend and activate scripts.

19 Aug 2017, 10:41

This worked my god thank you! Weeks of scratching my head it was the tilde key I forgot about!
KeyWarrior
Posts: 3
Joined: 14 Jul 2017, 07:23

Re: Making different keys suspend and activate scripts.

21 Aug 2017, 15:52

Riding on the tail coats of this there is one thing I forgot to ask regarding this setup which to be frank I have no idea how to do and couldn't even conceive of how to do and that is the following:

Making the..
  • ~enter::Suspend, Off ;
..work only once after..
  • ~t::
    ~y::Suspend, On ;
..have been pressed.

At the moment ~enter is always functioning whether t or y are pressed or not.
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Making different keys suspend and activate scripts.

21 Aug 2017, 16:03

I'm a bit confused by what you mean as functioning. I wouldn't have thought that ~enter being used to turn off Suspend (and turn on all hotkeys) is a problem. Please correct me if I'm wrong and have misinterpreted what you are asking for. But I guess you want to be able to turn on/activate the individual ~Enter hotkey once t/y is pressed, and once ~Enter is pressed, it disables itself? Two ways to accomplish this:

Code: Select all

~t::
~y::
Suspend, On
Hotkey, ~Enter, On
return

~Enter::
Suspend, Off
Hotkey, ~Enter, Off
return
(Though I think with this set up ~Enter hotkey is enabled at the start of the script. So using Hotkey, ~Enter, Off in your auto-execute section should resolve that.)

Alternatively, the #If directive decides based on a given condition if the hotkeys below it are active or not:

Code: Select all

~t::
~y::
Suspend, On
variable:=true
return

#If variable ; simply checks if variable is a "True" value. "False" values are the expression false, being an empty variable (or null value), or having the value zero (0)
~Enter::
Suspend, Off
variable:=false ; makes variable false, making the #If expression above false, so now the ~Enter hotkey has essentially disabled itself

#If ; reset the context-sensitivity so all hotkeys below this are active at all times. Well, unless they are suspended

~w up:: Send, 0

~s up:: Send, 0

End::ExitApp

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb, mikeyww and 316 guests