Rebind left alt to push to talk key, " ` " (vkDFsc029) Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
croana
Posts: 48
Joined: 30 Jul 2019, 14:46

Rebind left alt to push to talk key, " ` " (vkDFsc029)

30 Jul 2019, 15:12

I'd like to rebind my left alt key to my discord push to talk key " ` " (vkDFsc029) when I'm playing specific games -- Testing is being done in World of Warcraft, specifically.

I'm running into a problem with the press and HOLD mechanic needed for push to talk. No matter what I try, it seems that when I rebind my left alt key, the rebound key is only pressed when the key is released. When I look to see what autohotkey is doing using a keyboard hook and key history, I see autohotkey pressing "alt, alt, alt, control, control," and only at key release at the end do I see, " `, ` ". Ideally, I should be seeing " ` " pressed the entire time.

Here's the things I've tried. This is the beginning of the relevant part of my script:

Code: Select all

GroupAdd, justWow, ahk_exe wow.exe
GroupAdd, justWow, ahk_exe Wow.exe

#If WinActive("ahk_group justWow") and not GetKeyState("ScrollLock", "T")
And these are the rebinds I've tried:

Code: Select all

	*LAlt::SendInput {vkDFsc029 down}
	*LAlt up::SendInput {vkDFsc029 up}

Code: Select all

	SetKeyDelay, 0, 35 ;it does not need to be in the loop
	*LAlt::
		While GetKeyState("LAlt","P") 
		{ 
			Send {vkDFsc029 down} 
		} 
	Return

Code: Select all

	*LAlt::
		SendInput {vkDFsc029 down}
		KeyWait, LAlt
		SendInput {vkDFsc029 up}
Any ideas why none of these work, and how I can fix this? Thanks!

Edit - This was also suggested on Discord, but didn't work.

Code: Select all

~LAlt::
    Sleep, 1000
    If(GetKeyState("LAlt"))
        Send, {vkDFsc029}
This simply pulsed the push to talk button in Discord once a second, after rebinding push to talk to alt+`. That is, I could see my icon flash / hear the push to talk release noise once a second when the rebound alt button was pressed.

For completeness, this also doesn't work:

Code: Select all

lalt:: Send, {vkDFsc029}
Last edited by croana on 02 Aug 2019, 08:59, edited 3 times in total.
User avatar
rommmcek
Posts: 1475
Joined: 15 Aug 2014, 15:18

Re: Rebind left alt to push to talk key, " ` " (vkDFsc029)

30 Jul 2019, 20:17

Why don't you use simply LAlt::`. I think asterisk is not needed because Alt and its SysCommand message differs from other modifier keys.
croana
Posts: 48
Joined: 30 Jul 2019, 14:46

Re: Rebind left alt to push to talk key, " ` " (vkDFsc029)

31 Jul 2019, 04:23

That doesn't work either. I have the exact same issue that ` is only pressed and released quickly right when I release the alt.

When I press and hold ` normally on my keyboard, it acts exactly as you would expect.

In all cases, this is what the ahk key history shows when I press and hold a remapped LAlt.

https://i.imgur.com/aDaallG.png

And this is what it looks like when ` is pressed and held normally:

https://i.imgur.com/pFOMlNi.png

I want my remapped key to behave like the second picture.
User avatar
rommmcek
Posts: 1475
Joined: 15 Aug 2014, 15:18

Re: Rebind left alt to push to talk key, " ` " (vkDFsc029)

31 Jul 2019, 12:39

It works for me. Try to run the script as Admin.
croana
Posts: 48
Joined: 30 Jul 2019, 14:46

Re: Rebind left alt to push to talk key, " ` " (vkDFsc029)

31 Jul 2019, 14:56

OK!

So I'm getting somewhere. I just tried adding LAlt::` to my script, compiled the script, and ran as administrator. It still didn't work how I wanted.

Out of frustration, I made a new ahk script that was JUST LAlt::`, compiled it, ran as administrator, and that did work. (Edit: No, no it didn't. It only worked OUTSIDE of the wow window. When I was inside the wow window I was getting the same issue.)

So there's something wrong with the rest of my script and how it interacts with wow and Discord. I even tried adding Discord.exe to my filters to see if that helped.

Here's the entire script. What did I do wrong?

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

#InstallKeybdHook

GroupAdd, justWow, ahk_exe wow.exe
GroupAdd, justWow, ahk_exe Wow.exe
GroupAdd, gaming, ahk_group justWow
GroupAdd, gaming, ahk_exe dxNothing.exe
Return

#If WinActive("ahk_group gaming") and not GetKeyState("ScrollLock", "T")
	p::B
	*c::Send {LAlt down}
	*c Up::Send {LAlt up}
	*v::Send {LControl down}
	*v Up::Send {LControl up}
	b::Send {vkBAsc027}
	t::c
	F5::n
	PrintScreen::y
	F9::j
	r::=
	CapsLock::m
	<!w::Send {x down}			; <! = left alt
	<!w Up::Send {x up}
	
#If

; left alt needs to be remapped to push to talk so that it only works in the active wow window
#If WinActive("ahk_group justWow") and not GetKeyState("ScrollLock", "T")
	LAlt::`
