1

I'm using livecode 9.6.0 on an iMac. the commands 'commandKeyDown and 'escapeKey' don't work. The escapeKey doesn't work with keyDown either. Anyone have any ideas?

Malcolm
  • 11
  • 1
  • Can you share some code showing how you are using these? Keep in mind that commandKeyDown, escapeKey, and keyDown are messages, not commands. – Devin Aug 26 '20 at 14:26

3 Answers3

1

Do you have the commandKeyDown handler in the card or stack script? This message has to be used in either of those, or a control that can have focus, like a field. It cannot easily be trapped in, say, a button script, where focus is rarely obvious.

Similarly with "escapekey". I bet you are not quite using them correctly.

Same for "keyDown", the message will not be sent without a focused control, unless the stack or card traps it, since those objects always "have focus".

So, in a field script, for example;

 on commandkeyDown tkey
   if  tkey = "3" then beep 3
 end commandkeyDown
dunbarx
  • 756
  • 5
  • 4
  • Unfortunately commandKeyDown, and escapeKey are not even recognised in the script, bringing up a red cross, so I don't get as far as trying to run the script. I even copied the script suggestion in the dictionary to no avail. – Malcolm Aug 26 '20 at 16:38
0

It is hard to know what is going on without seeing the actual script you are working with. The issue is the origin of these messages, which are a little tricky if not generated by a control with focus. There are likely kludges around the problem, but without seeing the handlers, and the environment they live in, there is no way to tell.

dunbarx
  • 756
  • 5
  • 4
  • Hi dunbarx, thanks for your reply. I probably didn't explain properly what is going on. When I enter the commandKeydown or escapeKey instructions, the red cross shows in the margin, indicating there is an error, even if the syntax is correct. Also the instruction words don't change colour when typed, unlike valid instructions. So of course the script doesn't compile. The rest of the code is really irrelevant. – Malcolm Sep 03 '20 at 15:24
0

First, the keyDown event is for alphanumeric keys. CommandKeyDown is only generated when you use a command key in combination with another key. Use rawkeydown instead of keydown for capturing function keys. Remember to pass rawkeydown if you want the event to propagate further.

Check this:

on commandKeyDown pKeyName
   answer "Command+"  & pKeyName
end commandKeyDown


on escapeKey -- return to the last card visited
   answer "Escape with escapeKey event"
end escapeKey

on rawkeydown pkey
   
   switch pkey
      case "65307"
         answer "Escape key with rawkeydown event"
         break
   end switch
   pass rawkeydown
end rawkeydown
ouflak
  • 2,458
  • 10
  • 44
  • 49
William
  • 56
  • 4