0
votes

I am trying to run a kiosk-mode browser and I want to disable Ctrl-N opening a new window. I don't want to do it in JS (I only want Ctrl-N to be disabled in kiosk mode, and in any case it isn't possible in Chrome).

I have just discovered AutoHotkey as a possible solution, but I am a complete newbie. I wrote this but it doesn't work:

^n::return
RunWait C:\Program Files\Internet Explorer\iexplore.exe
ExitApp

Using the SciTE debugger, it never comes back from executing the first line. I understood that the first line would ignore Ctrl-N, but it seems that I'm completely misunderstanding something about how hotkeys are handled. If I comment out the first line, IE launches as expected.

Can anyone help explain what I need to do here?

1

1 Answers

3
votes

From the AHK docs:

After the script has been loaded, it begins executing at the top line, continuing until a Return, Exit, hotkey/hotstring label, or the physical end of the script is encountered (whichever comes first). This top portion of the script is referred to as the auto-execute section.

Consequentially, if you want something to be executed once when the script is started, you have to put it at the very top of the script, before you define your hotkeys/hotstrings, subroutines or use a Return or Exit. Alternatively, you can define a subroutine which is then called in the auto-execute section.

To your code

It makes little sense to define a hotkey in a script that then immediatly terminates (ExitApp). As soon as the script isn't running anymore, its hotkeys won't have any effect.

Edit

According to your new comment, it is much more reasonable to let the script run all the time and only bind your hotkey to IE's windows:

#IfWinActive ahk_exe iexplore.exe
^n::return

There's really no reason to start/terminate your script together with IE. The memory consumption of simple AHK scripts is minuscule. But you get the big advantage of not having the start the script whenever you want to start IE. This is especially helpful whenever an external program starts IE (e.g. you open a link in a PDF). I suggest you put auto-start this script.