13

Is there any way to securely stick a notebook window (e.g. a dialog) on screen that it cannot be closed/removed/hidden by any of the standard OS shortcuts, like AltF4 or AltTab under Windows? The ideal solution would allow me to specify a range of key-combinations that can be used, and block any other, though it would not be a problem to block all keyboard input, as there are other ways to close a modal dialog.

I have a feeling that this cannot be done entirely from under Mathematica, though I'll give it a go. You can experiment with the following example:

CreateDialog[{TextCell["Click OK to close"], DefaultButton[]}, Modal -> True]

Purpose: I'm doing some experimentation on humans in Mathematica, and since this species is known by its extensive explorative behaviour (i.e. pushing all buttons) and the ability to ruin everything, I want to make the experiment-gui foolproof so that they can't remove it from the screen. This is a must, as it could happen that they hit AltF4 (accidentally or intentionally) and quit at the middle of a test, rendering any saved data useless.

István Zachar
  • 47,032
  • 20
  • 143
  • 291
  • I guess you figured out that WindowFrameElements -> {} doesn't prevent Alt-F4 from working. – Szabolcs Apr 19 '12 at 15:14
  • Not sure this is a Mathematica-specific question? Maybe people over on SuperUser might have ideas that can then be implemented in MMA? – Eli Lansey Apr 19 '12 at 15:22
  • @Szabolcs Setting WindowFrameElements -> {} does prevent Cmd-w from closing the notebook on OS X. – Heike Apr 19 '12 at 15:34
  • I now how to do it in AutoHotKey, though I would prefer a domestic solution. – István Zachar Apr 19 '12 at 15:36
  • @Heike that doesn't help for Alt-F4 – Eli Lansey Apr 19 '12 at 15:41
  • @Heike On Windows, it does help Ctrl-W, but not Alt-F4. – Szabolcs Apr 19 '12 at 15:52
  • @Szabolcs I don't think OS X has an Alt-F4 equivalent apart from Cmd-W and possibly Cmd-H (which hides all windows of the active application (at least on 10.6)) – Heike Apr 19 '12 at 15:55
  • @EliLansey I realise that. I just thought it curious that the behaviour is different for a different OS. – Heike Apr 19 '12 at 15:57
  • I'm not sure that this is a good idea in principle, regardless of whether it can be done in Mathematica or not. As Raymond Chen frequently asks: "what if two people did this?" – Oleksandr R. Apr 19 '12 at 16:20
  • @OleksandrR., please see my edit. I don't think there is any other clever solution than simply suppressing all shortcuts. – István Zachar Apr 19 '12 at 16:43
  • Okay, that seems reasonable. Have you considered running the notebook in the Mathematica browser plugin, using a browser that has a kiosk mode? – Oleksandr R. Apr 19 '12 at 16:57
  • @Oleksandr That is a good idea, though I am afraid that deploying my stuff for the plugin might not be a straightforward task. If you could just post it as an answer with some details, I could accept it if no direct in-Mathematica solution appears. – István Zachar Apr 19 '12 at 17:16
  • I'm reluctant to post that as an answer because I haven't actually tried it and don't have all the details worked out. For example, I had thought that if you have full Mathematica installed and open a notebook rather than a CDF, the restrictions disappear. But now that I test it, that's not the case (and I can't work out how to change that either). If I figure it out, then I'll post an answer. :) – Oleksandr R. Apr 19 '12 at 17:43
  • I will appreciate that :) In the meanwhile, I will do my research as well. – István Zachar Apr 19 '12 at 18:13

1 Answers1

10

Not 100% solution, but this may work. Define:

dialog := 
 CreateDialog[{TextCell["Click OK to close"], DefaultButton[]}, 
  Modal -> True, NotebookEventActions -> {"WindowClose" :> dialog}]

Then call:

dialog

At least, it reappears :)

Yu-Sung Chang
  • 7,061
  • 1
  • 39
  • 31
  • 1
    Devilish workaround :) But unfortunately it does not prevent accidental Alt+Tab changes and similar non-invasive key combinations which simply just hide the window. – István Zachar Apr 19 '12 at 20:00