Sending PTT keys and unmuting Mic whilst held

Ask gaming related questions (AHK v1.1 and older)
doveman
Posts: 4
Joined: 18 Mar 2014, 09:17

Sending PTT keys and unmuting Mic whilst held

Post by doveman » 18 Mar 2014, 09:36

I'm trying to create a script that will unmute the mic input whilst any one of several PTT keys are held, so that when making videos of gameplay it only records the person's mic when he's actually saying something and not whilst he's eating crisps, coughing, etc.

I've got this so far, which works fairly well by toggling the Mic input mute status, so the player has to mute it manually in the Soundcard control panel first and then the script toggles it to unmute whilst the keys are held.

In this example:
Insert is the Teamspeak 3 PTT key.

End is the Task Force Arrowhead Radio (ArmA3 addon) Short Range transmit key.

Ctrl+End is the TFAR Long Range transmit key.

Alt+End is the TFAR underwater transceiver transmit key.

It works fairly well except
a) it seems to send some keys twice, so for example when I press Ctrl+Xbutton2 to send Ctrl+End, the radio works fine but it triggers the ArmA3 command Lower Weapon, which I have mapped to 2xCtrl.
b) I have to be sure to release Xbutton2 first or else it will leave the keys depressed and the radio stuck on transmit. It's most natural to release the most button first when holding a modifier key and pressing it but still it would be better if the script released the keys when either Xbutton2 or the modifier key was released.
c) When setting the keys in TS3, I have to press Xbutton2 first, then Ctrl, then release either key. If I press Ctrl first, then Xbutton2 the keys register but if I release Xbutton2 first it will just reset and prompt for input again and if I release Ctrl first it will just set Ctrl as the Hotkey. It would be nice if this worked more naturally i.e. press Ctrl+Xbutton2 then release both, in any order, to set.

So if anyone has any ideas how to fix any of those, that would be great.

Code: Select all

#Persistent ; Keep this script running until the user explicitly exits it.

Xbutton1::
VA_SetMasterMute(!VA_GetMasterMute("capture"), "capture")
Send, {Insert down}
Keywait, Xbutton1
Send, {Insert up}
VA_SetMasterMute(!VA_GetMasterMute("capture"), "capture")
return

Xbutton2::
VA_SetMasterMute(!VA_GetMasterMute("capture"), "capture")
Send, {End down}
Keywait, XButton2
Send, {End up}
VA_SetMasterMute(!VA_GetMasterMute("capture"), "capture")
return

^Xbutton2::
VA_SetMasterMute(!VA_GetMasterMute("capture"), "capture")
Send, {Ctrl down} {End down}
Keywait, XButton2
Send, {Ctrl up} {End up}
VA_SetMasterMute(!VA_GetMasterMute("capture"), "capture")
return

!Xbutton2::
VA_SetMasterMute(!VA_GetMasterMute("capture"), "capture")
Send, {Alt down} {End down}
Keywait, XButton2
Send, {Alt up} {End up}
VA_SetMasterMute(!VA_GetMasterMute("capture"), "capture")
return

User avatar
FanaticGuru
Posts: 1908
Joined: 30 Sep 2013, 22:25

Re: Sending PTT keys and unmuting Mic whilst held

Post by FanaticGuru » 24 Mar 2014, 16:30

You might get better results from using GetKeyState().

Example:

Code: Select all

^a:: ; Ctrl + A
	while GetKeyState("Ctrl") or GetKeyState("a") 
		Sleep 50
	MsgBox Both Released
return
	
!a:: ; Alt + A
	while GetKeyState("Alt") and GetKeyState("a") 
		Sleep 50
	MsgBox One Released
return
In the first one it will keep looping forever while either Ctrl or A is pressed down. Only when both are released will it continue.

In the second it will keep looping forever while both Ctrl and A are pressed down. Continuing when either is released.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks

doveman
Posts: 4
Joined: 18 Mar 2014, 09:17

Re: Sending PTT keys and unmuting Mic whilst held

Post by doveman » 24 Mar 2014, 18:32

Thanks but

Code: Select all

^XButton1::
Send {CTRL down} {END down}
    while GetKeyState("Ctrl") or GetKeyState("END") 
        Sleep 50
