alinebee / Boxer

The DOS game emulator that's fit for your Mac.
http://boxerapp.com/
773 stars 139 forks source link

Feature request: fn lock #6

Closed mratzloff closed 12 years ago

mratzloff commented 12 years ago

Boxer now disables OS X’s function key and arrow-key shortcuts while you’re playing: no more switching Spaces by mistake! ... Your keyboard’s own built-in function key shortcuts will still take effect unless you hold down Fn while you press them. Unfortunately that functionality is part of the keyboard itself, and out of Boxer’s control.

I hate to be that guy, but... are you sure there's no way around it?

Here are a couple links I dug up:

http://stackoverflow.com/questions/1759526/set-get-fn-lock-for-a-macos-application http://forums.macrumors.com/showthread.php?t=313721#15

I assume when you say "part of the keyboard itself" you mean it's handled in the keyboard driver. But there's an option in the Keyboard panel for "Use all F1, F2, etc. keys as standard function keys". Can you not implement a system similar to what is described in the Stack Overflow answer, toggling what to send based on the value of that checkbox?

Playing a game like Star Wars: X-Wing where energy allocation is half the game and having to press fn-F9 (allocate to lasers) and fn-F10 (allocate to shields) using one hand while keeping an eye on the screen is pretty darn tough. :-)

If I could map my CH Fighterstick buttons to keyboard keys it would also solve this problem for me, so in the meantime I'm going to give ControllerMate (http://www.orderedbytes.com/controllermate/) a shot to try to bypass this.

alinebee commented 12 years ago

When that "Use all F1, F2 etc." option is unchecked in System Preferences, the keyboard driver is sending custom signals that Boxer cannot use to reliably distinguish which function key was pressed. As an example: on my Macbook Air keyboard, the F9 key is mute. Rather than sending an "F9" or "Fn-F9" signal to the system, it's sending a "media volume mute" signal - that's what OS X and Boxer see.

The catch is that other Mac keyboard models put mute on a different function key and send the same signal for it - same with play/pause, brightness up/down, and so on. These hotkeys move around from Mac model to Mac model and keyboard revision to keyboard revision, and will no doubt continue to do so. Attempts to correlate them would be doomed to failure.

Toggling that keyboard preference tells the keyboard driver "Ok, you know that hotkey thing the keyboard does? Make it do that the other way around." If Boxer were able to temporarily flip that switch itself, so that it's treated as always on while Boxer is active, then that would be a solution; but I have not found any suitable means to do so.

The Applescript workaround offered in that Macrumors thread is extremely brittle and completely unsuitable for a shipping product like Boxer. A quick glance at the sourcecode for the Applescript will explain why this is so; but in short it uses clumsy user-input fakery to reenact opening up that System Preferences panel and clicking on the checkbox to toggle it.

Should someone manage to work out how to toggle this programmatically at the keyboard driver level then I could look into implementing such a solution into Boxer. For now, my suggestion is to just toggle the preference manually when you play a game that makes heavy use of function keys, and flip it back again once you're done playing.