Search code examples
keyboard-shortcutsinno-setup

How to add access key to button in Inno Setup


I want to add Alt functions to my audio button; Alt+M for Mute and Alt+P for Play Like this

screenshot

How? What code should be entered? Where will I insert the code? Here's my script:

SoundCtrlButton := TNewButton.Create(WizardForm);
SoundCtrlButton.Parent := WizardForm;
SoundCtrlButton.Left := 8;
SoundCtrlButton.Top := WizardForm.ClientHeight - 
  SoundCtrlButton.Height - 8;
SoundCtrlButton.Width := 40;
SoundCtrlButton.Caption :=
  ExpandConstant('{cm:SoundCtrlButtonCaptionSoundOff}');
SoundCtrlButton.OnClick := @SoundCtrlButtonClick;

Solution

  • In Windows controls, you just prefix a letter in control caption with & to mark is as an access key.

    See https://learn.microsoft.com/en-us/cpp/windows/defining-mnemonics-access-keys#mnemonics-access-keys

    SoundCtrlButton.Caption := '&Mute';
    

    Or in your case, indirectly via a custom message:

    [CustomMessages]
    SoundCtrlButtonCaptionSoundOff=&Mute
    

    keyboard accelertor


    See how the standard button captions are defined in Default.isl:

    ButtonBack=< &Back
    ButtonNext=&Next >
    ButtonInstall=&Install