Disable CMD-Q ?

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

Zax
Posts: 473
Joined: Mon May 28, 2007 10:12 am
Location: France
Contact:

Disable CMD-Q ?

Post by Zax » Wed Mar 06, 2024 3:16 pm

Hello,

From some research, there doesn't seem to be a way to disable the CMD-Q keyboard shortcut for the Quit menu item when compiling a standalone :(

I would like the Quit menu item to be present, but without the keyboard shortcut. Of course, I could trap the shutdownRequest message and answer an exit confirmation, but by doing that, this confirmation is also requested when the machine is turned off (which is logical) but I would not want to this behavior.

I would like my standalone to quit normally when the machine is turned off, but simply remove the CMD-Q keyboard shortcut.

Do you know any tips for this? In AppleScript? With an extension?
When quitting a standalone with CMD-Q, no AppleScript event are received, unless I missed something.

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Disable CMD-Q ?

Post by stam » Wed Mar 06, 2024 7:57 pm

I think if you create a custom menu that doesn’t have this option you can’t use the keystrokes.

At least that’s true of other menu items, I’ve not specifically checked for Quit.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Disable CMD-Q ?

Post by dunbarx » Wed Mar 06, 2024 9:08 pm

Stam.

Interesting.

You are saying that if the keyboard shortcut does not appear in a menuItem in (any?, proper?, expected?) menu, then the "default" behavior goes away?

Craig

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Disable CMD-Q ?

Post by stam » Wed Mar 06, 2024 11:28 pm

I've just observed this when I was tinkering with a menu recently, for the first time.
But I suspect it may be optimistic to override this behaviour built into MacOS and haven't really built a standalone to prove it.
It certainly doesn't work in the IDE...

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Disable CMD-Q ?

Post by dunbarx » Thu Mar 07, 2024 12:11 am

Stam.

I think so as well. There are a few "core" operations that seem to be solidly built-in to the OS. Quitting, I believe, is one of them, and is always accessible with CMD-Q.

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Disable CMD-Q ?

Post by dunbarx » Thu Mar 07, 2024 12:14 am

Stam.

Rereading, if it does not work in the IDE I bet it will not in a standalone. Is it even possible to add any, er, disfunctionality to a standalone?

Craig

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Disable CMD-Q ?

Post by stam » Thu Mar 07, 2024 2:28 am

It's not dysfunction, it's changing keyboard shortcuts to menu items. It's not impairing function as such.
Really these shortcuts should be defined in the menus, as they are linked to menu items, but it looks like they're hard-coded in the engine.

I would argue that is not correct design...

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Disable CMD-Q ?

Post by dunbarx » Thu Mar 07, 2024 3:25 am

Stam.

That is what I meant by "solidly built-in", that they are hard coded.

What sucker, I mean, brave soul, will test a standalone to see?

Craig

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Disable CMD-Q ?

Post by stam » Thu Mar 07, 2024 3:37 am

Well standalone did not help.

I was however able to block Command-Q (in standalone only) with some experimentation.

I tried using a frontScript to trap cmd-Q - no dice, even though supposedly this is at the start of the message path. I tried trapping rawKeyDown and again no dice (although weirdly in a bout 1:10 attempts using both did work, and I can't explain it).

In the end the only thing worked reliably was shutDownRequest - this cannot be used in the IDE, only standalones:

Code: Select all

on shutdownRequest
    if the commandKey is down then 
        // do nothing
    else
        pass shutdownRequest
    end if
end shutdownRequest
Tested on standalone and it works. This will block any key combination that uses command (Mac) or control (Win/Lin) to trigger shutdown.
Using the menu to quit works normally.

Zax
Posts: 473
Joined: Mon May 28, 2007 10:12 am
Location: France
Contact:

Re: Disable CMD-Q ?

Post by Zax » Thu Mar 07, 2024 9:05 am

stam wrote:
Thu Mar 07, 2024 3:37 am
In the end the only thing worked reliably was shutDownRequest - this cannot be used in the IDE, only standalones:

Code: Select all

on shutdownRequest
    if the commandKey is down then 
        // do nothing
    else
        pass shutdownRequest
    end if
end shutdownRequest
Very smart workaround!
It works and does not block the shutdown the machine shutdown (tested).

Once again, you save my life Stam. :D
I'm seriously starting to consider erecting a statue dedicated to Stam in my living room... :wink:

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Disable CMD-Q ?

Post by stam » Thu Mar 07, 2024 12:56 pm

Glad I could help!

Please note that the cmd-Q shortcut still shows in the menu item, so this may be incongruous to the end-user.

You'll have to create a custom menu with the shortcut removed - even then I think it still appears, but at least greyed out, so the user at least knows they can't use cmd-Q to quit...

If you're not sure about how to create custom menus, Jacque has provided an excellent resource here: https://hyperactivesw.com/resources/#16 ... 91d1f-67d2

Regards
Stam

Zax
Posts: 473
Joined: Mon May 28, 2007 10:12 am
Location: France
Contact:

Re: Disable CMD-Q ?

Post by Zax » Thu Mar 07, 2024 1:38 pm

Even if the shortcut Q is removed in IDE, it will be added during standalone compilation.
And if the "Quit" menu-item is gray, user will think he can't quit the app! At this time, I prefer an enabled menu-item with shortcut and block the keyboard shortcut with your code.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Disable CMD-Q ?

Post by dunbarx » Thu Mar 07, 2024 2:50 pm

Zax.

Why actually do you want this oddity?

Craig

Zax
Posts: 473
Joined: Mon May 28, 2007 10:12 am
Location: France
Contact:

Re: Disable CMD-Q ?

Post by Zax » Thu Mar 07, 2024 3:49 pm

dunbarx wrote:
Thu Mar 07, 2024 2:50 pm
Why actually do you want this oddity?
For that :
https://forums.livecode.com/viewtopic.php?f=143&t=38966

The application is designed to be launched at startup and only closed when the machine is shut down. As the application is most often reduced to a simple button, I think it is better to block unwanted CMD-Q.

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Disable CMD-Q ?

Post by stam » Thu Mar 07, 2024 4:10 pm

Zax wrote:
Thu Mar 07, 2024 1:38 pm
if the "Quit" menu-item is gray, user will think he can't quit the app! At this time, I prefer an enabled menu-item with shortcut and block the keyboard shortcut with your code.
The Quit menu item is not greyed out - just the shortcut. The menu item is clearly selectable:
Screenshot 2024-03-07 at 14.59.21.png
regards
Stam

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”