{"id":764,"date":"2011-11-08T02:17:50","date_gmt":"2011-11-07T18:17:50","guid":{"rendered":"http:\/\/www.computersolutions.cn\/blog\/?p=764"},"modified":"2011-11-08T02:28:52","modified_gmt":"2011-11-07T18:28:52","slug":"macbook-pro-top-replacement-issue-or-how-i-fixed-my-macbook-and-sorted-out-the-function-keys","status":"publish","type":"post","link":"https:\/\/www.computersolutions.cn\/blog\/2011\/11\/macbook-pro-top-replacement-issue-or-how-i-fixed-my-macbook-and-sorted-out-the-function-keys\/","title":{"rendered":"Macbook Pro top replacement issue &#8211; or how I fixed my Macbook and sorted out the function keys."},"content":{"rendered":"<p>I&#8217;ve been buying broken Macbook&#8217;s in SA when I&#8217;ve been home, for repair in China.<\/p>\n<p>My latest purchase is a pre unibody Mac Book Pro that had been dropped &#8211; the top case was dented,and the screen shattered.<br \/>\nThe LCD was fairly painless to replace &#8211; I&#8217;ve done quite a few already on various models, and I have a bazillion suppliers for raw panels.<\/p>\n<p>The top case was a little more problematic &#8211; I ordered 2 consecutive replacements off of Taobao, but unfortunately the delivery company (ShenTong) destroyed both in shipping.  Took about a month to sort that out and find a yet another replacement with explicit instructions please not to send via ShenTong (aka destroyer of parts).<\/p>\n<p>The third case arrived in pristine condition, and I installed the keyboard from the previous case, only to find that the function keys didn&#8217;t work, and the caps lock didn&#8217;t work.<\/p>\n<p>It wasn&#8217;t a hardware issue with the keyboard, as it worked fine in another laptop.  I even ordered another one just to make sure.<\/p>\n<p>A bit of googling revealed that the keyboard kext gets the layout from the USB hardware ID present in the top case.<br \/>\nAs my top case didn&#8217;t quite match up hardware id wise, I was seeing that as an issue.<\/p>\n<p>Fixing this is a bit tricky, but doable.<\/p>\n<p>First up was to find out what the hardware id is for the USB case.<br \/>\nIn my case this was as below (snarfed from System Information \/ USB)<\/p>\n<pre>\r\nApple Internal Keyboard \/ Trackpad:\r\n\r\n  Product ID:\t0x0231\r\n  Vendor ID:\t0x05ac  (Apple Inc.)\r\n  Version:\t0,70\r\n  Speed:\tUp to 12 Mb\/sec\r\n  Manufacturer:\tApple, Inc.\r\n  Location ID:\t0x5d200000 \/ 3\r\n  Current Available (mA):\t500\r\n  Current Required (mA):\t40\r\n<\/pre>\n<p>Product ID is the useful bit &#8211; 0x0231 =  561 in decimal.<br \/>\nSo, we need to lookup 561 in the kext (driver) for the keyboard.<\/p>\n<p>In Lion \/ Snow Leopard, this is in the AppleUSBTopCase.kext over in System \/ Library \/ Extensions.<\/p>\n<p>If you open up that kext, it has the plist for the keyboard layouts over here &#8211;<\/p>\n<p>AppleUSBTopCase.kext \u00bb Contents \u00bb PlugIns \u00bb AppleUSBTCKeyEventDriver.kext \u00bb Contents \u00bb Info.plist<\/p>\n<p>Open up the Info.plist, and look for the Product ID that matches your Product ID &#8211; in my case 560.<\/p>\n<p>The key FnFunctionUsageMap contains the mapping for the keyboard.  In my case I had to change it to this:<\/p>\n<pre>\r\n<key>FnFunctionUsageMap<\/key>\r\n<string>0x0007003a,0x00ff0005,0x0007003b,0x00ff0004,0x0007003c,0x000c00e2,0x0007003d,0x000c00ea,0x0007003e,0x000c00e9,0x0007003f,0x00070083,0x00070040,0x00ff0006,0x00070041,0x00ff0007,0x00070042,0x00ff0009,0x00070043,0x00ff0008<\/string>\r\n<\/pre>\n<p>Each value is a pair &#8211; first the key number, then the value to set it to.<br \/>\n0x0007003a = F1<br \/>\n0x0007003b = F2<br \/>\n&#8230;<\/p>\n<p>My above settings are for<br \/>\nF1 = brightness down<br \/>\nF2 = brightness up<br \/>\nF3 = mute<br \/>\nF4 = volume down<br \/>\nF5 = volume up<br \/>\nF6 = num lock<br \/>\nF7 = Expose<br \/>\nF8 = Keyboard Light off<br \/>\nF9 = Keyboard Light down<br \/>\nF10 = Keyboard Light Up<br \/>\nF11 = n\/a<br \/>\nF12 = n\/a<\/p>\n<p>I got these values from here &#8211; <\/p>\n<p>\/\/ usage IDs from the hid<br \/>\n#define FF_BRIGHTNESS_DOWN_ID_LAPTOP @&#8221;0x00ff0005&#8243; \/\/ for laptops<br \/>\n#define FF_BRIGHTNESS_UP_ID_LAPTOP @&#8221;0x00ff0004&#8243; \/\/ for laptops<br \/>\n#define FF_BRIGHTNESS_DOWN_ID_EXTERNAL @&#8221;0xff010021&#8243; \/\/ for external keyboards<br \/>\n#define FF_BRIGHTNESS_UP_ID_EXTERNAL @&#8221;0xff010020&#8243; \/\/ for external keyboards<br \/>\n#define FF_EXPOSE_ID @&#8221;0xff010010&#8243;<br \/>\n#define FF_DASHBOARD_ID @&#8221;0xff010002&#8243;<br \/>\n#define FF_ILLUMINATION_TOGGLE_ID @&#8221;0x00ff0007&#8243;<br \/>\n#define FF_ILLUMINATION_DOWN_ID @&#8221;0x00ff0009&#8243;<br \/>\n#define FF_ILLUMINATION_UP_ID @&#8221;0x00ff0008&#8243;<br \/>\n#define FF_VIDEO_MIRROR_ID @&#8221;0x00ff0006&#8243;<br \/>\n#define FF_REWIND_ID @&#8221;0x000C00B4&#8243;<br \/>\n#define FF_PLAYPAUSE_ID @&#8221;0x000C00CD&#8221;<br \/>\n#define FF_FASTFORWARD_ID @&#8221;0x000C00B3&#8243;<br \/>\n#define FF_MUTE_ID @&#8221;0x000C00E2&#8243;<br \/>\n#define FF_VOLUME_DOWN_ID @&#8221;0x000C00EA&#8221;<br \/>\n#define FF_VOLUME_UP_ID @&#8221;0x000C00E9&#8243;<\/p>\n<p>Once I&#8217;d done that, I also needed to rebuild (or in my case build), the Kext cache so that the OS would use it on next reboot.<br \/>\nHeres how to do that in Lion<\/p>\n<pre>\r\nsudo kextcache -v 1 -a i386 -a x86_64 -m \/System\/Library\/Caches\/com.apple.kext.caches\/Startup\/Extensions.mkext \/System\/Library\/Extensions\r\n<\/pre>\n<p>&#8230;oh, and lastly, reboot of course!<\/p>\n<p>Post reboot my function keys were working normally.<br \/>\nThe caps lock key is still non-functional, but I&#8217;m ok with that, as its means a bit more work for little effort.<\/p>\n<p>I may look into setting up a special plist to override the usb_id its getting from the hardware via the method here  &#8211;<a href=\"http:\/\/www.projectosx.com\/forum\/index.php?showtopic=798\">http:\/\/www.projectosx.com\/forum\/index.php?showtopic=798<\/a><\/p>\n<p>..but again, time vs effort&#8230;<\/p>\n<p>Still, my Macbook is working now more or less, so its good enough for me \ud83d\ude42<\/p>\n<p>Of course, subsequently to doing this the hard way, I found a program to do it all for me!<\/p>\n<p><a href=\"http:\/\/pqrs.org\/macosx\/keyremap4macbook\/\">http:\/\/pqrs.org\/macosx\/keyremap4macbook\/<\/a><\/p>\n<p>Suggest unless you are a masochist, use that!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been buying broken Macbook&#8217;s in SA when I&#8217;ve been home, for repair in China. My latest purchase is a pre unibody Mac Book Pro that had been dropped &#8211; the top case was dented,and the screen shattered. The LCD was fairly painless to replace &#8211; I&#8217;ve done quite a few already on various models, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[7,25],"tags":[524,358,357,359,261,360],"class_list":["post-764","post","type-post","status-publish","format-standard","hentry","category-apple","category-technical-mumbo-jumbo","tag-apple","tag-function-keys","tag-keyboard","tag-plist","tag-replace","tag-top-case"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/posts\/764","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/comments?post=764"}],"version-history":[{"count":3,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/posts\/764\/revisions"}],"predecessor-version":[{"id":766,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/posts\/764\/revisions\/766"}],"wp:attachment":[{"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/media?parent=764"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/categories?post=764"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/tags?post=764"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}