<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>chuyeow.wtf</title>
  <subtitle>Go, Ruby, Rails, Firefox, Anime, Mac</subtitle>
  <link rel="self" type="application/atom+xml" href="https://chuyeow.wtf/categories/productivity/feed.xml"/>
  <link rel="alternate" type="text/html" href="https://chuyeow.wtf"/>
  <generator uri="https://www.getzola.org/">Zola</generator>
  <updated>2020-06-24T08:00:00+08:00</updated>
  <id>https://chuyeow.wtf/categories/productivity/feed.xml</id>
  <entry>
    <title>Remapping keys on macOS</title>
    <published>2020-06-24T08:00:00+08:00</published>
    <updated>2020-06-24T08:00:00+08:00</updated>
    <author><name>Chu Yeow</name></author>
    <link rel="alternate" type="text/html" href="https://chuyeow.wtf/2020/06/24/remapping-keys-on-macos/"/>
    <id>https://chuyeow.wtf/2020/06/24/remapping-keys-on-macos/</id>
    <content type="html" xml:base="https://chuyeow.wtf/2020/06/24/remapping-keys-on-macos/">&lt;p&gt;&lt;a href=&quot;#remap-keys-on-macos&quot;&gt;I ramble a bit here - you may want to &lt;b&gt;skip to how to remap keys on macOS&lt;&#x2F;b&gt;&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;I attended &lt;a href=&quot;https:&#x2F;&#x2F;developer.apple.com&#x2F;wwdc20&#x2F;&quot;&gt;WWDC&lt;&#x2F;a&gt; for the first time ever (making lemonade in the
COVID-19 situation), and after watching the &lt;a href=&quot;https:&#x2F;&#x2F;developer.apple.com&#x2F;wwdc20&#x2F;101&quot;&gt;keynote&lt;&#x2F;a&gt;, got pretty
excited about macOS Big Sur.&lt;&#x2F;p&gt;
&lt;p&gt;I wanted to install the macOS Big Sur developer beta but &lt;em&gt;not&lt;&#x2F;em&gt; at the expense of making my main development
MacBook Pro virtually unusable. One of the things I thought I really needed working was
&lt;a href=&quot;https:&#x2F;&#x2F;karabiner-elements.pqrs.org&#x2F;&quot;&gt;Karabiner-Elements&lt;&#x2F;a&gt;, which I use to remap keys, specifically:&lt;&#x2F;p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;code&gt;Caps Lock&lt;&#x2F;code&gt; to &lt;code&gt;Esc&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
  &lt;li&gt;&lt;code&gt;Esc&lt;&#x2F;code&gt; to &lt;code&gt;`&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;This particular remapping is really because I use &lt;code&gt;`&lt;&#x2F;code&gt; (backtick) as my
