Use F-keys without Fn [DONE]

Any wishes
sasha
Posts: 168
Joined: Wed Feb 17, 2016 4:59 pm

Use F-keys without Fn [DONE]

Post by sasha » Mon Jun 13, 2016 5:16 pm

I really like using the special functions on the F-keys like dimming the display (F1/F2) or playing next track in iTunes (F9) etc - except when I'm working in NC. Here, pressing Fn + F-key (e.g. Fn+F5 to copy) is really cumbersome instead of plain F5.

I am aware that one can turn on "Use all F1, F2 etc keys as standard function keys..." in the System Preferences -> Keyboard, but then I would need to press Fn when accessing the special functions, also not great.

It would be nice to only switch F-keys and special functions when NC has focus as an optional setting in NC. A quick and dirty way would be using some Apple Skript (e.g., http://forums.macrumors.com/threads/dis ... s.1122975/) but surely there is a better way.

sasha
Posts: 168
Joined: Wed Feb 17, 2016 4:59 pm

Re: Use F-keys without Fn

Post by sasha » Tue Jun 14, 2016 4:38 am

After a little research I figured out a solution using Karabiner, a free keyboard customizer that can do a lot of key remapping.

https://pqrs.org/osx/karabiner/

My private.xml looks like this:

Code: Select all

<?xml version="1.0"?>
<root>
	<appdef>
		<appname>Nimble Commander</appname>
		<equal>info.filesmanager.Files</equal>
	</appdef>
	<item>
		<name>NC original functional keys</name>
		<identifier>private.appdef</identifier>
		<only>Nimble Commander</only>
		<autogen> __KeyToKey__ ConsumerKeyCode::BRIGHTNESS_DOWN,    KeyCode::F1 </autogen>
		<autogen> __KeyToKey__ ConsumerKeyCode::BRIGHTNESS_UP,      KeyCode::F2 </autogen>
		<autogen> __KeyToKey__ KeyCode::EXPOSE_ALL,                 KeyCode::F3 </autogen>
		<autogen> __KeyToKey__ KeyCode::LAUNCHPAD,                  KeyCode::F4 </autogen>
		<autogen> __KeyToKey__ ConsumerKeyCode::KEYBOARDLIGHT_LOW,  KeyCode::F5 </autogen>
		<autogen> __KeyToKey__ ConsumerKeyCode::KEYBOARDLIGHT_HIGH, KeyCode::F6 </autogen>
		<autogen> __KeyToKey__ ConsumerKeyCode::MUSIC_PREV,         KeyCode::F7 </autogen>
		<autogen> __KeyToKey__ ConsumerKeyCode::MUSIC_PLAY,         KeyCode::F8 </autogen>
	</item>
</root>
Now, the special function buttons work as F-keys without Fn in NC and as special function buttons anywhere else.

@Mike: By the way, it seems like NC (build 1621) is still using "info.filesmanager.Files" as Application Bundle Identifier.

User avatar
mike
Posts: 1060
Joined: Thu Jul 16, 2015 5:35 am
Location: Exeter, UK

Re: Use F-keys without Fn

Post by mike » Tue Jun 14, 2016 6:53 am

Hi sasha,

Thank your for searches and links.
Karabiner can surely work, but that's such a heavy and unfriendly solution..

Anyway, great news are that I've finally understood (dumb me! :oops: ) how an app can intercept a key presses flow and make some changes in it.
It all goes down to "Privacy->Accessibility" stuff in Preferences and involves no scripting (variants with AppleScript are just awful).
A proof-of-concept demo is already working, and I think it will be easy to integrate that code into main codebase.
So, hopefully a new checkbox like "Always use functional keys as Fn1-Fn19" will appear in Hotkeys tabs very soon.

Best,
Mike.

PS
Oh, and about bundle IDs - that was a deliberate decision to left them intact. Lesser of two evils, I would say.

sasha
Posts: 168
Joined: Wed Feb 17, 2016 4:59 pm

Re: Use F-keys without Fn

Post by sasha » Tue Jun 14, 2016 8:11 am

These are great news, I'll be happy to uninstall Karabiner and use a built-in function of NC instead. I'm looking forward to it!

User avatar
mike
Posts: 1060
Joined: Thu Jul 16, 2015 5:35 am
Location: Exeter, UK

Re: Use F-keys without Fn

Post by mike » Tue Jun 14, 2016 3:48 pm

Alright, done!
Please check out this build:
http://magnumbytes.com/downloads/previe ... (1631).zip
It should "just work".

sasha
Posts: 168
Joined: Wed Feb 17, 2016 4:59 pm

Re: Use F-keys without Fn [DONE]

Post by sasha » Tue Jun 14, 2016 5:43 pm

Almost perfect, two small issues:

1) After installing and launching build 1631, the user is directly greeted by the Authentication Warning ("Nimble Commander" would like to control this computer using accessibility features). Maybe inexperienced users are scared by this because at first launch it's not clear what setting needs authentication? Suggestion: have "Always use Fn buttons as F1..F19" off by default. When the user enables the checkbox, the warning is easier to understand and directly connected to the event.