#If

Edit: Based on a conversation on Discord, made the following changes:
  • closed the top #if statement
  • reduced clutter when adding groups, added "Return" at the end
These changes didn't improve the issue.
Last edited by croana on 02 Aug 2019, 03:59, edited 8 times in total.
User avatar
rommmcek
Posts: 1475
Joined: 15 Aug 2014, 15:18

Re: Rebind left alt to push to talk key, " ` " (vkDFsc029)

01 Aug 2019, 07:55

In the first place, you have to decide if 'Alt' key should fire:
1. each time you press it
2. only when you not press 'w' afterwards.
croana
Posts: 48
Joined: 30 Jul 2019, 14:46

Re: Rebind left alt to push to talk key, " ` " (vkDFsc029)

01 Aug 2019, 12:19

So this script is supposed to do the following things involving alt. All of these things are supposed to happen in world of warcraft, when scroll lock is not toggled on:
  • C is rebound to Lalt.
  • Lalt+w is rebound to x (a movement key).
  • LAlt is rebound to ` (push to talk in Discord).
I spent about 40 min with someone on Discord trying to troubleshoot this issue earlier today.

There seems to be an issue with either Warcraft or Discord in terms of overriding AHK's new keybind, but we don't know how to fix it.

Attempting to run Discord as admin didn't fix the issue. Apparently Discord is an electron app, so ControlSend doesn't work. This rebind also didn't work, even when outside of the #if statement:

Code: Select all

lalt::ControlSend,, {vkDFsc029 Down}, ahk_exe Discord.exe
lalt up:: ControlSend,, {vkDFsc029 Up}, ahk_exe Discord.exe
Last edited by croana on 01 Aug 2019, 17:17, edited 2 times in total.
gregster
Posts: 9002
Joined: 30 Sep 2013, 06:48

Re: Rebind left alt to push to talk key, " ` " (vkDFsc029)

01 Aug 2019, 12:47

Put ControlFocus immediately before ControlSend (Note the slightly different syntax: no keys parameter).
This often helped me, when ControlSend alone didn't work.
croana
Posts: 48
Joined: 30 Jul 2019, 14:46

Re: Rebind left alt to push to talk key, " ` " (vkDFsc029)

01 Aug 2019, 17:30

Thanks for the reply. I just tried changing that bit to this:

Code: Select all

	lalt::
		ControlFocus,, ahk_exe Discord.exe
		ControlSend,, {vkDFsc029 Down}, ahk_exe Discord.exe
	lalt up:: 
		ControlFocus,, ahk_exe Discord.exe
		ControlSend,, {vkDFsc029 Up}, ahk_exe Discord.exe
I'm not at all sure if that's what you meant, but that was my best guess. Push to talk isn't being pressed in discord at all now, not even when I release the key. (This happened before I added ControlFocus too.)

I do notice that if I happened to have selected the chat box in discord before alt tabbing to wow, ` gets added to the text box when I press alt in wow, while the script is active.

Um....
I feel like at this point maybe I should also add context as to why I'm doing these insane keybinds. I use a really old gamepad+keyboard combo to play video games (merc stealth). I'm upgrading to windows 10, but unfortunately the remapping program that came with the keyboard doesn't work beyond windows 7. The keys on the gamepad all register as duplicate, identical keyboard keys in windows 10, even though some of the gamepad keys are in wildly different places than on a normal querty keyboard. The only workaround I can figure out to keep on using my gamepad is to use ahk to reinstate my normal gamepad keybinds, then use scroll lock to toggle between "gamepad mode" and "keyboard mode".
User avatar
rommmcek
Posts: 1475
Joined: 15 Aug 2014, 15:18

Re: Rebind left alt to push to talk key, " ` " (vkDFsc029)

01 Aug 2019, 18:46

Obviously you don't have much experience with Hotkeys. You must conclude each Hotkey label with Return, except if it is one liner. So try:

