Knipper John's C#kes
Coding with C#? Piece of cake!

Aug 15 2007

Small tool to manage the Apple keyboard fn key

Categories: C# | Apple | Tools Admin @ 03:08

Until Apple is releasing a fix and because this is annoying me, I decided to take some time and code a small tool that has the only purpose of locking the state of the fn key.

This is working on my computer. It's a PC computer, not a Mac. It's running XP.

Probably that if you are a Mac user you won't need this because the boot camp control panel is probably working for you. Lucky you!
In case you are using Vista this may not work because I'm accessing to the registry.

Because I'm doing a lot of programming, using Visual Studio and the like, the keys between F7 and F12 are often used. Because I also listen to a lot of music not being able to lock the behavior of the fn key annoyed me to the point that I decided to code a very small tool and follow Thomas's tip to toggle the fn key in the registry.

Just by changing the value of the key at:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\KeyMagic\OSXFnBehavior

Here is a small screenshot.

 

 

It’s not doing much. Just toggle the fn behavior. You can toggle the status by Right Click->Toggle but also by Double clicking on the systray icon.

Also, you can use F19. Hopefuly you are not using that key too much. In case you do, it should still work. Just it will now also toggle the fn key Wink

I’m sharing this with you in case you have the same problem. Like always, comments are welcome.

Get it here ToggleFn1.0.0.1.rar (9.17 kb)

History
1.0.0.0 Initial release
1.0.0.1 Supports more registry key types 

Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , ,
Actions: E-mail | Permalink | Comments (37) | Comment RSSRSS comment feed


Related posts

Comments

August 16. 2007 11:03

Thanks for the tool. Gave it a try but I got the following error message :

"Unable to cast object of type 'System.Int32' to type 'System.Byte[]'.

I'm running Windows XP with all the pre-requisites as listed in the email.

Cheers

Fletch

August 16. 2007 11:13

Looks like they changed the key type with the new boot camp version. I'll ake a new version in the coming days.
Until then you can create a .reg file containing:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\KeyMagic]
"OSXFnBehavior"=hex:00

this will change the type of the entry to the one I expect.

Jonx

August 16. 2007 11:45

Fletch, the new version is online. Test this one instead of modifying your registry like I suggested. Let me know. Thank you.

Jonx

August 18. 2007 10:33

works like a breeze for me! thanks so much!

michael

August 18. 2007 10:38

Excellent. Strangely you will see that sometimes the value is not effective immediately. this is because the kbrd.exe manager is polling the value in the registry (for real)...

Jonx

August 25. 2007 12:28

That's not cool.

What is the type of the
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\KeyMagic]
"OSXFnBehavior"=hex:00
registry entry? is it hex, dword, etc?
What is writen here is working for me. can you tell us more about your configuration? xp, vista, pc, mac, bc 1.3, 1.4 and the like... do you have the BC control panel loaded? my tool loaded? etc Smile

jonx

August 25. 2007 18:59

After setting the registry value to 00 try holding down your Fn key and hitting either F1, F2, or F3.... You get a bluescreen that says 'intiating memory dump'... and it just sits there!

Any ideas what's going on?

Simon

August 27. 2007 12:18

Hi
I just found the answer to all my request:
http://www.autohotkey.com/" rel="nofollow">http://www.autohotkey.com/

this litttle tool can do whatever you want with your keyboard

this is my present script:

; Volume On-Screen-Display (OSD) -- by Rajat
; http://www.autohotkey.com
; This script assigns hotkeys of your choice to raise and lower the
; master and/or wave volume. Both volumes are displayed as different
; color bar graphs.

;_________________________________________________
;_______User Settings_____________________________

; Make customisation only in this area or hotkey area only!!

; The percentage by which to raise or lower the volume each time:
vol_Step = 4

; How long to display the volume level bar graphs:
vol_DisplayTime = 2000

; Master Volume Bar color (see the help file to use more
; precise shades):
vol_CBM = Red

; Wave Volume Bar color
vol_CBW = Blue

; Background color
vol_CW = Silver

