Cmd z and Ctrl z

I’m trying to apply the best method for starting and undo process but have some doubts regarding the different ways Mac and Windows handle keys.
Code, in keydown event is:

#if TargetMacOS if Keyboard.CommandKey and ( asc(key) = 122 or asc(key) = 90 ) then MyUndo Return True end if #elseif TargetWin32 if Keyboard.ControlKey and asc(key) = 26 then MyUndo Return True end if #endif

It seems there is no difference between Z and z in Windows but there is a difference in Mac. Is this correct ?

Is this code the safest way to start an undo?

If the ASC(key)=26 then there is no need to check the Control Key as it would be “implied” (Ctrl-Z=26)

If (keyboard.commandkey or keyboard.controlkey) and (ascB(key)=26 or key.uppercase="Z") then 

all in one statement… no need for target

Can I ask why you’re not using the menu item for undo?

[quote=172624:@Dave S]If the ASC(key)=26 then there is no need to check the Control Key as it would be “implied” (Ctrl-Z=26)

If (keyboard.commandkey or keyboard.controlkey) and (ascB(key)=26 or key.uppercase="Z") then 

all in one statement… no need for target[/quote]

Yes, but in this case Ctrl+z will also work in Mac, isn’t this a non “Mac” behaviour ?

Tim, I need my own undo because I don’t have any menu.

[quote=172631:@Alejandro Fresno Meyer]Yes, but in this case Ctrl+z will also work in Mac, isn’t this a non “Mac” behaviour ?

Tim, I need my own undo because I don’t have any menu.[/quote]

if (keyboard.ControlKey and TargetWin32 and (ascB(Key) = 26)) or _ (keyboard.CommandKey and TargetMacOS and (ascB(Key) = 26)) then

If you intend to place your app in the MAS, chances are they will reject it if it does not have a menu.

The other question is, “then why is there a control key on the mac”
Personally I set up most of my apps with similar code, so that it a WIn user on a Mac or a Mac user on a Win machine doesn’t have to remember which modifier key (is that contray to the reccomendations of Apple and Microsoft? yes… )

Dave, that’s true and may be a good option regarding many users have both OS.

Michel, not for the MAS (at least for now). :slight_smile:

String comparison is not case sensitive, so you can drop the “uppercase”.