Code: Select all

	lalt::
		ControlFocus,, ahk_exe Discord.exe
		ControlSend,, {vkDFsc029 Down}, ahk_exe Discord.exe
	return
	lalt up:: 
		ControlFocus,, ahk_exe Discord.exe
		ControlSend,, {vkDFsc029 Up}, ahk_exe Discord.exe
	return
If your app has more then one controls then you should define to which control are you sending (first parameter).
To determine Control use Spy tool (right click on the Ahk tray icon and left click on Window Spy menu item.

If code above works, fine. But if not, you should build on what already works for you, adding only one new Hotkey at a time.

How many combination do you have? Maybe you could define all combination as simple Hotkeys as we already tried with LAlt::`.
croana
Posts: 48
Joined: 30 Jul 2019, 14:46

Re: Rebind left alt to push to talk key, " ` " (vkDFsc029)

02 Aug 2019, 04:10

No, I don't have very much experience with AHK at all. :) Up until now, the most "advanced" coding I have done is basic HTML formatting and the hotkeynet script I wrote for multiboxing wow. I really appreciate the help I'm getting here. I spent a lot of time googling this issue and couldn't find anything that could help.

Unfortunately even adding "Return" as suggested doesn't seem to fix the issue.

When I check out what's happening with keyboard hook + key history, all I see being sent is Lalt down a lot, then lcontrol down up. No ` at all.

Sorry, it's early in the morning and I'm just drinking my coffee. What do you mean when you say these things?
To determine Control use Spy tool
When I mouseover discord using the window spy tool, the "Focused Control" box is blank. The only information I see is the window title, class, exe, pid, as well as some mouse and window position info.
you should build on what already works for you, adding only one new Hotkey at a time.
I think that's what I'm doing in this case? Adding one new hotkey?
How many combination do you have?
Combination of what? I described how alt is being used in my last answer I think.
Maybe you could define all combination as simple Hotkeys as we already tried with LAlt::`
Remapping lalt in all situations isn't ideal, but just to test I tried adding LAlt::` back to the on its own outside of an #if statement. And on testing I realized that while the rebind works when warcraft isn't my active window, as soon as wow is my active window, I get the same issue again of lalt being held down, ` being pressed for a split second on release. So unfortunately this solution doesn't work either.

I know I'm new to this, but it honestly looks to me like World of Warcraft is somehow overriding AHK's attempt to rebind alt, and this might be combined with an issue with Discord not being able to receive hotkeys sent to it directly? Is that's what's going on?

Thanks for your continued help on this.

A big problem here is that I use alt as a conditional in many, many macros in warcraft and isboxer (multiboxing software that works with wow). I could potentially just use alt as my push to talk key. This would mean I'd have to rewrite all my wow macros and isboxer keybinds so that I'm using a different conditional or conditional combination, then rebind that new conditional to the c key on my gamepad (which is where alt is sitting now), but I'd really, really like to avoid that if I can. It feels like a really brute force workaround? There are some things I won't even be able to do if I can't use alt anymore (as it's bound to discord push to talk).
croana
Posts: 48
Joined: 30 Jul 2019, 14:46

Re: Rebind left alt to push to talk key, " ` " (vkDFsc029)

02 Aug 2019, 04:38

OK....so this should work, but it doesn't.

Using alt and warcraft as new google keywords, I found this post: https wowlazymacros.com /t/autohotkey-script-that-allows-shift-ctrl-and-alt-modifiers/3587 (Broken Link for safety)

Code: Select all

#If WinActive("ahk_group justWow") and not GetKeyState("ScrollLock", "T")
		$lalt:: 
		While GetKeyState("lalt","P") 
			{ 
			Sendinput {Blind}{vkDFsc029 Down}
			Sleep, 100
			} 
		Return
#If
If I'm understanding it correctly, this post explains why this isn't working for me:
https wowlazymacros.com /t/alt-shift-ctrl-mod-keys-not-working/4602/13 (Broken Link for safety)

The problem is that when alt is used for ANYTHING in warcraft, it overrides ahk. So I'd have to unbind alt from absolutely everything in game to make this work, can't use it in macros, and can't use it as a conditional. That's well shit.
User avatar
rommmcek
Posts: 1475
Joined: 15 Aug 2014, 15:18

Re: Rebind left alt to push to talk key, " ` " (vkDFsc029)

02 Aug 2019, 13:25

This Thread is a mess! Sorry to say that, but I'm involved too.
There are too much questions opened!

If you agree, post the code which already works. (If you already did, post the link to it)
Then describe what did you add next, but it didn't work!