; Bar's screen position. Use -1 to center the bar in that dimension:
vol_PosX = -1
vol_PosY = -1
vol_Width = 150 ; width of bar
vol_Thick = 12 ; thickness of bar

; If your keyboard has multimedia buttons for Volume, you can
; try changing the below hotkeys to use them by specifying
; Volume_Up, ^Volume_Up, Volume_Down, and ^Volume_Down:
HotKey, #Up, vol_MasterUp ; Win+UpArrow
HotKey, #Down, vol_MasterDown
HotKey, +#Up, vol_WaveUp ; Shift+Win+UpArrow
HotKey, +#Down, vol_WaveDown


;___________________________________________
;_____Auto Execute Section__________________

; DON'T CHANGE ANYTHING HERE (unless you know what you're doing).

vol_BarOptionsMaster = 1:B ZH%vol_Thick% ZX0 ZY0 W%vol_Width% CB%vol_CBM% CW%vol_CW%
vol_BarOptionsWave = 2:B ZH%vol_Thick% ZX0 ZY0 W%vol_Width% CB%vol_CBW% CW%vol_CW%

; If the X position has been specified, add it to the options.
; Otherwise, omit it to center the bar horizontally:
if vol_PosX >= 0
{
vol_BarOptionsMaster = %vol_BarOptionsMaster% X%vol_PosX%
vol_BarOptionsWave = %vol_BarOptionsWave% X%vol_PosX%
}

; If the Y position has been specified, add it to the options.
; Otherwise, omit it to have it calculated later:
if vol_PosY >= 0
{
vol_BarOptionsMaster = %vol_BarOptionsMaster% Y%vol_PosY%
vol_PosY_wave = %vol_PosY%
vol_PosY_wave += %vol_Thick%
vol_BarOptionsWave = %vol_BarOptionsWave% Y%vol_PosY_wave%
}

#SingleInstance
SetBatchLines, 10ms
Return


;___________________________________________

vol_WaveUp:
SoundSet, +%vol_Step%, Wave
Gosub, vol_ShowBars
return

vol_WaveDown:
SoundSet, -%vol_Step%, Wave
Gosub, vol_ShowBars
return

vol_MasterUp:
SoundSet, +%vol_Step%
Gosub, vol_ShowBars
return

vol_MasterDown:
SoundSet, -%vol_Step%
Gosub, vol_ShowBars
return

vol_ShowBars:
; To prevent the "flashing" effect, only create the bar window if it
; doesn't already exist:
IfWinNotExist, vol_Wave
Progress, %vol_BarOptionsWave%, , , vol_Wave
IfWinNotExist, vol_Master
{
; Calculate position here in case screen resolution changes while
; the script is running:
if vol_PosY < 0
{
; Create the Wave bar just above the Master bar:
WinGetPos, , vol_Wave_Posy, , , vol_Wave
vol_Wave_Posy -= %vol_Thick%
Progress, %vol_BarOptionsMaster% Y%vol_Wave_Posy%, , , vol_Master
}
else
Progress, %vol_BarOptionsMaster%, , , vol_Master
}
; Get both volumes in case the user or an external program changed them:
SoundGet, vol_Master, Master
SoundGet, vol_Wave, Wave
Progress, 1:%vol_Master%
Progress, 2:%vol_Wave%
SetTimer, vol_BarOff, %vol_DisplayTime%
return

vol_BarOff:
SetTimer, vol_BarOff, off
Progress, 1:Off
Progress, 2:Off
return

#2:: Send @

F19::
Drive, Eject
; If the command completed quickly, the tray was probably already ejected.
; In that case, retract it:
if A_TimeSinceThisHotkey < 100 ; Adjust this time if needed.
Drive, Eject,, 1
return



Joan Pons

August 27. 2007 12:32

Hello joan, thanks for sharing this here. But AFAIK this will only let you handle recognized keys. So neither the eject key, nor the fn key will work. right? But I agree that your tip will just achieve the same result for those that do not really care about using the original keys...

the problem I had at first was that the fn key is pressed down by default. meaning that in my case F7 to F12 where useless.

