# Guide: Using the Apple Wired Keyboard in Windows 7



## nathris

*Introduction (why I'm even writing this in the first place)
*
After the spacebar on my beloved Sidewinder X4 started sticking I had to get a new keyboard (lost my receipt, so no RMA). My budget was only around $50 though, so that ruled out a mechanical. Plus Tankguys is out of Ducky Browns, the only mech keyboard I was considering, and I'm not a fan of blues or blacks after having tried both.

I could get another Sidewinder X4, but the cheapest I could find it was $70 shipped and it wouldn't seem right paying $70 to replace a keyboard that should be working in the first place.

So I ended up getting an Apple Wired Keyboard, because everything else in the price bracket sucked, and scissor switches are a least a step up from the mushy rubber domes you get with generic low end keyboards, and Apple products are the same price online as in B&M, so I could save the shipping costs/time. I bought it for $56 after tax from Futureshop. Plus I love the minimalism.

The problem with getting an Apple keyboard is that its not designed to be used outside OSX, or even on any computer that's not a Mac. And like everything Apple does for Windows, support is borderline non-existent. If you aren't running Windows on a Mac then Boot Camp won't work, and if you can't run Boot Camp then you're left with generic keyboard drivers and non-functioning keys. But we can fix that.










*Step 0*

Plug the keyboard in. Windows will take a while to install the proper drivers and it should mostly work, aside from a few problems:

The windows(command) and alt(option) keys are switched. This is because OSX uses command for standard hotkeys (eg. command+c, command+v)
The eject button doesn't work
The fn button doesn't work, and thus neither do any of the media controls
F13-F19 don't do anything
We can fix everything but the Fn key. Maybe you'll have more luck than I did, but I couldn't get it to work.

*Step 1 - Install Autohotkey
*
Autohotkey is an open-source utility that lets you remap keys. Its not quite as elegant as SharpKey, as it required you to run your scripts in the background, but its much more powerful. Download AutoHotkey_L from here: http://www.autohotkey.com/download/ and install it. I recommend choosing the Ansi version when asked, since most of the scripts I've found don't support Unicode.

*Step 2 - Download Keyboard Script*
I've attached the script I'm using to remap the keys to my liking. It consists of 2 parts:


Spoiler: Apple Wired Keyboard.ahk



The sole purpose of this script is to enable the eject key. The reason it doesn't work is because it actually has its own driver and shows up as a different HID device. It should also enable the Function key, but its not working on my machine. All it does is remap Eject to F20, and would remap Fn to F21 if it worked.

Code:



Code:


; Note: Go to line 63 to map your command to the Eject key.
;
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
Gui, Show, x0 y0 h0 w0, FnMapper
fnPressed := 0
HomePath=AutohotkeyRemoteControl.dll
hModule := DllCall("LoadLibrary", "str", HomePath)
OnMessage(0x00FF, "InputMsg")
EditUsage := 1
EditUsagePage := 12
HWND := WinExist("FnMapper")
nRC := DllCall("AutohotkeyRemoteControl\RegisterDevice", INT, EditUsage, INT, EditUsagePage, INT, HWND, "Cdecl UInt")
WinHide, FnMapper
InputMsg(wParam, lParam, msg, hwnd) 
{
  DeviceNr = -1
  nRC := DllCall("AutohotkeyRemoteControl\GetWM_INPUTDataType", UINT, wParam, UINT, lParam, "INT *", DeviceNr, "Cdecl UInt")
  if (errorlevel <> 0) || (nRC == 0xFFFFFFFF) 
  {
        MsgBox GetWM_INPUTHIDData fehlgeschlagen. Errorcode: %errorlevel%
        gosub cleanup
  }
  ;Tooltip, %DeviceNr%
  ifequal, nRC, 2
  {
    ProcessHIDData(wParam, lParam)
  }
  else 
  {
        MsgBox, Error - no HID data
  }
}
Return

ProcessHIDData(wParam, lParam)
{
        ; Make sure this variable retains its value outside this function
        global fnPressed
        global ejectPressed

  DataSize = 5000
  VarSetCapacity(RawData, %DataSize%, 0)
  RawData = 1
  nHandle := DllCall("AutohotkeyRemoteControl\GetWM_INPUTHIDData", UINT, wParam, UINT, lParam, "UINT *" , DataSize, "UINT", &RawData, "Cdecl UInt")
  KeyStatus := NumGet(RawData, 1,"UChar")
  Transform, FnValue, BitAnd, 16, KeyStatus
  Transform, EjectValue, BitAnd, 8, KeyStatus

  if (FnValue = 16) {
        MsgBox function pressed
        fnPressed := 1
        SendInput {F21}
        return
  } else {
                fnPressed := 0
  }

  if (EjectValue = 8) {
        ejectPressed := 1

        SendInput {F20}

        } else {
        ejectPressed := 0
  }

} ; END: ProcessHIDData

; If there was an error retrieving the HID data, cleanup
cleanup:
DllCall("FreeLibrary", "UInt", hModule)  ; It is best to unload the DLL after using it (or before the script exits).
ExitApp







Spoiler: AutoHotkey.ahk



This is the primary script that rebinds all of the keys to the more familiar windows ones.

Code:



Code:


#InstallKeybdHook
#SingleInstance force
SetTitleMatchMode 2
#Include Apple Wired Keyboard.ahk
SendMode Input

; --------------------------------------------------------------
; NOTES
; --------------------------------------------------------------
; ! = ALT
; ^ = CTRL
; + = SHIFT
; # = WIN

; media/function keys all mapped to the right option key
RAlt & F7::SendInput {Media_Prev}
RAlt & F8::SendInput {Media_Play_Pause}
RAlt & F9::SendInput {Media_Next}
RAlt & F10::SendInput {Volume_Mute}
RAlt & F11::SendInput {Volume_Down}
RAlt & F12::SendInput {Volume_Up}

; swap left command/windows key with left alt
LWin::LAlt
LAlt::LWin ; add a semicolon in front of this line if you want to disable the windows key

; Eject Key
F20::SendInput {Insert}

; F13-15, standard windows mapping
F13::SendInput {PrintScreen}
F14::SendInput {ScrollLock}
F15::SendInput {Pause}

;F16-19 custom app launchers, see http://www.autohotkey.com/docs/Tutorial.htm for usage info
F16::Run Notepad
F17::Run calc.exe
F18::Run http://www.overclock.net
F19::Run cmd





Download and extract the zip folder somewhere (I recommend your User folder), and run AutoHotKey.ahk to start the script. It should remap your keyboard as follows:










I highly encourage you to play around with it though. I created this setup to be generic, but I honetly don't expect anyone needs the scroll lock or pause keys. You can remap any key on your keyboard, and do more than simply swap buttons. Check out http://www.autohotkey.com/docs/Tutorial.htm for more of what you can do.

*Step 3 (Optional): Start the script when Windows starts.
*
In order to do this you need to place a shortcut in the startup folder (C:\Users\\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup)

You can quickly open this by typing %AppData%\Microsoft\Windows\Start Menu\Programs\Startup into the search bar in the start menu or the explorer address bar. Create a shortcut to AutoHotkey.ahk in the folder like so: (protip: you can create a shortcut by holding ALT and dragging the file over)









And that's it. Not sure the eject key fix will work for any other model of Apple keyboard (mine is A1243 btw) but the hotkey remappings should work on any keyboard, so even if you don't have an Apple wired keyboard you could use this as a base for your own keyboard.

Also if you can get the Fn button working please please please share it with me. My OCD is driving me nuts.

Edit: uploaded the wrong file. whoops.









AppleWiredKeyboard_AHK.zip 11k .zip file


----------



## Garyx24

I just prefer using sharpkey since its simple easy & fast.


----------



## davidcncn

Just read your post and used your solution and it worked. Thanks!!!


----------



## dannywaugh1

everthing is working for me aprt from the insert key. in the script is says go to line 63 to set. what do i need to do? Sorry i must tell you im new to this.

i have model no A1243

thanks!


----------



## braindeadcrave

Thank you worked like a charm P:


----------



## bcji

I can't for the life of me get the media keys to work. Everything else okay! Any ideas please?


----------



## name

This worked great for me, but the equals sign (=) on the number pad doesn't do anything. What can I add to the script?


----------



## SnoWHandS

A little hard to understand at first but when I downloaded the zip you attached at the end of your post it all made sense, you're meant to open those .AHK files with the application you download from AutoHotKey's website. . . I was trying to compile them with that exe compiler they have on their download page which doesn't help









I also made my eject key a windows task manager key which will come in useful however I originally wanted to make it so that when I hold the eject key and a media key, the media function would be carried out, however that proved difficult as all the combinations I tried didn't work. If anyone has successfully done this themselves please do post a response

I also made my F19 key a Alt F4 key using the function F19:: Send !{F4}

Thanks for posting this it was a great help as Bootcamp is a typical apple application with no support...


----------



## Jixr

guess you never heard of uawks? ( unoffical apple wireless keyboard support )
works with both wired and wireless apple keyboards
1 click download and done.


----------



## xbipin

with the newer apple boot camp drivers the fn keys work so can u provide the modified script using fn+f7-f12 ?


----------



## tomwalker

When I plugged the same keyboard into my Windows 7 machine, it loaded the drivers and worked fine. Alt and Ctrl keys were mapped correctly. However, after I unplugged it from USB port and then plugged it back in, my Win7 laptop would not recognize it anymore (even after reboot). A friend of mine had the same thing happen, but when he plugs it in via his monitor's USB port, it works. I don't have USB on my monitor, and don't want to use a USB Hub (assuming that might solve the issue, since a monitor with USB is like a hub). Any idea on how to get around this issue?

Apple Keyboard Model A1243 EMC No. 2171


----------

