Author Topic: How can I re-map keys using VoiceAttack?  (Read 168 times)

Sethioz

  • Newbie
  • *
  • Posts: 8
How can I re-map keys using VoiceAttack?
« on: October 03, 2018, 08:53:40 pm »
Hey, I have quite specific request, hope someone can help.

I want to be able to use VoiceAttack to remap my keyboard buttons. It's needed for a game where different profiles comes in handy, sure I can do it via my gaming keyboard's profile, but that's not same. I want it to be on Voice.

So for example If i press "V" I want VoiceAttack to press "E" instead, just like if V = E
It should also hold the button down, so if i hold down V then in game E is being kept down.

And finally it has to work with a voice command, for example if I say "swap controls" then it should replace V with E and keep it that way until I say "swap controls back" or like "default controls"

I was able to use the "if key is pressed" option and "do not allow key to be passed through", but that's not what I need. It doesn't exactly hold down E when pressing V, it just clicks it really fast.
Also it's not on voice command.

Does anyone know more specific solution that would work the way I need it? thanks.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1570
  • RTFM
Re: How can I re-map keys using VoiceAttack?
« Reply #1 on: October 03, 2018, 09:49:55 pm »
You can use that option, and opt to always have VoiceAttack send the keypress:

E.G.
remap V
Code: [Select]
Begin Text Compare : [pressForV] Has Not Been Set
    Set Text [pressForV] to 'V'
End Condition
Press down variable key(s) [pressForV]
Start Loop While :  Keyboard Key 'V' Is Pressed
End Loop
Release variable key(s) [pressForV]

With a companion command
swap controls [back;];default controls
Code: [Select]
Begin Text Compare : [{CMD}] Equals 'swap controls'
    Set Text [pressForV] to 'E'
Else
    Set Text [pressForV] to 'V'
End Condition

However, this doesn't so much "swap" the keys as have two send the same thing(E.G. pressing either "V" or "E" would send "e").
As this is intended for a game, it shouldn't be an issue, but it's worth noting that text input won't autorepeat(E.G. if you hold "V" in notepad, it'll type either a single "v" or a single "e").


If you really do need a swap(and don't want to add commands for all the keyboard keys you may want to use), while you could theoretically use the "Block Keyboard Input" action to do that dynamically, and have a command looping in the background, the simpler method is to use AutoHotKey to do the swapping, and have VoiceAttack launch or stop the appropriate script.

E.G.
Code: [Select]
Begin Text Compare : [{CMD}] Equals 'swap controls'
    Run application 'C:\Program Files\AutoHotkey\AutoHotkey.exe' -with parameters '"{VA_APPS}\keySwappingProfiles\VtoE.ahk"'
Else
    Press F24 key and hold for 0,06 seconds and release
End Condition

Where "VtoE.ahk" contains
Code: [Select]
#SingleInstance ignore
#MaxHotkeysPerInterval 200
F24::ExitApp
v::e
e::v
This will swap "V" and "E" around, allow you to press the key rapidly without AutoHotKey warning you(which is a safety feature, in case a script goes off the rails), and discard any new instance of the script(in case you run "swap controls" twice).
F24(some keyboards used to have F13 to F24 in addition to F1 to F12, but this is no longer physically present on modern keyboards, which means it can be used without interfering with actual user input) is used to enable terminating that specific AutoHotKey script, while leaving any others running; If you don't need that you could terminate the "AutoHotKey" process instead.

As this allows you to specify many keys to swap, you can use each script as a profile, and start the appropriate one with a voice command when you need it(while terminating the running one, if any).

Sethioz

  • Newbie
  • *
  • Posts: 8
Re: How can I re-map keys using VoiceAttack?
« Reply #2 on: October 03, 2018, 10:20:26 pm »
Nice thanks :) but i'm still bit confused, which option do I need to use in VoiceAttack to enter the code?

However i'm not sure if autohotkey is allowed in that game, it uses anti-cheat and i've heard lot of anti-cheats ban you for using autohotkey on background, i'd prefer using only VoiceAttack, is that possible?

The first option would only work if it actually swaps 2 keys, because I actually need to swap V with E, so E does V and V does E (it's example tho, I'd have to swap about 8 keys total to make it really handy).

Gangrel

  • Caffeine Fulled Mod
  • Global Moderator
  • Full Member
  • *****
  • Posts: 190
Re: How can I re-map keys using VoiceAttack?
« Reply #3 on: October 04, 2018, 02:31:50 am »
Nice thanks :) but i'm still bit confused, which option do I need to use in VoiceAttack to enter the code?

However i'm not sure if autohotkey is allowed in that game, it uses anti-cheat and i've heard lot of anti-cheats ban you for using autohotkey on background, i'd prefer using only VoiceAttack, is that possible?

