avaraline / Avara

Port of the original 1996 game from Ambrosia Software.
MIT License
123 stars 19 forks source link

Command key not captured by Avara in OSX #145

Open assertivist opened 3 years ago

yorb commented 3 years ago

I figured out a workaround for this, because I wanted to use Left Command as jump but it also closes the window:

  1. Open Avara
  2. Go to System Preferences > Keyboard > Shortcuts > App Shortcuts
  3. Add a shortcut for Avara to invoke ~"Avara" (the name of the window, under Window) with ⌘W~ "Close" with some crazy obscure key combo you'll never hit
  4. Switch back to Avara

This disables the Close shortcut until you quit. ~Unfortunately you have to redo this every time you reopen Avara (set the shortcut to something else, switch to Avara and back, set the shortcut back to ⌘W).~

Edit: Found a better workaround here, updated steps above. Set once and done.

assertivist commented 3 years ago

Thanks for the workaround @yorb !

Thanks to your info, I think I finally know how to fix this https://wiki.libsdl.org/SDL_HINT_GRAB_KEYBOARD

basically there is an SDL hint that will prevent any keyboard events from reaching anything but our app. This would make it so that ALT+TAB, volume keys etc. would not work while playing Avara, BUT you could use Left GUI and Right GUI as keys without triggering OS shortcuts.

The idea being (I need to research to see if this is possible without regenerating the SDL window) we would 'grab' the keyboard during gameplay and 'release' it in-between games so you can switch apps and change the volume and stuff with the keyboard again.

Anybody with strong thoughts on this?

dcwatson commented 3 years ago

We might be able to patch mainloop to check to see if there's an active game, and just ignore the SDL_QUIT event in that case. But if that doesn't work for some reason, we could grab the keyboard, but it should probably either be a preference, or only be done if you actually have command/win/meta bound.

yorb commented 3 years ago

We might be able to patch mainloop to check to see if there's an active game, and just ignore the SDL_QUIT event in that case. But if that doesn't work for some reason, we could grab the keyboard, but it should probably either be a preference, or only be done if you actually have command/win/meta bound.

If we go with the first route, we'll have to catch more than just Quit:

These are all ones that have happened to me in-game, but I'm sure there are plenty of other possibilities.