Send {Ctrl up} {End up}
return
caused issues, in TeamSpeak3 Hotkey settings at least, where after setting a hotkey to Ctrl+End, repeating this would result in nothing happening when I pressed the mouse button, like it had got stuck and the Hotkey would just be set to Ctrl. I had to click the mouse button again to 'release' it and then the next time I could set Ctrl+End again. So that's not going to work.

Using 'and' instead of 'or' just resulted in the same thing happening in TS3 as when I use 'Keywait, XButton2'. It sounds like it might work better in ArmA3 though and avoid END getting stuck on, so I'll try it.

User avatar
FanaticGuru
Posts: 1908
Joined: 30 Sep 2013, 22:25

Re: Sending PTT keys and unmuting Mic whilst held

Post by FanaticGuru » 24 Mar 2014, 19:55

doveman wrote:Thanks but

Code: Select all

^XButton1::
Send {CTRL down} {END down}
    while GetKeyState("Ctrl") or GetKeyState("END") 
        Sleep 50
Send {Ctrl up} {End up}
return
caused issues, in TeamSpeak3 Hotkey settings at least, where after setting a hotkey to Ctrl+End, repeating this would result in nothing happening when I pressed the mouse button, like it had got stuck and the Hotkey would just be set to Ctrl. I had to click the mouse button again to 'release' it and then the next time I could set Ctrl+End again. So that's not going to work.

Using 'and' instead of 'or' just resulted in the same thing happening in TS3 as when I use 'Keywait, XButton2'. It sounds like it might work better in ArmA3 though and avoid END getting stuck on, so I'll try it.
In your first script you were using Keywait to detect when Xbutton was pushed or released (you probably only cared about the release part but Keywait waits for either to happen), but then you used my GetKeyState() example to check for when "End" is released. "End" will never be released because you have a while statement that is sleeping until "End" is released before it will release "End".

You probably want something like this:

Code: Select all

^XButton1::
Send {CTRL down} {END down}
    while GetKeyState("Ctrl") and GetKeyState("XButton1") 
        Sleep 50
Send {Ctrl up} {End up}
return
Control + XButton1 get pushed by user then script will push down Control and End. Sleep while both Control and XButton1 are physically held down by user. If either Control or XButton1 is not down then stop sleeping and script will put Control and End in up position.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks

doveman
Posts: 4
Joined: 18 Mar 2014, 09:17

Re: Sending PTT keys and unmuting Mic whilst held

Post by doveman » 24 Mar 2014, 20:33

FanaticGuru wrote:In your first script you were using Keywait to detect when Xbutton was pushed or released (you probably only cared about the release part but Keywait waits for either to happen), but then you used my GetKeyState() example to check for when "End" is released. "End" will never be released because you have a while statement that is sleeping until "End" is released before it will release "End".

You probably want something like this:

Code: Select all

^XButton1::
Send {CTRL down} {END down}
    while GetKeyState("Ctrl") and GetKeyState("XButton1") 
        Sleep 50
Send {Ctrl up} {End up}
return
Control + XButton1 get pushed by user then script will push down Control and End. Sleep while both Control and XButton1 are physically held down by user. If either Control or XButton1 is not down then stop sleeping and script will put Control and End in up position.

FG
Woops, how embarassing. Yes, pretty obvious mistake there :oops:

However, even with the example you've given above, waiting for either Ctrl or Xbutton1 to be released, I still have the same problem in TS3, when I press Ctrl+Xbutton1 it sets Ctrl+End to the Hotkey but keeps waiting for input and when I release the mouse button it changes it back to just Ctrl, unless I press the mouse button before Ctrl as described previously. If I press Ctrl+End on the keyboard, it just shows that briefly before closing the input sequence and showing it as set, so I don't really know what's going on when I use AHK.

I'll still test it in ArmA3 though as it might just be a specific peculiarity of TS3 that doesn't like the script.

doveman
Posts: 4
Joined: 18 Mar 2014, 09:17

Re: Sending PTT keys and unmuting Mic whilst held

Post by doveman » 27 Mar 2014, 13:32

Nope, doesn't work in ArmA3 properly either I'm afraid.

Xbutton1 for End works fine and shows the onscreen indicator that it's transmitting on the short range but with Ctrl+Xbutton1 it doesn't trigger properly and the indicator only flickers up briefly when first pressing the keys and it doesn't always even do that.

Post Reply

Return to “Gaming Help (v1)”