&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;tmux&#x2F;tmux&quot;&gt;tmux&lt;&#x2F;a&gt; prefix key. I picked this up from an
&lt;a href=&quot;https:&#x2F;&#x2F;twitter.com&#x2F;keyist&quot;&gt;ex-colleague&lt;&#x2F;a&gt; after watching him &lt;em&gt;fly&lt;&#x2F;em&gt; while switching tmux panes. And I
use either a compact 60% or 65% keyboard which meant I didn&#x27;t have a dedicated &lt;code&gt;`&lt;&#x2F;code&gt; key - I&#x27;d have to hit
&lt;code&gt;Fn-Esc&lt;&#x2F;code&gt; which is even more terrible than the default of &lt;code&gt;Ctrl-B&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;esc-tilde-backticks.jpg&quot; alt=&quot;Photo of Escape key&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p id=&quot;remap-keys-on-macos&quot;&gt;Unsurprisingly, &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;pqrs-org&#x2F;Karabiner-Elements&#x2F;issues&#x2F;2331&quot;&gt;Karabiner-Elements was not working
in Big Sur&lt;&#x2F;a&gt;. Not satisfied with that, I quickly found that macOS has supported
&lt;a href=&quot;https:&#x2F;&#x2F;developer.apple.com&#x2F;library&#x2F;archive&#x2F;technotes&#x2F;tn2450&#x2F;_index.html&quot;&gt;native key remapping&lt;&#x2F;a&gt; since macOS
Sierra via the &lt;code&gt;hidutil&lt;&#x2F;code&gt; command-line tool. If you&#x27;re not beyond scrappily writing some JSON and XML, this
&lt;em&gt;just works&lt;&#x2F;em&gt;:&lt;&#x2F;p&gt;
&lt;ol&gt;
  &lt;li&gt;Decide what keys you want to remap. In my case, I wanted to remap &lt;code&gt;Caps Lock&lt;&#x2F;code&gt; to &lt;code&gt;Esc&lt;&#x2F;code&gt;.&lt;&#x2F;li&gt;
  &lt;li&gt;
    &lt;a href=&quot;https:&#x2F;&#x2F;developer.apple.com&#x2F;library&#x2F;archive&#x2F;technotes&#x2F;tn2450&#x2F;_index.html#&#x2F;&#x2F;apple_ref&#x2F;doc&#x2F;uid&#x2F;DTS40017618-CH1-TNTAG8&quot;&gt;Apple&#x27;s docs&lt;&#x2F;a&gt;
    say:
    &lt;blockquote&gt;The keys take a hexadecimal value that consists of 0x700000000 or’d with the desired keyboard usage value&lt;&#x2F;blockquote&gt;
    Pretty cryptic, but what it really means is you just have to add &lt;code&gt;0x700000000&lt;&#x2F;code&gt; to your key&#x27;s &quot;usage ID&quot; in
    &lt;a href=&quot;https:&#x2F;&#x2F;developer.apple.com&#x2F;library&#x2F;archive&#x2F;technotes&#x2F;tn2450&#x2F;_index.html#&#x2F;&#x2F;apple_ref&#x2F;doc&#x2F;uid&#x2F;DTS40017618-CH1-KEY_TABLE_USAGES&quot;&gt;this table&lt;&#x2F;a&gt;
    (techically, this is a bitwise &lt;code&gt;OR&lt;&#x2F;code&gt;, which is &lt;em&gt;not&lt;&#x2F;em&gt; addition, but the usage IDs are small enough
    for it to not matter).
  &lt;&#x2F;li&gt;
  &lt;li&gt;
    &lt;code&gt;Caps Lock&lt;&#x2F;code&gt;&#x27;s usage ID is &lt;code&gt;0x39&lt;&#x2F;code&gt;. Adding &lt;code&gt;0x700000000&lt;&#x2F;code&gt; to that gives
    &lt;code&gt;0x700000039&lt;&#x2F;code&gt;.
  &lt;&#x2F;li&gt;
  &lt;li&gt;&lt;code&gt;Esc&lt;&#x2F;code&gt;&#x27;s usage ID is &lt;code&gt;0x29&lt;&#x2F;code&gt; - we&#x27;ll use &lt;code&gt;0x700000029&lt;&#x2F;code&gt;.&lt;&#x2F;li&gt;
  &lt;li&gt;&lt;code&gt;Caps Lock&lt;&#x2F;code&gt; (&lt;code&gt;0x700000039&lt;&#x2F;code&gt;) is the &lt;em&gt;source&lt;&#x2F;em&gt;, so we will specify &lt;code&gt;&quot;HIDKeyboardModifierMappingSrc&quot;: 0x700000039&lt;&#x2F;code&gt;.&lt;&#x2F;li&gt;
  &lt;li&gt;&lt;code&gt;Esc&lt;&#x2F;code&gt; (&lt;code&gt;0x700000029&lt;&#x2F;code&gt;) is the &lt;em&gt;destination&lt;&#x2F;em&gt;, so we will specify &lt;code&gt;&quot;HIDKeyboardModifierMappingDst&quot;: 0x700000029&lt;&#x2F;code&gt;.&lt;&#x2F;li&gt;
  &lt;li&gt;Repeat for each pair of keys you want to remap.&lt;&#x2F;li&gt;
  &lt;li&gt;
    Try it out in the command-line:
    &lt;pre&gt;hidutil property --set &#x27;{&quot;UserKeyMapping&quot;:[
  {
    &quot;HIDKeyboardModifierMappingSrc&quot;: 0x700000039,
    &quot;HIDKeyboardModifierMappingDst&quot;: 0x700000029
  },
  {
    &quot;HIDKeyboardModifierMappingSrc&quot;: 0x700000029,
    &quot;HIDKeyboardModifierMappingDst&quot;: 0x700000035
  }
]}&#x27;&lt;&#x2F;pre&gt;
  &lt;&#x2F;li&gt;
  &lt;li&gt;This remapping will be undone whenever you reboot your Mac, so one way to persist the remapping is to run the
  &lt;code&gt;hidutil&lt;&#x2F;code&gt; command every time your Mac boots. For that, we can rely on
  &lt;a href=&quot;https:&#x2F;&#x2F;developer.apple.com&#x2F;library&#x2F;archive&#x2F;documentation&#x2F;MacOSX&#x2F;Conceptual&#x2F;BPSystemStartup&#x2F;Chapters&#x2F;CreatingLaunchdJobs.html&quot;&gt;Launch Agents&lt;&#x2F;a&gt;.
  &lt;li&gt;
    Create a file named &lt;code&gt;~&#x2F;Library&#x2F;LaunchAgents&#x2F;com.example.KeyRemapping.plist&lt;&#x2F;code&gt;:
    &lt;script src=&quot;https:&#x2F;&#x2F;gist.github.com&#x2F;chuyeow&#x2F;2ab2d3e6a649389cea58f4d31f7f6d53.js&quot;&gt;&lt;&#x2F;script&gt;
    This file basically tells macOS to run the &lt;code&gt;hidutil&lt;&#x2F;code&gt; tool when it starts up.
  &lt;&#x2F;li&gt;
  &lt;li&gt;You&#x27;re all set!&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;A vast improvement would be to generate the key remappings from an HTML form &lt;code&gt;#ideas-are-free&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;I really love Karabiner-Elements, but my use of it has become less complex of late. There&#x27;s also something to be said
about running less software. And that brings me a tiny step closer to trying out Big Sur - yes, I can&#x27;t take the plunge
yet! You can evaluate whether you are ready after taking a look at this
&lt;a href=&quot;https:&#x2F;&#x2F;forums.macrumors.com&#x2F;threads&#x2F;big-sur-working-not-working-apps.2242312&#x2F;&quot;&gt;list of apps that are not working on macOS&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
</content>
  </entry>
</feed>
