[
  {
    "path": ".gitignore",
    "content": "Brewfile.lock.json\n"
  },
  {
    "path": "Brewfile",
    "content": "cask 'hammerspoon'\n"
  },
  {
    "path": "LICENSE",
    "content": "MIT License\n\nCopyright (c) 2017 Jason Rudolph\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "# ControlEscape.spoon\n\nSupercharge your <kbd>control</kbd> key. Tap it for <kbd>escape</kbd>. Hold it for <kbd>control</kbd>.\n\n### A more useful control key\n\nAs Steve Losh points out in his [Modern Space Cadet](http://stevelosh.com/blog/2012/10/a-modern-space-cadet/#control-escape) post, there are \"keys you hold down to change how other keys behave, but that (usually) don’t do anything if you use them on their own\" (e.g., <kbd>control</kbd>), and there are \"keys that you press and release but don’t want to 'repeat' as you hold them\" (e.g., <kbd>escape</kbd>). \"There are two [distinctly] different ways to use [these keys] and they’re each only useful in one of those ways. This means that we can *combine* them onto a single key without losing any useful functionality!\"\n\nWith that in mind, we can teach the <kbd>control</kbd> key to pull double duty:\n\n- If <kbd>control</kbd> is pressed and released in isolation, we can interpret it as <kbd>escape</kbd>\n- If <kbd>control</kbd> is held down and used in combination with another key, then we can let it provide the normal <kbd>control</kbd> key behavior\n\n### Goes great with Touch Bar\n\nIf you've got one of those fancy new Touch Bar Macs, you might find yourself longing for the good ol' days of a tactile <kbd>escape</kbd> key. Look no further. 😅\n\n### Optional: A more useful caps lock key\n\nWhat's more useful than a \"more useful control key?\" A more useful *and more-easily reachable* control key, of course. By repurposing the anachronistic caps lock key, we can skip the acrobatics needed to reach the physical control key. We can use <kbd>caps lock</kbd> to give us <kbd>control</kbd> and <kbd>escape</kbd> right on the home row.\n\nSay goodbye to [Emacs pinky](http://wiki.c2.com/?EmacsPinky). 👋\n\n## Dependencies\n\nThis functionality is developed and tested with the following dependencies:\n\n- macOS Sierra 10.12\n- [Hammerspoon 0.9.54][hammerspoon]\n\n## Installation\n\n#### Just the basics\n\n```sh\nmkdir -p ~/.hammerspoon/Spoons\n\ngit clone https://github.com/jasonrudolph/ControlEscape.spoon.git ~/.hammerspoon/Spoons/ControlEscape.spoon\n\ncd ~/.hammerspoon/Spoons/ControlEscape.spoon\n\nscript/setup\n```\n\n#### Optional: You're just a few seconds away from a [more useful caps lock key](#optional-a-more-useful-caps-lock-key)\n\nWith one more bit of setup, you'll be able to hold <kbd>caps lock</kbd> for <kbd>control</kbd>, and tap <kbd>caps lock</kbd> for <kbd>escape</kbd>:\n\nOpen *System Preferences*, navigate to *Keyboard > Modifier Keys*, and set the <kbd>caps lock</kbd> key to <kbd>control</kbd>. [[screenshot]](https://user-images.githubusercontent.com/2988/27111039-7f620442-507b-11e7-9bcf-93d46e14af13.png)\n\nNow you're ready to rock. 🤘\n\n## Where can I get this code as a Spoon?\n\nIf you prefer to roll your own Hammerspoon config, this code is also available as a [Spoon](https://github.com/Hammerspoon/hammerspoon/blob/0.9.54/SPOONS.md#how-do-i-install-a-spoon). Just look for `ControlEscape.spoon.zip` included with the [latest release](https://github.com/jasonrudolph/ControlEscape.spoon/releases/latest).\n\n## Shout-outs\n\nShout-out to [@arbelt](https://github.com/arbelt) and [@jasoncodes](https://github.com/jasoncodes) for the original implementation of this functionality. ⚡️🍻🌟\n\nThis code is an adaptation of their work:\n\n- https://gist.github.com/arbelt/b91e1f38a0880afb316dd5b5732759f1\n- https://github.com/jasoncodes/dotfiles/blob/ac9f3ac/hammerspoon/control_escape.lua\n\n## You might also like...\n\nStill reading? Dude, you're pretty serious about your keyboard. :neckbeard:\n\nLucky for you, there's more where this came from. Check out [jasonrudolph/keyboard](https://github.com/jasonrudolph/keyboard#features) for even more fun. ⌨🤓\n\n[hammerspoon]: http://www.hammerspoon.org\n"
  },
  {
    "path": "docs.json",
    "content": "[\n  {\n    \"Constant\" : [\n\n    ],\n    \"submodules\" : [\n\n    ],\n    \"Function\" : [\n\n    ],\n    \"Variable\" : [\n\n    ],\n    \"stripped_doc\" : [\n\n    ],\n    \"type\" : \"Module\",\n    \"Deprecated\" : [\n\n    ],\n    \"desc\" : \"Make the `control` key more useful...\",\n    \"Constructor\" : [\n\n    ],\n    \"items\" : [\n      {\n        \"def\" : \"ControlEscape:start()\",\n        \"name\" : \"start\",\n        \"doc\" : \"Start sending `escape` when `control` is pressed and released in isolation\",\n        \"stripped_doc\" : [\n          \"Start sending `escape` when `control` is pressed and released in isolation\"\n        ],\n        \"notes\" : [\n\n        ],\n        \"signature\" : \"ControlEscape:start()\",\n        \"type\" : \"Method\",\n        \"returns\" : [\n\n        ],\n        \"desc\" : \"Start sending `escape` when `control` is pressed and released in isolation\",\n        \"parameters\" : [\n\n        ]\n      },\n      {\n        \"def\" : \"ControlEscape:stop()\",\n        \"name\" : \"stop\",\n        \"doc\" : \"Stop sending `escape` when `control` is pressed and released in isolation\",\n        \"stripped_doc\" : [\n          \"Stop sending `escape` when `control` is pressed and released in isolation\"\n        ],\n        \"notes\" : [\n\n        ],\n        \"signature\" : \"ControlEscape:stop()\",\n        \"type\" : \"Method\",\n        \"returns\" : [\n\n        ],\n        \"desc\" : \"Stop sending `escape` when `control` is pressed and released in isolation\",\n        \"parameters\" : [\n\n        ]\n      }\n    ],\n    \"Method\" : [\n      {\n        \"def\" : \"ControlEscape:start()\",\n        \"name\" : \"start\",\n        \"doc\" : \"Start sending `escape` when `control` is pressed and released in isolation\",\n        \"stripped_doc\" : [\n          \"Start sending `escape` when `control` is pressed and released in isolation\"\n        ],\n        \"notes\" : [\n\n        ],\n        \"signature\" : \"ControlEscape:start()\",\n        \"type\" : \"Method\",\n        \"returns\" : [\n\n        ],\n        \"desc\" : \"Start sending `escape` when `control` is pressed and released in isolation\",\n        \"parameters\" : [\n\n        ]\n      },\n      {\n        \"def\" : \"ControlEscape:stop()\",\n        \"name\" : \"stop\",\n        \"doc\" : \"Stop sending `escape` when `control` is pressed and released in isolation\",\n        \"stripped_doc\" : [\n          \"Stop sending `escape` when `control` is pressed and released in isolation\"\n        ],\n        \"notes\" : [\n\n        ],\n        \"signature\" : \"ControlEscape:stop()\",\n        \"type\" : \"Method\",\n        \"returns\" : [\n\n        ],\n        \"desc\" : \"Stop sending `escape` when `control` is pressed and released in isolation\",\n        \"parameters\" : [\n\n        ]\n      }\n    ],\n    \"Command\" : [\n\n    ],\n    \"doc\" : \"Make the `control` key more useful: If the `control` key is tapped, treat it\\nas the `escape` key. If the `control` key is held down and used in\\ncombination with another key, then provide the normal `control` key\\nbehavior.\",\n    \"Field\" : [\n\n    ],\n    \"name\" : \"ControlEscape\"\n  }\n]\n"
  },
  {
    "path": "init.lua",
    "content": "--- === ControlEscape ===\n---\n--- Make the `control` key more useful: If the `control` key is tapped, treat it\n--- as the `escape` key. If the `control` key is held down and used in\n--- combination with another key, then provide the normal `control` key\n--- behavior.\n\nlocal obj={}\nobj.__index = obj\n\n-- Metadata\nobj.name = 'ControlEscape'\nobj.version = '0.1'\nobj.author = 'Jason Rudolph <jason@jasonrudolph.com>'\nobj.homepage = 'https://github.com/jasonrudolph/ControlEscape.spoon'\nobj.license = 'MIT - https://opensource.org/licenses/MIT'\n\nfunction obj:init()\n  self.sendEscape = false\n  self.lastModifiers = {}\n\n  -- If `control` is held for this long, don't send `escape`\n  local CANCEL_DELAY_SECONDS = 0.150\n  self.controlKeyTimer = hs.timer.delayed.new(CANCEL_DELAY_SECONDS, function()\n    self.sendEscape = false\n  end)\n\n  -- Create an eventtap to run each time the modifier keys change (i.e., each\n  -- time a key like control, shift, option, or command is pressed or released)\n  self.controlTap = hs.eventtap.new({hs.eventtap.event.types.flagsChanged},\n    function(event)\n      local newModifiers = event:getFlags()\n\n      -- If this change to the modifier keys does not invole a *change* to the\n      -- up/down state of the `control` key (i.e., it was up before and it's\n      -- still up, or it was down before and it's still down), then don't take\n      -- any action.\n      if self.lastModifiers['ctrl'] == newModifiers['ctrl'] then\n        return false\n      end\n\n      -- If the `control` key has changed to the down state, then start the\n      -- timer. If the `control` key changes to the up state before the timer\n      -- expires, then send `escape`.\n      if not self.lastModifiers['ctrl'] then\n        self.lastModifiers = newModifiers\n        self.sendEscape = true\n        self.controlKeyTimer:start()\n      else\n        if self.sendEscape then\n          hs.eventtap.keyStroke({}, 'escape', 1)\n        end\n        self.lastModifiers = newModifiers\n        self.controlKeyTimer:stop()\n      end\n      return false\n    end\n  )\n\n  -- Create an eventtap to run each time a normal key (i.e., a non-modifier key)\n  -- enters the down state. We only want to send `escape` if `control` is\n  -- pressed and released in isolation. If `control` is pressed in combination\n  -- with any other key, we don't want to send `escape`.\n  self.keyDownEventTap = hs.eventtap.new({hs.eventtap.event.types.keyDown},\n    function(event)\n      self.sendEscape = false\n      return false\n    end\n  )\nend\n\n--- ControlEscape:start()\n--- Method\n--- Start sending `escape` when `control` is pressed and released in isolation\nfunction obj:start()\n  self.controlTap:start()\n  self.keyDownEventTap:start()\nend\n\n--- ControlEscape:stop()\n--- Method\n--- Stop sending `escape` when `control` is pressed and released in isolation\nfunction obj:stop()\n  -- Stop monitoring keystrokes\n  self.controlTap:stop()\n  self.keyDownEventTap:stop()\n\n  -- Reset state\n  self.controlKeyTimer:stop()\n  self.sendEscape = false\n  self.lastModifiers = {}\nend\n\nreturn obj\n"
  },
  {
    "path": "script/generate-docs",
    "content": "#!/bin/sh\n\n# See https://github.com/Hammerspoon/hammerspoon/blob/0.9.54/SPOONS.md#generating\nhs -c \"hs.doc.builder.genJSON(\\\"$(pwd)\\\")\" | grep -v \"^--\" > docs.json\n"
  },
  {
    "path": "script/setup",
    "content": "#!/bin/sh\n\nMINIMUM_HAMMERSPOON_VERSION=0.9.54\n\nset -e\n\ncommand -v brew > /dev/null || (echo \"Homebrew is required: http://brew.sh/\" && exit 1)\n\nbrew bundle check || brew bundle\n\n# Prepare custom settings for Hammerspoon\nmkdir -p ~/.hammerspoon\nif ! grep -sq \"ControlEscape\" ~/.hammerspoon/init.lua; then\n  echo \"hs.loadSpoon('ControlEscape'):start() -- Load Hammerspoon bits from https://github.com/jasonrudolph/ControlEscape.spoon\" >> ~/.hammerspoon/init.lua\nfi\n\n# If Hammerspoon is already running, kill it so we can pick up the new config\n# when opening Hammerspoon below\nkillall Hammerspoon || true\n\n# Open Hammerspoon\nopen /Applications/Hammerspoon.app\n\n# Enable Hammerspoon at startup\nosascript -e 'tell application \"System Events\" to make login item at end with properties {path:\"/Applications/Hammerspoon.app\", hidden:true}' > /dev/null\n\n# Output Hammerspoon version\nCURRENT_VERSION=$(brew info hammerspoon | grep \"hammerspoon:\")\necho\necho \"Hammerspoon version $MINIMUM_HAMMERSPOON_VERSION or greater required. Actual installed version: $CURRENT_VERSION\"\necho\n\necho \"Done! Be sure to verify your version of Hammerspoon above. If your version is older than $MINIMUM_HAMMERSPOON_VERSION, run 'brew update && script/setup' to install a compatible version.\"\n"
  }
]