Anyway, for me, the original drivers, the buggy bootcamp panel (when it accepts to start) and my small tool to manage the state of the fn key do the trick.

Anyway, thank you.

Jonx

August 30. 2007 15:19

Thank you very much for this!

Steve

September 19. 2007 02:07

Pingback from rickvandelaar.wordpress.com

Alternative to the earlier mentioned drivers for the Apple keyboard « Rick van de Laar

rickvandelaar.wordpress.com

September 28. 2007 23:25

worked perfectly - many thanks

phil

February 26. 2008 13:26

It only recognizes the F19 key, it still doesn't notice the fn key. I'm using Windows XP with an Apple aluminum keyboard. Is this normal?

Nathaniel

March 1. 2008 11:48

Hello,
what do you mean? my tool aims only at toggling the fn key status. That means that, just because I cannot access to the fn key, I use the F19 key to toggle the status of the fn key. that's all. Is it not doing this for you?

Jonx

March 18. 2008 17:53

Hi guys. I've bought a new Apple Wireless Keyboard a few days ago, and I've been Googling and trying to make the Fn key work in Windows XP ever since. I think I've read every page with the occurence of 'Fn key' by now.

As mentioned above, AutoHotKey has lots of options. Unfortunately, it works with keyboard scancodes, and since the Fn key doesn't have a scancode of its own, it won't be recognized.

I came across this posting though:
http://www.autohotkey.com/forum/topic7135.html

Someone wrote a DLL file, which enables AutoHotKey to detect when 'strange' keys are pressed, also the Fn key on the Apple Wireless Keyboard! Relevant part from my script at this point:

---

;
; Checks whether Fn key (4949) or Eject key (4854) is pushed
;
Key_Action_Check:
IfEqual, Vals, 4949, GoSub 4949
IfEqual, Vals, 4854, GoSub 4854
Return

;
; The 'Vals' variable has the number that corresponds with
; the 'strange' key. If so, it send you to another part of
; the script, in this case, when you press Fn, it'll goto
; the label '4949'
;

4949: ; Fn
MsgBox, You pressed Fn!
Return

;
; And here's the eject key (label 4854), which I use for DELETE for now
;

4854: ; Eject
Send, {DEL}
Return

---

And yes, this works! But now the bad news, I can't get it to behave like CONTROL. I can use it as any letter, digit, or as e.g. DELETE, but it won't act as CONTROL.

AutoHotKey has a keyhistory, which shows you all the keys that were pressed. If I say in the script, that it should send {CTRL}, it'll register, but Fn+c won't act as CTRL+c.

Anyway, I've been at this for a few days now, and I can't get the Fn key to work as a modifier (Fn+F8 = play/pause, or Fn+Backspace = Delete, e.g.). If anyone reads this, is trying the same thing, and finds a way, please let me know Smile

You can also contact me by mail (veilure[at]gmail[dot]com), if that's easier. The more people trying to find the secret of the Fn key the better!

Regards,

Veil

March 19. 2008 17:34

Very good news. We are all trying to achieve the same here, I think. I suggest that we keep the conversation here so that all can benefit from it. If it's needed maybe I can open a forum so that we can talk about all this.

Now about your keys. When you say that you would like to map fn to Control. Is this just a sample to illustrate your need or is this really something you want to do? Wink

The principle of a modifier is exactly that: it modifies the value of a specific key. that means that for example Fn+F8 will not appear as two keys but only as one having a special/specific value. You should have 3 different codes for Fn, F8 and Fn+F8, but only one code for each combinaison, not a succession of two codes... This means that in your sample you need to map the scan code of Fn+F8 to the scan code of CTRL+F8

I'll try to find some time over the weekend to test you solution because I'm not sure I understand everything Wink

One more thing... What have you installed to make this work ? Both the keyboard driver and the bootcamp.msi? only the keyboard driver, nothing at all?

Jonx

March 20. 2008 12:33

Hey,

I have the latest Wireless keyboard from Apple, and I use it on my Shuttle PC with Windows XP SP2. So I don't use Bootcamp. I also haven't installed a driver. Just a BT dongle, and the keyboard works fine.

