Page 1 of 1

Wait until commandKey is down only works once

Posted: Fri Aug 22, 2025 8:21 pm
by Fermin
Hi, I’m facing a problem I thought I had already solved, but now I’m stuck again and can’t make it work.
I’m trying to run three actions, each triggered by a separate press of the Command key:

Code: Select all

on mouseUp
   wait until the commandKey is down 
   put "AAAAA"

   wait until the commandKey is down 
   put "BBBBB"

   wait until the commandKey is down
   put "CCCCC"
end mouseUp

But it runs through all steps quickly after the first press, as if the key remains down and the condition is always true.

I’ve tried approaches like repeat while, repeat until, is down, is up... but nothing seems to work.
Could someone please help?

Thanks in advance!

Re: Wait until commandKey is down only works once

Posted: Fri Aug 22, 2025 9:47 pm
by SWEdeAndy
Either you can use a counter variable, to just perform different actions depending on the number of times the command key has been down and up.

Or introduce a wait period in between key presses:

Code: Select all

   wait until the commandKey is down 
   put "AAAAA"
   wait 1 secs with messages
   
   wait until the commandKey is down 
   put "BBBBB"
   wait 1 secs with messages
   
   wait until the commandKey is down
   put "CCCCC"
The reason your code example does not work as you intend is that as soon as the "commandKey is down" condition is satisfied, it takes like a millisec to process the rest of the code, so no human can be fast enough to release the command key before the script is already at the end. So all you see is CCCCC... :)

Re: Wait until commandKey is down only works once

Posted: Fri Aug 22, 2025 10:08 pm
by Fermin
Great, thank you so much, SWEdeAndy. And since this is about synchronizing musical moments where a second is sometimes too long, I assume ticks might work. I've tried wait 10 with messages and it seems to be working. :) :) :)