Wait until commandKey is down only works once

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Fermin
Posts: 151
Joined: Fri Jun 05, 2015 10:44 pm

Wait until commandKey is down only works once

Post by Fermin » Fri Aug 22, 2025 8:21 pm

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!

SWEdeAndy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 326
Joined: Sat Aug 16, 2008 9:48 am
Contact:

Re: Wait until commandKey is down only works once

Post by SWEdeAndy » Fri Aug 22, 2025 9:47 pm

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... :)
Andreas Bergendal
Independent app and system developer
Free LC dev tools: https://github.com/wheninspace
(WIS_WebDeployHelper, WIS_ScriptDependencies, WIS_BrowserAnimation)
WhenInSpace: https://wheninspace.com

Fermin
Posts: 151
Joined: Fri Jun 05, 2015 10:44 pm

Re: Wait until commandKey is down only works once

Post by Fermin » Fri Aug 22, 2025 10:08 pm

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. :) :) :)

Post Reply