AmatCoder / mednaffe

A front-end (GUI) for mednafen emulator
GNU General Public License v3.0
429 stars 35 forks source link

Use macOS keyboard mapping when __APPLE__ is defined #158

Closed codeman38 closed 1 year ago

codeman38 commented 2 years ago

Mednaffe compiles and runs surprisingly well out of the box on macOS with one notable exception: the key codes returned in hardware_keycode by GDK on macOS are really weird compared to those used on other Unix-based OSes, due to maintaining compatibility with standards used by older macOS versions. This causes the key definition dialogues to behave very unexpectedly on that OS.

These key definitions are conveniently specified in Events.h in Carbon.framework - with the exception of the Windows application key, which doesn't exist on Mac keyboards, but which returns a code of 110 in GDK when I tested it manually. Additionally, Mac F13-F15 correspond to the Print Screen, Scroll Lock, and Pause keys on Windows, so I mapped those accordingly as well.

The __APPLE__ preprocessor directive identifies whether we're compiling on macOS, so I added these in an additional #ifdef block under the existing one for __G_OS_UNIX__ with these Mac-specific definitions.

codeman38 commented 2 years ago

I've personally tested this change on an M1 MacBook running macOS 13, and can confirm that it interprets key definitions from the config and writes updated key mappings to the config correctly now when it hadn't done so before.

AmatCoder commented 1 year ago

Merged (apologies for the late reply).

Thanks for this, really appreciated.