Its possible, but if you are worried about getting banned for it with AHK, then you should also get worried for being banned for it with VA.

Personally speaking though, if all you are doing is basic remap (ie swapping one key for another, and nothing extra (ie multiple key presses makes you rotate through a series of keys) then you *should* be fine no matter the issue.

Side note: If they are banning you just for having AHK running in the background, then I would be banned right from the get go, as I use AHK for numerous non-ingame functions...

Sethioz

  • Newbie
  • *
  • Posts: 8
Re: How can I re-map keys using VoiceAttack?
« Reply #4 on: October 04, 2018, 03:23:55 am »

Its possible, but if you are worried about getting banned for it with AHK, then you should also get worried for being banned for it with VA.

Personally speaking though, if all you are doing is basic remap (ie swapping one key for another, and nothing extra (ie multiple key presses makes you rotate through a series of keys) then you *should* be fine no matter the issue.

Side note: If they are banning you just for having AHK running in the background, then I would be banned right from the get go, as I use AHK for numerous non-ingame functions...

I can ask them, but i'd rather use only VoiceAttack if possible. It's also the matter of running Autohotkey when i start the game + VoiceAttack. I don't want to do all that, i just wanna boot up VA and have it ready.

Gangrel

  • Caffeine Fulled Mod
  • Global Moderator
  • Full Member
  • *****
  • Posts: 190
Re: How can I re-map keys using VoiceAttack?
« Reply #5 on: October 04, 2018, 04:20:27 am »
May I ask as to the game that this is concerning?

The reason as to why I say "If you are worried about banning over AHK, then you should be worried over VoiceAttack" is because it would be *really* bizarre behaviour to ban for one action using one piece of software, and not banning another piece of software for performing the same action.

As in, that is almost giving a cart blanche to say "Hey, use this piece of software, no matter what it does and we won't ban you".

That is why *generally* speaking the rules for banning due to 3rd person software tends to be either 100% zero tolerance no matter the software (which also explains as to why some games don't like Razer/Logitech hardware such as the Nostromo/G13) or go on the rule of "One keypress, one action"

Sethioz

  • Newbie
  • *
  • Posts: 8
Re: How can I re-map keys using VoiceAttack?
« Reply #6 on: October 04, 2018, 08:12:17 am »
May I ask as to the game that this is concerning?

The reason as to why I say "If you are worried about banning over AHK, then you should be worried over VoiceAttack" is because it would be *really* bizarre behaviour to ban for one action using one piece of software, and not banning another piece of software for performing the same action.

As in, that is almost giving a cart blanche to say "Hey, use this piece of software, no matter what it does and we won't ban you".

That is why *generally* speaking the rules for banning due to 3rd person software tends to be either 100% zero tolerance no matter the software (which also explains as to why some games don't like Razer/Logitech hardware such as the Nostromo/G13) or go on the rule of "One keypress, one action"

that's not important, please stay in topic. I don't want to use autohotkey and I'm not interested in discussing anti-cheats. I just need help getting this done only within VoiceAttack.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1570
  • RTFM
Re: How can I re-map keys using VoiceAttack?
« Reply #7 on: October 04, 2018, 09:30:37 am »
It's also the matter of running Autohotkey when i start the game + VoiceAttack. I don't want to do all that, i just wanna boot up VA and have it ready.
AutoHotKey would be started by VoiceAttack when you run the command, that's how the second example works. You wouldn't manually start or stop it, that's what the command is for(and you could use an exit command to kill AutoHotKey when you close VoiceAttack).


Either way, the first example works, and is currently the only way to swap a key through VoiceAttack, as further testing shows: If you use the "Block Keyboard Input" action, neither {STATE_KEYSTATE:}" tokens, nor the "Device State" setting for conditions detect that keypress, so it's impossible to both disable a key but still read its state.

Sethioz

  • Newbie
  • *
  • Posts: 8
Re: How can I re-map keys using VoiceAttack?
« Reply #8 on: October 05, 2018, 08:16:39 pm »
It's also the matter of running Autohotkey when i start the game + VoiceAttack. I don't want to do all that, i just wanna boot up VA and have it ready.
AutoHotKey would be started by VoiceAttack when you run the command, that's how the second example works. You wouldn't manually start or stop it, that's what the command is for(and you could use an exit command to kill AutoHotKey when you close VoiceAttack).


Either way, the first example works, and is currently the only way to swap a key through VoiceAttack, as further testing shows: If you use the "Block Keyboard Input" action, neither {STATE_KEYSTATE:}" tokens, nor the "Device State" setting for conditions detect that keypress, so it's impossible to both disable a key but still read its state.

I'm still having trouble finding on how to add code into voice attack, which option do i need to use to add your code into voiceattack?
I haven't used any code-based commands before


EDIT: sometimes i just ask before I put my mind into it ... I thought there's an easy option to just paste the code, but now i realize i have to add commands one by one. Think i got it working, will test soon :)
« Last Edit: October 05, 2018, 08:42:02 pm by Sethioz »

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1570
  • RTFM
Re: How can I re-map keys using VoiceAttack?
« Reply #9 on: October 05, 2018, 08:23:28 pm »
"Code" is just the name of the forum tag, what's listed is what you should recreate in your action list, just like you'd build any VoiceAttack command.

The text in italics above the code blocks is the contents of the "When I say" field for that respective command.

Sethioz

  • Newbie
  • *
  • Posts: 8
Re: How can I re-map keys using VoiceAttack?
« Reply #10 on: October 05, 2018, 08:44:15 pm »
"Code" is just the name of the forum tag, what's listed is what you should recreate in your action list, just like you'd build any VoiceAttack command.

The text in italics above the code blocks is the contents of the "When I say" field for that respective command.

Thanks for quick replies, yeah I know, I edited the last post too. I thought there's an option in VA to easily add entire block of code and it will do all the things listed in that block.


Sethioz

  • Newbie
  • *
  • Posts: 8
Re: How can I re-map keys using VoiceAttack?
« Reply #11 on: October 05, 2018, 09:14:29 pm »
Thanks for the help, it was very easy actually, I should have spent some time going through VA :)

I'm not sure why i need the conditional and else blocks tho, here's what I did:

I set a simple voice command to launch autohotkey script to swap my controls
- Just a "run application" with parameters (path to the script)

and then another command to press F24 for me when I say "reset controls", so it terminates the autohotkey script.

However I noticed something odd, why can't i terminate autohotkey.exe by process? At first i wanted to make it simple and just terminate the process, but VA fails to do so.
I chose autohotkey.exe from the processes to stop it, but it won't work on some reason. I ran VA as admin too, but still doesn't work.

Any ideas why? It's not that important as I used that F24 trick to terminate the AHK, but still odd that it won't stop it by process.

Anyway thanks a lot for help :-)

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1570
  • RTFM
Re: How can I re-map keys using VoiceAttack?
« Reply #12 on: October 05, 2018, 09:51:25 pm »
I'm not sure why i need the conditional and else blocks
They condense both commands down into one, which I personally prefer to keep profiles easier to maintain, but as you can of course use separate commands, as you have.

However I noticed something odd, why can't i terminate autohotkey.exe by process? At first i wanted to make it simple and just terminate the process, but VA fails to do so.
I chose autohotkey.exe from the processes to stop it, but it won't work on some reason. I ran VA as admin too, but still doesn't work.
Did you actually add ".exe" in your command? Process names don't include the extension.

Code: [Select]
Close 'AutoHotkey' process
Works fine on my machine.

Gangrel

  • Caffeine Fulled Mod
  • Global Moderator
  • Full Member
  • *****
  • Posts: 190
Re: How can I re-map keys using VoiceAttack?
« Reply #13 on: October 05, 2018, 10:13:15 pm »
I would recommend exiting by hotkey over terminating the process *generally* speaking.

If you terminate by process, there is *no* guarantee that it will exit gracefully, and whilst it may be suitable in this occurrence, it is not recommended to do it for everything. For one thing, if the script saved information to a file when it was closed via the hotkey, then terminating the process would skip this part, or maybe even corrupt what it was trying to save.

So whilst yes, suitable to do in this case, it is *most definitely* not best practice.

Sethioz

  • Newbie
  • *
  • Posts: 8
Re: How can I re-map keys using VoiceAttack?
« Reply #14 on: October 06, 2018, 02:31:14 am »
thanks guys for all the help, I already got it working by using the F24 trick. I've actually been using F13 - F24 keys for various things in the past, but less and less programs nowdays recognize it. Tried using F13 - F24 in nvidia's shadowplay, but it won't take them as hotkeys.

Anyway a new command in VA with simple F24 press works fine if i want to swap it back to normal (close the script)

Exergist

  • Sr. Member
  • ****
  • Posts: 332
  • Can you dig it?
Re: How can I re-map keys using VoiceAttack?
« Reply #15 on: October 08, 2018, 07:41:15 am »
@Sethioz - I'm glad you found a solution that works for you.

If you're feeling particularly crazy (or you just want better integration between VA and AHK), then check out VA-AHK.Integration. I'm guessing it's far more than you'll need, but I figured I'd throw it out there as another way to manage AHK functionality within VA (as well as better communicate between the two if that's something you want down the road).