Opened 7 years ago

Closed 5 years ago

#12917 closed defect (fixed)

[wxOSX_COCOA] Key&board accelerators for button labels

Reported by: joostn Owned by:
Priority: low Milestone:
Component: wxOSX Version: stable-latest
Keywords: wxbutton button shortcut accelerator Cc: joost@…
Blocked By: Blocking:
Patch: yes


Sample app:

#include "wx/wx.h"

class MyFrame : public wxFrame
    DECLARE_CLASS( MyFrame )
      : wxFrame(NULL,wxID_ANY,wxT("Frame"))
      wxButton *btn1=new wxButton(this,1100,wxT("Button &A"),wxPoint(0,10));
      wxButton *btn2=new wxButton(this,1101,wxT("Button &B"),wxPoint(0,100));
    void OnButtonAClick(wxCommandEvent &event)
    void OnButtonBClick(wxCommandEvent &event)

IMPLEMENT_CLASS( MyFrame, wxFrame )
BEGIN_EVENT_TABLE( MyFrame, wxFrame )
    EVT_BUTTON( 1100, MyFrame::OnButtonAClick )
    EVT_BUTTON( 1101, MyFrame::OnButtonBClick )

class MyApp : public wxApp
    bool OnInit()
      MyFrame *frame=new MyFrame();
      return true;


Pressing Cmd+A should invoke button A and Cmd+B should invoke button B, just like the Alt shortcuts under windows. This is accomplished by the attached patch.

Keyboard shortcut is ignored if the button is the default button, since I haven't found a way to attach two keys to the same button.

Attachments (1)

button_shortcut.patch download (3.7 KB) - added by joostn 7 years ago.
The patch

Download all attachments as: .zip

Change History (4)

Changed 7 years ago by joostn

The patch

comment:1 Changed 6 years ago by vadz

  • Priority changed from normal to low
  • Status changed from new to confirmed

Looks reasonable to me. Stefan, any objections to applying this?

comment:2 Changed 6 years ago by csomor

apart from the fact that it should be #if and not #ifdef for wxOSX_USE_COCOA and that it should have the same brace around the call for MacSetAcceleratorFromLabel in _osx.cpp it looks fine to me

comment:3 Changed 5 years ago by VZ

  • Resolution set to fixed
  • Status changed from confirmed to closed

(In [72809]) Implement support for button mnemonics in wxOSX/Cocoa.

Set the mnemonic as "key equivalent".

Closes #12917.

Note: See TracTickets for help on using tickets.