Modifier keys on Mac and ruby API confusion

The Tool class documentation contains the following constants

CONSTRAIN_MODIFIER_KEY = Shift Key
CONSTRAIN_MODIFIER_MASK = Shift Key
COPY_MODIFIER_KEY = Menu on Mac, Ctrl on PC
COPY_MODIFIER_MASK = Alt on Mac, Ctrl on PC
ALT_MODIFIER_KEY = Command on Mac, Menu on PC
ALT_MODIFIER_MASK = Command on Mac, Alt on PC"

If I’m not mistaking these constants form pairs and are meant to be used in methods that takes a flags argument for the keys currently being pressed as follows:

if flags & CONSTRAIN_MODIFIER_MASK == CONSTRAIN_MODIFIER_MASK
  // The constrain modifier key was pressed
end

The docs however refers to different keys within one key/mask pair on one system. This must be a documentation error, right? Also I can’t remember ever using a menu key as modifier key on PC and the tutorials says Command is used for copying on Mac, not Menu or Alt.

I’m getting really confused and I don’t have a Mac myself to test with so maybe someone with a Mac can answer these questions:

Is the copy modifier in move and rotate tool Option on Mac? (Ctrl in Windows)
Is the lock/constrain inference/direction key always Shift on Mac? (Always shift in Windows)
What is the move tool toggle auto-fold key on Mac? (Alt on Windows)
What is the axes tool alternate axes orientation key on Mac? (Alt on Windows)

I suspect that both places the docs say “Menu” are wrong, as there is no Menu key on a Mac and I think SU uses the alt key as ALT_MODIFIER_KEY.

I’m assuming the rest of your questions are about the physical modifier keys used by the built-in Tools, as opposed to the Ruby symbolic constants…

Yes (the key is sometimes labelled alt, sometimes option, sometimes both depending on keyboard model)

Yes

Command key

Command key

1 Like

Thanks for these answers! This was just what I was looking for.

Do you also happen to know if the key code for Option key passed to onKeyDown and onKeyUp is the same as for the Ctrl key? I’m not familiar with Mac but maybe these are really the same key.

The API provides a constant VK_CONTROL but no VK_OPTION. The VK_ALT and VK_COMMAND constants however have the same value, suggesting Alt and Command are just different names for the same key.

“Alt and Command are just different names for the same key.”
[Edit] WHOOPS. Misread this when I first replied too quickly.
Alt and Command are NOT the same key.

But Alt and Option are - my one year old Apple Magic Keyboard has both names in the same physical key.

But the Mac Ctrl key is a different key with a different key code. Don’t know if it’s the same key code as on Windows but I’d guess not.

I don’t know how many times I’ve mixed up Command and Option today myself :stuck_out_tongue: .

But then it’s settled about Ctrl and Option.

Do you know if the Windows Ctrl and Mac Command have the same position on the keyboard? Since they are used identically in the native SU tools it would make sense if they are the same key, even with Mac having another key named Ctrl.

Command keys are adjacent to both sides of the spacebar. On my phone now, so I can’t probe the key codes just now. Later…

1 Like

No they don’t. And Windows keyboards differ anyway.

I’ve just looked at 4 Windows keyboards.
Bottom left row:

  1. Ctrl, Windows key, Alt, spacebar
  2. Ctrl, Fn, Windows, Alt, spacebar
  3. Ctrl, Windows, Alt, spacebar
  4. Ctrl, \ and |, Alt, space bar (this is a very old keyboard)

Mac kb:
Fn, Ctrl, Option/Alt, Command, spacebar

So Windows Alt and Mac Command are (in my examples) next left from spacebar. But Ctrl is further left on all.

Although as Steve says, Mac kb mirrors Command and Option keys either side of spacebar, Windows doesn’t, usually.

,Although the keys next right of spacebar mirror or at least duplicate, some keys, sometimes.

All mine have an AltGr key next R of spacebar. And all have a second Ctrl key, but not necessarily in a mirrored position.

Oh… I mixed them up again… :expressionless:

I meant: do you know if the Windows Alt and Mac Command have the same position on the keyboard? It seems they do though :slight_smile: .

Edit: Wait, did I mix up the keys again? I think it’s time for me to go to bed now…

In my examples Windows Alt and Mac COMMAND (not Option/Alt) are both next left of spacebar.

But serve different functions.

maybe this helps…

john

Your kb @john_drivenupthewall has symbols where mine has text, but in same positions.

[Edit] But I have Fn left of ^ (Ctrl)

that’s the image of the ‘Keyboard Viewer’ [click your ‘Flag’ in the top menu]…

on a mac book yours will show a function key extreme left and not include the number pad…

btw. all seven of my mac keyboards are worded alt with the symbol and none show the word option

john

1 Like

I have an iMac 27" with Magic Keyboard. Haven’t tried the kb viewer. Tx for tip.

You need to activate this and the emoji viewer in the system preferences for the keyboard before they will show when you click the flag icon in the menu.

On Mac, Option and Alt are equivalent. Some Mac keyboards label the key option, some label it alt, some label it both, and some use the symbol. Given this somewhat complicated mess, SketchUp chose to use only VK_ALT. Both control and command are separate keys, neither of them equivalent to option/alt.

The values of the key code constants are:

VK_ALT
524288
VK_CONTROL
262144
VK_COMMAND
1048576

I think I’ve got it right now :slight_smile: .

One last thing, could anyone share screenshots of how the Move tool instructor and Move toot status bar (with at least one pre-selected entity) looks on Mac so I can use consistent key names and graphicl design in my own plugin.