What I did install:

1) AutoHotKey: http://www.autohotkey.com/ (latest version)

The remapping with AHK works the same way as with all the other remapping tools. Let some combination act as another, etc. For the non-standard keys, you can use the scancode, and it'll detect it, and give it the function you want.

The problem with the Apple keyboard, and Fn keys in general, is that they -do not- act as a normal key, and do not have a scancode. So in that regard, there's no way you can bind anything to the key, because it simply won't be recognized.

Now, someone on the AHK forums wrote a DLL file for certain remote controls. AHK combined with this DLL can recognize keys even if they normally wouldn't send a scancode. As it happens, this also works for the Fn and Eject key on the Apple keyboard.

2) http://www.autohotkey.com/forum/topic7135.html

This is the thread where this DLL and related config files are rewritten to make certain audio hotkeys on other types of keyboards work, keys that also don't send a scancode. I downloaded the zipfile that's linked in the thread, and ran the configs as stated in the readme.

I don't really have a clue how it works exactly, all I know is that when I press the Fn or Eject key, it's detected by AHK. It'll give a certain 'key number' to the pressed key, and redirect your script to a point where you can add your custom action.

So at this point, the Fn key is functional, and you can do with it whatever you want. The problem I have, is that I don't know enough about AHK to make it do what I want. I also posted my question on their forums (http://www.autohotkey.com/forum/viewtopic.php?t=30321), unfortunately no response yet.

So Jonx, to answer your question about my goal. What I'd like to accomplish is to use the Fn key as a modifier, just as it does on my Mac. So:

- Fn => does nothing;
- Key x => does something;
- Fn + Key x => does something else.

Since the Fn key will only be registered by AHK with that DLL file, you can't use scancodes, and you're limited to the part of the script that says 'You pressed Fn, now what?':

line 1: 4949: ; Fn
line 2: MsgBox, You pressed Fn!
line 3: Return

Explained:

line 1: label for 'Fn key is pressed', and a comment
line 2: Display a messagebox with text
line 3: end this label

Like you said, it's best to try it for yourself. Install AHK, download the files in the zip and follow the readme. At this point you'll see where I'm stuck. You can bind a single action to the Fn key (like Del, Backspace), but I haven't yet figured out how to combine it with another key (like Fn+Backspace=Del).

So, to conclude. Fn, Eject, and any key without a scancode *can* be detected by AHK + this dll. It's up to some creativity to let the AHK script do something useful with it.

I'll keep on trying, and let you know if I find anything else.

PS: Nice to see that there are more people actively looking for a solution!

Regards,

Veil

March 21. 2008 04:22