Be patient, and let's do it step by step and be aware it might be mission impossible!
croana
Posts: 48
Joined: 30 Jul 2019, 14:46

Re: Rebind left alt to push to talk key, " ` " (vkDFsc029)

03 Aug 2019, 06:02

OK. Here's a summary of this thread so far:
  • My keyboard (merc stealth) has a gamepad on the side. The keyboard remapping software doesn't work with windows 10, so I'm trying to use ahk to remap the keys for when I play world of warcraft.
  • I would like to rebind the left alt key to my discord push to talk key, `.
  • I've worked on many attempts at code fixes ahk, but none of them worked while I was in wow.
  • In nearly all cases, key history shows that even while rebound, while lalt is pressed and held in wow, lalt down is sent (not `), followed by lcontrol up down. When the rebound lalt is released, ` is pressed up down for a split second.
  • Running as administrator doesn't help.
  • Attempts to send the push to talk keybind directly to discord, circumventing wow, have failed.
  • I discovered that if alt is used in world of warcraft in any macro, in-game keybind, or as a conditional by any other addon, warcraft will override ahk and press alt down even when that button has been remapped to something else.
Here is my current code. Please note that I'm using the simplest possible rebind for lalt at the moment, since none of the other attempts have been successful:

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

#InstallKeybdHook
#MaxThreadsPerHotkey 2

GroupAdd, justWow, ahk_exe wow.exe
GroupAdd, justWow, ahk_exe Wow.exe
GroupAdd, gaming, ahk_group justWow
GroupAdd, gaming, ahk_exe dxNothing.exe
Return

#If WinActive("ahk_group gaming") and not GetKeyState("ScrollLock", "T")
	p::B
	*c::Send {LAlt down}
	*c Up::Send {LAlt up}
	*v::Send {LControl down}
	*v Up::Send {LControl up}
	b::Send {vkBAsc027}
	t::c
	F5::n
	PrintScreen::y
	F9::j
	r::=
	CapsLock::m
	<!w::Send {x down}			; <! = left alt
	<!w Up::Send {x up}
#If

; left alt needs to be remapped to push to talk so that it only works in the active wow window
; except that I can't rebind alt in wow so long as alt is used for other things as well. Lame.
; this rebind is just for interact with mouseover now. :(

#If WinActive("ahk_group justWow") and not GetKeyState("ScrollLock", "T")
	LAlt::`
#If
Is this the information you were looking for?
User avatar
rommmcek
Posts: 1475
Joined: 15 Aug 2014, 15:18

Re: Rebind left alt to push to talk key, " ` " (vkDFsc029)

03 Aug 2019, 06:28

I noticed a thing, that might help you: sign ` in AutoHotkey is reserved and is used as escape character.
So to send it you must escape it!: Send, ``.

Btw, which sing represents vkDFsc029?
User avatar
rommmcek
Posts: 1475
Joined: 15 Aug 2014, 15:18

Re: Rebind left alt to push to talk key, " ` " (vkDFsc029)

03 Aug 2019, 17:29

