Author Topic: Variable keys press  (Read 2496 times)

johnliem

  • Newbie
  • *
  • Posts: 49
Variable keys press
« on: January 13, 2020, 02:19:46 AM »
Hello

Is it possible to do variable keys press, for example

When I press once key A execute command A
When I press twice key A execute command B
When I press three times  key A execute command C , thank you.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Variable keys press
« Reply #1 on: January 13, 2020, 11:43:07 AM »
This should accomplish that:
Code: [Select]
Begin Boolean Compare : [>>{CMDWHENISAY}waiting] Equals True
End Condition - Exit when condition met
Set Boolean [>>{CMDWHENISAY}waiting] to True
Set date [~timeout] to [~timeout] plus [300] milliseconds
Set Boolean [~waitingForRelease] to True
Start Loop While : [~timeout] Is After Current Date/Time
    Begin Device State Check :  Keyboard Key 'A' Is Pressed
        Begin Boolean Compare : [~waitingForRelease] Equals False
            Set integer [~pressCount] to [~pressCount] plus 1
            Begin Integer Compare : [~pressCount] Equals 2
                Loop Break
            End Condition
            Set date [~timeout] value to [Not Set]
            Set date [~timeout] to [~timeout] plus [300] milliseconds
            Set Boolean [~waitingForRelease] to True
        End Condition
    Else
        Set Boolean [~waitingForRelease] to False
    End Condition
End Loop
Begin Integer Compare : [~pressCount] Equals 0
    Write [Blue] 'Single press' to log
Else If Integer Compare : [~pressCount] Equals 1
    Write [Blue] 'Double press' to log
Else
    Write [Blue] 'Triple press' to log
End Condition
Set Boolean [>>{CMDWHENISAY}waiting] to False

The way it's set up, you have 300ms after pressing a key to register a subsequent press. E.G. if you press once, you'll have 300ms in which you need to perform the second press, and 300ms after the second press in which you need to perform the third press.
These include the time the key is held down, E.G. if you hold down A for 150ms then release, you have another 150ms to press it again in order to register a second press.
It's also set up so holding a key down will still allow the command to function, E.G. if you press, release, then hold within 300ms and keep holding down the key, that will register as a double press.

johnliem

  • Newbie
  • *
  • Posts: 49
Re: Variable keys press
« Reply #2 on: January 13, 2020, 01:56:29 PM »
Thank you, I will give it a try.

johnliem

  • Newbie
  • *
  • Posts: 49
Re: Variable keys press
« Reply #3 on: January 15, 2020, 11:04:33 AM »
Hello


I did try about this, see attechement 1 and 2, I can press once and then twice with execute only one, it works

but when I try the repeating for number of times like attechement 3, it plays all the waves file together,

so how can I make as attechement 1,2 with repeating for number of times which it willl play one by one as the reapeating only one?


Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Variable keys press
« Reply #4 on: January 15, 2020, 11:10:55 AM »
The "Repeat a specified number of times" option means the command will complete all actions in the action list from start to finish X amount of times whenever the command is executed.

It has nothing to do with how many times a key must be pressed before the command will execute.

johnliem

  • Newbie
  • *
  • Posts: 49
Re: Variable keys press
« Reply #5 on: January 15, 2020, 12:45:44 PM »
Thank you for the reply and understood.

johnliem

  • Newbie
  • *
  • Posts: 49
Re: Variable keys press
« Reply #6 on: January 16, 2020, 11:40:48 AM »
Hello

after succesfully making a command with function once pressed and twice pressed (double tap) to execute 2 diffrence commands with a key pressed  and it works  :) ,

and now I want something diffrence,

will it be possible to do the same funtion as I mentioned above, but this time I do not  want to once pressed and twice pressed (double tap) to do that, only with once key pressed to switch between 2 commands, for example

when I press A key it will execute command 1, and then when I press A again it will execute command 2 without any pause of time in between , in short to use the same key to switch between A to B to A to B and so on,

if it is possible how do I do that? thanks

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Variable keys press
« Reply #7 on: January 16, 2020, 11:58:47 AM »
Yes, that is possible...

Something like
Code: [Select]
Begin Boolean Compare : [>>{CMDWHENISAY}executeB] Does Not Equal True
    Set Boolean [>>{CMDWHENISAY}executeB] to True
    Execute command, 'command 1'
Else
    Set Boolean [>>{CMDWHENISAY}executeB] to [Not Set]
    Execute command, 'command 2'
End Condition
should work.

johnliem

  • Newbie
  • *
  • Posts: 49
Re: Variable keys press
« Reply #8 on: January 16, 2020, 12:11:56 PM »
wow this is really Hero moderator very quick in respons  ;)

but I am a bit confuse you often give the answer with the code, I am not a smilliar with those code, you mentioned earlier that this as an example but could you tell me where I can do this as the code you mentioned, again thanks for quick reply.


I found it where to do but I still do not have any idea how to fill this option.



« Last Edit: January 16, 2020, 01:17:45 PM by johnliem »

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Variable keys press
« Reply #9 on: January 16, 2020, 01:33:29 PM »
Which option? The two "Set a True/False (Boolean) Value" both have the same variable name (">>{CMDWHENISAY}executeB") in the "Variable Name" field. One is set to "True" like in your screenshot, the other is set to "Clear value (set value to Not Set)".

The first action in the command is a "Begin a Conditional (If Statement) Block" action, then the "Set a True/False (Boolean) Value" action, then an "Execute Another Command" action, a "Condition Else" action, another "Begin a Conditional (If Statement) Block" and a "Set a True/False (Boolean) Value" action, finally an "End a Conditional Block" action (which is added automatically with the "Begin a Conditional (If Statement) Block" action).

johnliem

  • Newbie
  • *
  • Posts: 49
Re: Variable keys press
« Reply #10 on: January 16, 2020, 01:41:32 PM »
Okay I will give it  a try.

johnliem

  • Newbie
  • *
  • Posts: 49
Re: Variable keys press
« Reply #11 on: January 16, 2020, 02:20:51 PM »
I think I do not get it yet, but I have done like this but still not working, see the attechement. 

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Variable keys press
« Reply #12 on: January 16, 2020, 02:26:58 PM »
...that looks nothing like the command I posted...

Just import the command attached to this post (using the "Import Commands" button on the "Edit a Profile" window) and change the commands referenced in the "Execute Another Command" actions.

johnliem

  • Newbie
  • *
  • Posts: 49
Re: Variable keys press
« Reply #13 on: January 17, 2020, 02:10:00 AM »
Thnk you, it works.