Ok, thanks for all the details. When I started the blog here I tried to develop the sort of dll you are using. I achieved (after some very hard work - because I don't have the required skills Wink ) to catch the eject key... plus two other special keys fn+F7 and fn+F8. Because I didn't catch the other special keys and because I was stuck and didn't have the time to make further research I just dropped the thing. Right now I'm using the keyboard without driver and without bootcamp... That means that I have to know the keys of a PC keyboard to be able to find all the keys I need.

Anyway, that dll could be the missing link I was unable to produce... personally, I just want that my keys behave like they where designed to... I do not want to remap anything.

One more thing. What I want to happen when I press fn, is to toggle the fn key... like what my tool is doing with F19...

hopefuly I'll get enought time over the weekend... I'll keep you posted. So do you if you find something new Smile

thank you...

Jonx

March 22. 2008 06:39

Good news! My Fn key is now fully functional as a modifier key.

Fn + Backspace = Delete
Fn + F11 = Volume down
Fn + F12 = Volume up
Eject key opens/closes my drive, etc

The code is really messy at this moment, I'll rewrite it and add some comments this weekend. I'll add another message here as soon as I'm done, so stay tuned!

Veil

March 24. 2008 23:30

Hello again,

It started as a simple script, but it turned out as a whole guide. I included all the relevant information and files you need to remap the Fn key. The guide can be found at:

http://brrp.mine.nu/fnkey/

All this is based on the remapping of my Apple Wireless Keyboard, now with full use of the Fn key as a modifier and also the Eject key. From what I gather, the DLL has helped a lot of people already to remap single action keys and in doing so has proven its worth. That's why I'm confident that this method for remapping the Fn key will work on a wide variety of keyboards.

Feedback on the script and on whether you succeeded is much appreciated. Good luck!

Regards,

Veil

March 25. 2008 21:51

Hello, the fact that you succeeded is a really good news. Unfortunately it is not working for me. The fn key is not detected and the only key that is detetected is the eject key. strange...

Jonx

May 8. 2008 16:18

Hi - for me it works like a charm. Thank you very much!

Andre Tagesgeld

May 10. 2008 13:05

Hello Andre, can you confirm that you have the bluetooth keyboard and not the wired version? Also what is your OS and bootcamp version? Thank you Smile

Jonx

May 14. 2008 05:27

Many thanks for the fantastic utility! I dual-boot Linux/Windoze (Windoze only for gaming) and I've felt crippled when I log into Windows as a result of the default actions of the function keys on the keyboard. Many games rely on the F keys and it was a real pain having to hold Fn every time I needed to use one.

Had to upgrade my .net framework before being able to run your exe, but once that was upgraded, it worked like a charm!

Chris

May 14. 2008 20:33

Thank you for the follow up Smile
It's good to hear...

jonx

June 11. 2008 09:42

I'm obviously missing the point. My lack of understanding no doubt. I downloaded the utility and ran it. I toggle fn on and off but nothing that I notice happens.

What should I expect to happen? and how can I test this? and what might I practically use this utility for?

Thanx

Peter

June 12. 2008 02:45

Hello Peter,
The thing is not doing much, for sure...
You see, by default, when you press F10, it does just that. F10.
But now if you want to shut the sound down, you need to press Fn+F10, alright? (Maybe it's doing the otherway by default for you). Now, maybe that what you want, is that by default when you press the F keys they have their special function, sound up/down, play/pause etc... you do not want to press Fn+F key each time but just F10 to shut down the sound for example. Thne now if you need to have a real F10 you would now have to press Fn+F10...

So, a long story short. With that tool you specify if the keys have by default (without pressing Fn) the F1 to F19 meaning or the special key meaning Wink

In case it's still not clear, don't hesitate to ask...

Jonx

June 12. 2008 18:21

Thanks for the quick reply. I confess not too long after the post I realised what you said. However the specific example of f10 being mute fails to work for me. The pause (f8) and next track (f9) and previous track (f7) all work but not mute. Any ideas?

Peter

June 14. 2008 23:32

Not really. Those keys need to be forwarded by the keyboard drivers on one side and handled by the sofware you are using on the other side. Are you usin ITunes? Cause pause works for me in Windows media player.

Jonx

June 16. 2008 13:47

I'm using winamp 2.91

Peter

June 17. 2008 14:58

Can you try with windows media player? if it's working there, then it's more like a winamp bug... eventually Wink

Jonx

June 24. 2008 19:04

sorry about the long dealy in replying. no the mute does not work in Windows media player. In fact neither does the pause (and this does work in winamp)

Peter

July 19. 2008 10:21

@Jonx: yes, I can confirm, that it´s the bluetooth keybord.

Andre Tagesgeld

July 29. 2008 06:36

thank u! This is just what I needed to use VS.net

rob

August 9. 2008 00:50

Thank you!! Was hoping to find this very solution. Can now debug in Visual Studio to my heart's (dis)content.

William W. Lin

September 20. 2008 16:43

macbook -- sometimes my \\\\\\\\\\ kicks into repeating mode after I hit enter. I can make it stop by hitting "fn+return"...... any thoughts.

pat r

September 21. 2008 21:06

Hello, I have this also with the 'S' letter. With the 'C' letter also. I heard some other people having it. Don't know how to fix this. Maybe the bios update does something? Can't tell as I don't have a mac to make the update...

Jonx

Add comment


 

  Country flag





Live preview

October 5. 2008 21:07