Disable CMD-Q ?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Disable CMD-Q ?
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.
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.
Re: Disable CMD-Q ?
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.
At least that’s true of other menu items, I’ve not specifically checked for Quit.
-
- VIP Livecode Opensource Backer
- Posts: 9709
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Disable CMD-Q ?
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
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
Re: Disable CMD-Q ?
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...
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...
-
- VIP Livecode Opensource Backer
- Posts: 9709
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Disable CMD-Q ?
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
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
-
- VIP Livecode Opensource Backer
- Posts: 9709
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Disable CMD-Q ?
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
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
Re: Disable CMD-Q ?
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...
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...
-
- VIP Livecode Opensource Backer
- Posts: 9709
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Disable CMD-Q ?
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
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
Re: Disable CMD-Q ?
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:
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.
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
Using the menu to quit works normally.
Re: Disable CMD-Q ?
Very smart workaround!stam wrote: ↑Thu Mar 07, 2024 3:37 amIn 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
It works and does not block the shutdown the machine shutdown (tested).
Once again, you save my life Stam.
I'm seriously starting to consider erecting a statue dedicated to Stam in my living room...
Re: Disable CMD-Q ?
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
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
Re: Disable CMD-Q ?
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.
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.
-
- VIP Livecode Opensource Backer
- Posts: 9709
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Disable CMD-Q ?
Zax.
Why actually do you want this oddity?
Craig
Why actually do you want this oddity?
Craig
Re: Disable CMD-Q ?
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.
Re: Disable CMD-Q ?
The Quit menu item is not greyed out - just the shortcut. The menu item is clearly selectable: regards
Stam