Author Topic: Toggle Key Not Working As Expected  (Read 7495 times)

vonFelty

  • Guest
Toggle Key Not Working As Expected
« on: December 18, 2016, 12:23:33 AM »
So I believe I got this command working. Basically in Star Citizen we need to hold shift key down to run after burner.

I basically want to have a keyboard shortcut to toggle weather or not shift key is being held down.

I have created a command, which executes, but it seems to just hold down the shift key and won't toggle off.

Is there something I am doing wrong?

iceblast

  • Sr. Member
  • ****
  • Posts: 372
Re: Toggle Key Not Working As Expected
« Reply #1 on: December 18, 2016, 02:26:41 AM »
All you should have to do is, make a toggle key.

Code: [Select]
Toggle Left Shift key

Make a new command.

Hit Press Keys.

Shift

Radio button: Toggle Key

Done.

That should turn Shift on and off like a light switch.

Are you doing this, or something else?



« Last Edit: December 18, 2016, 02:30:23 AM by iceblast »

vonFelty

  • Guest
Re: Toggle Key Not Working As Expected
« Reply #2 on: December 18, 2016, 06:15:38 PM »
Well the toggle key turns the shift key on, but does not turn it off when pressed.

However I was able to use PageUp and PageDown to press and release keys just fine.

This is 1.6.1.7

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4749
  • RTFM
Re: Toggle Key Not Working As Expected
« Reply #3 on: December 18, 2016, 07:02:10 PM »
Could you verify whether it works in something like notepad? Just hold a letter key and use the toggle command, see if it produces capital letters when on and not when off.

vonFelty

  • Guest
Re: Toggle Key Not Working As Expected
« Reply #4 on: December 21, 2016, 04:38:34 PM »
Yeah. I tested in note pad.

What happens it will activate the ctrl+shift+C key as a button press so everything I type is in caps.

However pressing ctrl+shift+C key again does not toggle it off. Am I doing something wrong?
« Last Edit: December 21, 2016, 05:44:51 PM by vonFelty »

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4749
  • RTFM
Re: Toggle Key Not Working As Expected
« Reply #5 on: December 21, 2016, 05:09:49 PM »
Here's what's likely happening: You press CTRL+SHIFT+C, so shift is quickly toggled on then off again as you release the combination. 0.5 seconds(ish) later, shift is toggled from its off state back to on.

So the toggle action itself is doing what you're asking, except the state it's toggling from is always off, so the end result is always on.

iceblast

  • Sr. Member
  • ****
  • Posts: 372
Re: Toggle Key Not Working As Expected
« Reply #6 on: December 22, 2016, 05:21:05 AM »
This will do what you want it to do. Using CTRL+SHIFT+C as the trigger. I've tested it, and it works fine for me.

Honestly, I don't know why it works. That EXP is getting the wrong answer, yet it works. The answer should be 1, that is sees all 3 keys pressed, yet, the answer is 0, meaning it's not seeing all keys pressed, but the answer is good enough to allow the command to work properly with the trigger keys CTRL+SHIFT+C. Which is the more important part. :)


Code: [Select]
Begin Small Integer Compare : [Afterburner] Has Not Been Set
    Set small int (condition) [Afterburner] value to 1
End Condition
Begin Small Integer Compare : [Afterburner] Equals 1
    Begin Text Compare : [{EXP:({STATE_KEYSTATE:SHIFT} + {STATE_KEYSTATE:CTRL} + {STATE_KEYSTATE:C})}] Equals '0'
        Say, 'Afterburner ON'
        Press down Left Shift key
        Write '[Blue] Afterburner ON' to log
        Set small int (condition) [Afterburner] value to 2
    End Condition - Exit when condition met
End Condition - Exit when condition met
Begin Small Integer Compare : [Afterburner] Equals 2
    Begin Text Compare : [{EXP:({STATE_KEYSTATE:SHIFT} + {STATE_KEYSTATE:CTRL} + {STATE_KEYSTATE:C})}] Equals '0'
        Say, 'Afterburner off'
        Release Left Shift key
        Set small int (condition) [Afterburner] value to 1
        Write '[Blue] Afterburner OFF' to log
    End Condition - Exit when condition met
End Condition - Exit when condition met


Hope this helps!

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4749
  • RTFM
Re: Toggle Key Not Working As Expected
« Reply #7 on: December 22, 2016, 06:18:34 AM »
Here's how I would do it:
Code: [Select]
Start Loop While : [{EXP:({STATE_KEYSTATE:SHIFT} + {STATE_KEYSTATE:CTRL} + {STATE_KEYSTATE:C})}] Does Not Equal '0'
End Loop
Begin Boolean Compare : [Afterburner] Equals False
    Say, 'Afterburner on'
    Pause 0,5 seconds
    Press down Left Shift key
    Set Boolean [Afterburner] to True