2) All keys work except for F4. I connected F4 to "External Editor" in NC, but F4 (w/out Fn) still triggers Dashboard on my A1255 external keyboard or Launchpad on my Mid 2014 MBP which seems to be system default. I have not set any keys for those functions in System Prefs -> Mission Control. Fn+F4 calls external Editor. Any idea?

User avatar
mike
Posts: 1060
Joined: Thu Jul 16, 2015 5:35 am
Location: Exeter, UK

Re: Use F-keys without Fn [DONE]

Post by mike » Wed Jun 15, 2016 1:47 am

sasha wrote: 1) After installing and launching build 1631, the user is directly greeted by the Authentication Warning ("Nimble Commander" would like to control this computer using accessibility features). Maybe inexperienced users are scared by this because at first launch it's not clear what setting needs authentication? Suggestion: have "Always use Fn buttons as F1..F19" off by default. When the user enables the checkbox, the warning is easier to understand and directly connected to the event.
Agree, that is reasonable.
Will make it Off by default.
sasha wrote: 2) All keys work except for F4. I connected F4 to "External Editor" in NC, but F4 (w/out Fn) still triggers Dashboard on my A1255 external keyboard or Launchpad on my Mid 2014 MBP which seems to be system default. I have not set any keys for those functions in System Prefs -> Mission Control. Fn+F4 calls external Editor. Any idea?
I'm pretty sure that is a system-wide hotkey defined in System Preferences -> Keyboard -> Shortcuts.
They are processed after buttons substitution, but before these keypresses can trigger anything in any regular app.

sasha
Posts: 168
Joined: Wed Feb 17, 2016 4:59 pm

Re: Use F-keys without Fn [DONE]

Post by sasha » Tue Jun 21, 2016 8:57 am

migun wrote: I'm pretty sure that is a system-wide hotkey defined in System Preferences -> Keyboard -> Shortcuts.
They are processed after buttons substitution, but before these keypresses can trigger anything in any regular app.
I can rule out this possibility, there's no hotkey mapped to F4 there. The problem seems to have something to do with my external keyboard. All F-keys work fine with the internal MBP keyboard and on my external USB keyboard (A1243). Only on my external bluetooth keyboard (A1255) the F4 button doesn't get recognized as F4 in NC. It does get recognized as F4 when pressing Fn+F4, though.

I'll be happy to give you more details if you need any, but it's not a crucial issue for me.

Cheers,
Sasha

User avatar
mike
Posts: 1060
Joined: Thu Jul 16, 2015 5:35 am
Location: Exeter, UK

Re: Use F-keys without Fn [DONE]

Post by mike » Thu Jun 23, 2016 6:03 am

Hi sasha,

I think I've seen similar strange behavior before...

Can you please send me a console output of this build when you hit your Fxx keys?
Maybe it's possible to intercept F4 key on that keyboard.

The key logging build itself: http://magnumbytes.com/downloads/previe ... -print.zip
You can run it from another's NC terminal or from OS X Terminal to get that output.

sasha
Posts: 168
Joined: Wed Feb 17, 2016 4:59 pm

Re: Use F-keys without Fn [DONE]

Post by sasha » Thu Jul 21, 2016 8:16 am

migun wrote:Can you please send me a console output of this build when you hit your Fxx keys?
Maybe it's possible to intercept F4 key on that keyboard.
Mike, could you please explain this step again? I downloaded and started this build, but it seemed not to write anything to Console.app. I'll be happy to try again!

Locked