Your post appears on the form with the delay (for the security reason, because you're a new member).
Maybe this was what confused me.

Try to run this script:

Code: Select all

if not A_IsAdmin
{
   Run *RunAs "%A_ScriptFullPath%"  ; Requires v1.0.92.01+
   ExitApp
}

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance, Force

if !GetKeyState("ScrollLock", "T") ; just to prevent firing right away.
    Send, {ScrollLock}
    
loop, {
    if !GetKeyState("ScrollLock", "T")
        Send, ``
    sleep, 25
}

^Esc::
    if GetKeyState("ScrollLock", "T") ; untoggle ScrollLock.
        Send, {ScrollLock}
ExitApp
Then run or activate your application where do you want to Send `.
Then toggle ScrollLock a few times.
To exit the script press Ctrl + Esc.

If the script works, there is a good chance for success.

===========================================================

Try this script once again, just to be sure:

Code: Select all

if not A_IsAdmin
{
   Run *RunAs "%A_ScriptFullPath%"  ; Requires v1.0.92.01+
   ExitApp
}

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance, Force

LAlt::`

^Esc::ExitApp
croana
Posts: 48
Joined: 30 Jul 2019, 14:46

Re: Rebind left alt to push to talk key, " ` " (vkDFsc029)

04 Aug 2019, 07:51

Yeah, the post delay is really annoying, especially because I'm in EU, so often I post before the mods are awake, it seems. It can take hours for my post to go live.

vkDFsc029 is `. I used the code specifically because I was worried about ` being an escape character in ahk, but you recommended I use lalt::` instead of lalt::Send, {vkDFsc029}, so that's what I've been doing what you wanted in order to test.

Edit:
Woo! This post went live in less than 10 min. Thanks mods!

I'm just gonna keep editing this post so we can avoid the delay anyway. Sorry that this is a bit of stream of consciousness...

Testing script 1:
Toggling scroll lock causes ` to be pressed and released over and over again, which does indeed enable/disable push to talk a whole lot in discord. Even when I'm in wow.

This sort of behavior is actually super problematic in wow itself, because it would probably be considered automation. Straight up automation isn't allowed by the warcraft TOS/ EULA. They have a rule of one keypress must equal one action. If I were to use this, I'd 100% need to rewrite it so that the loop only worked while a key was actively PRESSED, not just toggled. Using scroll lock to turn keybinds on/off are fine, since it doesn't actually cause the keys to be pressed. Using scroll lock to toggle a key press loop on/ off is not fine.

Testing script 2:
This script is way more interesting.

Alt rebound to ` in wow actually works! Pressing alt actually triggers push to talk in discord as expected! Cool!

I'm going to try to add this to my script and see if it works....

...No it doesn't work. I thought it did, but I forgot that I still had my old keyboard software running because I'm on my windows 7 machine right now. Crap.

Here's the current script:

Code: Select all

if not A_IsAdmin
{
   Run *RunAs "%A_ScriptFullPath%"  ; Requires v1.0.92.01+
   ExitApp
}

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance, Force

GroupAdd, justWow, ahk_exe wow.exe
GroupAdd, justWow, ahk_exe Wow.exe
GroupAdd, gaming, ahk_group justWow
GroupAdd, gaming, ahk_exe dxNothing.exe
Return

#If WinActive("ahk_group gaming") and not GetKeyState("ScrollLock", "T")
	p::B
	*c::Send {LAlt down}
	*c Up::Send {LAlt up}
	*v::Send {LControl down}
	*v Up::Send {LControl up}
	b::Send {vkBAsc027}
	t::c
	F5::n
	PrintScreen::y
	F9::j
	r::=
	CapsLock::m
	<!w::Send {x down}			; <! = left alt
	<!w Up::Send {x up}
#If

; left alt needs to be remapped to push to talk so that it only works in the active wow window

#If WinActive("ahk_group justWow") and not GetKeyState("ScrollLock", "T")
	LAlt::`
#If

^Esc::ExitApp

You're still amazing.

I tried moving LAlt::` outside of the #if statement and it still doesn't work. What's the difference between your 2nd script and my script? Your 2nd script works. My script doesn't. I don't think you're seeing these edits because I thought my script worked. :(
Last edited by croana on 04 Aug 2019, 08:31, edited 4 times in total.
User avatar
rommmcek
Posts: 1475
Joined: 15 Aug 2014, 15:18

Re: Rebind left alt to push to talk key, " ` " (vkDFsc029)

04 Aug 2019, 08:17

This is good news.
It was just a crude test script!

Try in the second script Send, `` too!!!
croana
Posts: 48
Joined: 30 Jul 2019, 14:46

Re: Rebind left alt to push to talk key, " ` " (vkDFsc029)

04 Aug 2019, 08:21

Gonna risk and see if the mods approve this fast. :) Edit: It was not fast this time.

LAlt::`` actually causes an error when I try to run the code. So it looks like LAlt::` is the way to go, suprisingly.

Do you mind explaining what these pieces of the code do? I'd just like to be able to tell other people what they're doing if they ask.

Code: Select all

if not A_IsAdmin
{
   Run *RunAs "%A_ScriptFullPath%"  ; Requires v1.0.92.01+
   ExitApp
}
and

Code: Select all

#SingleInstance, Force
Edit:

My new posts aren't getting past the mods. Your script and my script aren't playing nice together. I can EITHER have a rebound alt button, or I can have the rest of my rebinds. They don't work well at the same time.
Last edited by croana on 04 Aug 2019, 14:33, edited 2 times in total.
User avatar
rommmcek
Posts: 1475
Joined: 15 Aug 2014, 15:18

Re: Rebind left alt to push to talk key, " ` " (vkDFsc029)

04 Aug 2019, 08:28

If it works, that's fine!!!
Then we're finished! This is the most natural solution too, even if I had an idea to make first script behave equally to the second (if it wouldn't work).

Yeh, this was still better news!

bye!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: doodles333, Frogrammer, Google [Bot] and 258 guests