Else
    Say, 'Afterburner off'
    Pause 0,5 seconds
    Release Left Shift key
    Set Boolean [Afterburner] to False
End Condition
This way, VoiceAttack will wait until you release the key combination(entirely, you could check for shift only if you prefer).
Note that the Boolean compare has "Evaluate 'Not Set' as false" checked, this way there is no need to initialize the value by setting it beforehand.

iceblast

  • Sr. Member
  • ****
  • Posts: 372
Re: Toggle Key Not Working As Expected
« Reply #8 on: December 22, 2016, 06:35:49 AM »
Question:

How long does this loop run? And Why does VA wait for the key release?

Code: [Select]
Start Loop While : [{EXP:({STATE_KEYSTATE:SHIFT} + {STATE_KEYSTATE:CTRL} + {STATE_KEYSTATE:C})}] Does Not Equal '0'
End Loop

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4749
  • RTFM
Re: Toggle Key Not Working As Expected
« Reply #9 on: December 22, 2016, 07:03:26 AM »
How long does this loop run? And Why does VA wait for the key release?
As long as any one key of the combination is still held down. As soon as all of them are released, the loop stops because the condition is no longer true.

The wait is built in to make sure the shift key is physically released before VoiceAttack attempts to change the state.

On my machine at least, "{EXP:({STATE_KEYSTATE:SHIFT} + {STATE_KEYSTATE:CTRL} + {STATE_KEYSTATE:C})}" will return "1" if shift is down(or "on", if you prefer), so the "Afterburner off" section in your example would never trigger.

You could do it without the loop, counting only on the half second delay in which you'd have to release the physical shift key; If you don't, the loop will "press down" the key, but releasing the physical key will reset the state to "up".

It could also be argued explicitly turning shift "off" is redundant, but attempting to release a key that already has an "up" state shouldn't have any ill effects.

iceblast

  • Sr. Member
  • ****
  • Posts: 372
Re: Toggle Key Not Working As Expected
« Reply #10 on: December 22, 2016, 07:05:20 AM »
Been playing around with your command.

I now understand why my command wasn't going quite as expected.

This command isn't needed for Afterburner to work though.

Code: [Select]
Start Loop While : [{EXP:({STATE_KEYSTATE:SHIFT} + {STATE_KEYSTATE:CTRL} + {STATE_KEYSTATE:C})}] Does Not Equal '0'
End Loop

Just this command will do the trick just fine.

Code: [Select]
Begin Boolean Compare : [Afterburner] Equals False
    Say, 'Afterburner on'
    Pause 0.5 seconds
    Press down Left Shift key
    Set Boolean [Afterburner] to True
Else
    Say, 'Afterburner off'
    Pause 0.5 seconds
    Release Left Shift key
    Set Boolean [Afterburner] to False
End Condition

You can even add this to it, so it only works while in Elite.

Code: [Select]
Begin Text Compare : [{WINDOWTITLEUNDERMOUSE}] Contains 'Elite'
    Begin Boolean Compare : [Afterburner] Equals False
        Say, 'Afterburner on'
        Pause 0.5 seconds
        Press down Left Shift key
        Set Boolean [Afterburner] to True
    Else
        Say, 'Afterburner off'
        Pause 0.5 seconds
        Release Left Shift key
        Set Boolean [Afterburner] to False
    End Condition
End Condition

I'm guessing Elite is in the Windows Title, If not, change it to the Windows Title. :)
« Last Edit: December 22, 2016, 07:23:59 AM by iceblast »

iceblast

  • Sr. Member
  • ****
  • Posts: 372
Re: Toggle Key Not Working As Expected
« Reply #11 on: December 22, 2016, 07:21:23 AM »
I was originally thinking that it would compare the states. So, if all were 1 the answer would be 1.

I forgot that {EXP:({STATE_KEYSTATE:SHIFT} + {STATE_KEYSTATE:CTRL} + {STATE_KEYSTATE:C})} is adding the states together, if all are pressed, they add up to 3, but if you have Shortcut is invoked when all keys are released check, the answer is 0. That's why my answer was 0. If you don't have the shortcut invoked box checked, the answer will be 3.

Also, I checked, and it doesn't seem to matter how long you hold the keys before release, it doesn't appear to have any effect on the Shift key. The command seems to always work as you wish it too.


« Last Edit: December 22, 2016, 07:32:18 AM by iceblast »

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4749
  • RTFM
Re: Toggle Key Not Working As Expected
« Reply #12 on: December 22, 2016, 07:36:32 AM »
it doesn't seem to matter how long you hold the keys before release, it doesn't appear to have any effect on the Shift key.
If you hold the shortcut while VoiceAttack attempts to toggle shift, the shift key will always end up released. At least on my machine.

However, you make a good point in that "Shortcut is invoked only when all keys are released" will prevent shift from remaining pressed, rendering the loop section redundant.