[Pythonmac-SIG] Key Bindings on cross platform apps.

Robin Dunn robin at alldunn.com
Sat Feb 2 00:55:15 CET 2008


Christopher Barker wrote:
> Hi all
> 
> I'm trying help out Rob McMullen get his "Peppy" editor working well on 
> OS-X. I'm thinking about about key bindings.
> 
> Apple has the "command" key, but also an "alt"(option) key and a 
> "control" key. I kind of wish they had never introduced a control key, 
> but so be it.
> 
> Anyway, it seems that for the standard conventions, like cut, copy, 
> paste, save, etc, that Macintosh apps use the "command" key where 
> Windows (and KDE and GNOME) apps use the "control" key. This, for cross 
> platform apps, this is what I think should be done:
> 
> On the Mac, the default behavior should be for "command" to do 
> everything that "control" does on Windows and Linux, and "control" 
> should do nothing. The alt(option) key should do the same thing as alt 
> on the other platforms.
> 
> This seems like it makes for the best compatibility. Is this a standard 
> and good way to do it?

A lot of this can be automated in wxPython by following some basic 
rules.  First of all wxMac will automatically convert Ctrl-whatever 
accelerators in menu items to be Command-whatever, so for example if 
somebody writes the app on Windows and uses Ctrl-C for the Copy menu 
accelerator then when it runs on Mac it will be turned into a Cmd-C. 
For other key bindings, such as those handled in explicit EVT_KEY_DOWN 
event handlers you can use the CmdDown() method in the key event object 
instead of MetaDown() on Mac and ControlDown() on the other platforms. 
CmdDown is simply defined like this:

     bool CmdDown() const
     {
#if defined(__WXMAC__) || defined(__WXCOCOA__)
         return MetaDown();
#else
         return ControlDown();
#endif
     }

For explicit accelerator tables there is a wx.ACCEL_CMD identifier that 
works the same way, it's equivalent to wx.ACCEL_CTRL on Windows and GTK 
and to the command key on Mac.

-- 
Robin Dunn
Software Craftsman
http://wxPython.org  Java give you jitters?  Relax with wxPython!



More information about the Pythonmac-SIG mailing list