Author Topic: Have one key do two separate things  (Read 1630 times)

exltride

  • Newbie
  • *
  • Posts: 6
Have one key do two separate things
« on: November 03, 2023, 01:52:27 PM »
Basically all I want to do is have my spacebar be used as it normally would be with a short press and then if I hold it down for a second and 1/2 or maybe two have it press a different key and I've tried activating the macro with long press but that didn't work I'm sure there's some kind of if and or statement but I can't figure it out.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4781
  • RTFM
Re: Have one key do two separate things
« Reply #1 on: November 03, 2023, 02:05:25 PM »
A command like this could accomplish that:
Code: [Select]
Set date [~holdTime] to [~holdTime] plus [2] seconds
Start Loop While :  Keyboard Key 'Space' Is Pressed
    Begin Date Compare : [~holdTime] Is Before Current Date/Time
        Press A key and hold for 0.1 seconds and release
    End Condition - Exit when condition met
End Loop
Press Space key and hold for 0.1 seconds and release

Configure it to trigger when the spacebar is pressed; leave everything but the "Do not allow key to be passed through" option disabled (unchecked)

exltride

  • Newbie
  • *
  • Posts: 6
Re: Have one key do two separate things
« Reply #2 on: November 03, 2023, 02:18:36 PM »
Okay that makes sense and seems like it should work, except I don't know how to actually put that into voice attack, I know how to start and end a loop but I don't understand the start date part but I should be able to Google it hopefully thank you that at least gives me somewhere to start

exltride

  • Newbie
  • *
  • Posts: 6
Re: Have one key do two separate things
« Reply #3 on: November 03, 2023, 02:39:42 PM »
Well I hobbled it together and it does work for what I need it to do but I'm not sure how to get the wait time to work properly this is going to be really ugly but this is what I have so far

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4781
  • RTFM
Re: Have one key do two separate things
« Reply #4 on: November 03, 2023, 02:45:17 PM »
The first action should be configured to use its "Add" option to add 2 seconds (or however much time the spacebar would need to be held down for to trigger the alternate key), making sure the "Evaluate Not Set as current date/time" option is enabled (which it should be by default).

What's in the "Code" block in my post should be what's in your command's action list, verbatim, when configured correctly.

exltride

  • Newbie
  • *
  • Posts: 6
Re: Have one key do two separate things
« Reply #5 on: November 03, 2023, 02:52:00 PM »
Yeah I haven't figured out how to copy code from this or any other source and put it directly into voice attack but I was able to mess around and I as far as I can tell have it set to do what I needed to do. This is what I have ended up having an actually works the way I want it to

Code: [Select]
Set date [[~holdTime]] value to the value of [[~0.2] to [~2]]
Start Loop While :  Keyboard Key 'Space' Is Pressed
    Begin Date Compare : [[~holdTime]] Is Before Current Date/Time
        Press S key and hold for 0.2 seconds and release
    End Condition - Exit when condition met
End Loop
Press Space key and hold for 0.2 seconds and release

exltride

  • Newbie
  • *
  • Posts: 6
Re: Have one key do two separate things
« Reply #6 on: November 03, 2023, 02:59:10 PM »
Nevermind it's not working I forgot that I had something else enabled

exltride

  • Newbie
  • *
  • Posts: 6
Re: Have one key do two separate things
« Reply #7 on: November 03, 2023, 03:05:45 PM »
Okay well I take it all back you are a genius and I am just really stupid LOL I have gotten it to work I did not need to add the brackets myself or any of that other stuff and I found the add option that you were talking about and it works like a charm

SemlerPDX

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 291
  • Upstanding Lunatic
    • My AVCS Homepage
Re: Have one key do two separate things
« Reply #8 on: November 04, 2023, 12:50:19 PM »
Yeah I haven't figured out how to copy code from this or any other source and put it directly into voice attack ...

You cannot copy "code" or examples of VoiceAttack actions such as those presented by Pfeil above.  This is not in fact code, but a list of actions as they would appear in a VoiceAttack command once they are manually added by us users.

These actions have individual options menu screens, and so could not be copy/pasted even if it was possible because a lot of information would be lost - for example, the checkbox to evaluate 'not set' as 'current date/time' for setting a date/time variable, among others.

When we share these examples, it's required to add each individual action as you had done, so that once complete, the actions list looks exactly like the example provided.  The only way to actually share a command that would function would be to share a VoiceAttack profile containing the command(s) already configured, but it more preferable for us to teach users how to create these things for themselves and work through the actions necessary rather than simply provide a working command by sharing an example profile with example command(s).  This way, we are preparing you to create anything you can dream up in VoiceAttack commands as opposed to teaching you to ask someone to make the things for you upon request.

Glad you got it working!! Congrats and best wishes with your profile commands!