Archive: Disable Enter Key


Disable Enter Key
I have a dialog With 3 buttons: Back, Accept and Decline - Within the displayed text there are two links (Not sure if the links are relevant to the question).

Anyway, initially the BACK button is the default:
${NSD_SetText} $mui.Button.Next "&Accept"
${NSD_SetText} $mui.Button.Cancel "&Decline"
SendMessage $HWNDPARENT ${WM_NEXTDLGCTL} $mui.Button.Back 1

The problem is, if the user CLICKS on either of the links (Or for that matter anywhere in the dialog), the FOCUS (Or default) moves to the ACCEPT button - At which point the user can press ENTER and move forward - The requirement is for them to physically CLICK the ACCEPT button.

Question: How do I: (1) Stop the user from pressing ENTER, or (2) Ensure that clicking within the dialog does not change the default, or even (3) ensure that the BACK button is always the default.


Simple solution: Disable the next button and add a checkbox 'I accept' that enables it.

Proper solution: You need to change the default action from Next to Back. I've no idea how to do this though. (Note that this is very different from setting the focus! Using NEXTDLGCTL you changed the focus, but you did NOT change the default.)


You'll want to send DM_SETDEFID (0x0401) to the parent dialog. The wparam will be the control id (not the handle). If you are creating your Accept/Decline/Back buttons on your custom page, the dialog is not HWNDPARENT, it is your inner dialog.

!define DM_SETDEFID 0x0401
SendMessage $HWND ${DM_SETDEFID} $mui.Button.Back.Id 0

Hi: MSG, thanks, you pointed me in the RIGHT DIRECTION:

Change the DEFAULT. So I went to RESOURCE HACKER and changed DIALOG 105 of modern.exe to set the BACK BUTTON to BS_DEFPUSHBUTTON - This worked like a charm - Many thanks. HOWEVER, that (Obviously) changes the default throughout the installer. New question: How to change the PROPERTIES of a BUTTON within a function (So that it applies to this one dialog only).

From:
"CONTROL "", 3, BUTTON, BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 166, 201, 50, 14"

To:
"CONTROL "", 3, BUTTON, BS_DEFPUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 166, 201, 50, 14"

Demiller9: Tried that, but that just changed the DEFAULT to the ACCEPT button (Tried it with a "0" and a "1".


It sounds like you were not using the ID of the Back button - perhaps you used the Accept button's id by accident. The last parameter is unused, so 0/1 would not help.


Demiller9, you are right, I was not using the ID - I hate to ask (Especially since it seem like I know what I am doing by doing stuff in Resource Hacker).....................But I am relatively new to NSIS - How do I find out the ID assigned to each button?


If you are using MUI2, the IDs of your controls start at 1200 and go up for each control (checkbox, label, groupbox, radio button, etc) you create. You can also find several 'spy' type programs that will let you drag a crosshair onto the control and will show you the id.


Thank you so much for your help. Through a series of your help and a bit of luck I have it working. The trick was to add your code:

!define DM_SETDEFID 0x0401
SendMessage $HWND ${DM_SETDEFID} $mui.Button.Back.3 0

Change the $HWND to $HWNDPARENT:

SendMessage $HWNDPARENT ${DM_SETDEFID} $mui.Button.Back.3 0

And THEN reset FOCUS to the BACK button:

SendMessage $HWNDPARENT ${WM_NEXTDLGCTL} $mui.Button.Back 1.

So the complete solution is:

!define DM_SETDEFID 0x0401
SendMessage $HWNDPARENT ${DM_SETDEFID} $mui.Button.Back.3 0
SendMessage $HWNDPARENT ${WM_NEXTDLGCTL} $mui.Button.Back 1

I sure hope this helps somebody else - I know it drove me mad!

PS. Is there a way to mark this issue as solved?


(There's no way to mark this 'issue' solved, and there's no need to. Forum threads aren't issues, they're discussions.)