Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
New Hyper Key (josh.blog)
66 points by joshbetz on July 12, 2017 | hide | past | favorite | 55 comments


I used to use software to map keys. I religiously want to get rid of caps lock and use it as escape... but I also want control near by.

But let me tell you something; if you are a power user, then relying on software to map keys kind of sucks. I couldn't dual boot windows and linux without everything getting screwed up. I also can't easily switch from mac to linux when I get off work. So I decided to start buying fully programmable keyboards and doing all of it at the firmware. I use QMK (https://github.com/qmk/qmk_firmware) and do very similar things to op. For instance, where my caps lock is, I have set to tap for escape, hold for function layer and where tab is, I have tap for tab and hold for control. There's a ton of other bindings I have, but these are the heavy hitters that have made me very happy.

I killed Karabiner Elements. I removed my software bindings in Widnows and deleted my Xmodmap file in Linux because I can finally just plug a keyboard into a computer and have it behave the same everywhere.

The only drawback is laptop keyboards. I really wish those were programmable (if anyone knows of a way, I would love to hear about it ;)). I have to start Karabiner once in a while when I don't have one of my keyboards handy, or if I'm floating around coffeeshops.


I used to map capslock to control in software (I find control much more useful than escape because it has much wider use and for vim I can use ^[ anyway), but I've since switched to using a Kinesis Advantage2 and no longer need to.

For one, the Advantage2 has the modifier keys in super easy and convenient thumb clusters so moving them to capslock wouldn't actually make it any easier.

You can also remap the keys in the firmware itself, so the OS just sees a standard qwerty keyboard but you send it different keys (I use colemak, but again, its mapped on the keyboard level: the OS thinks I use US english qwerty). So I actually did remap my capslock, but I mapped it to tab because I find it slightly easier to press than the real tab. I also moved the keys in the thumb clusters a little bit to make control and command easier.

I now no longer need to change anything in software and everything works (my tweaks + my keyboard layout) by simply plugging the keyboard into a US english qwerty machine. I use the keyboard both on my home machine and my laptop, although on laptop only when I'm at home. When I'm not home, I have to rely on the usual software mods (I use OSX's settings to remap caps lock to control then)


I literally just went through this tonight with a fresh Arch/KDE install. 45 minutes with various permutations of custom Linux console keymaps, X11 keyboard options (specifically ctrl:nocaps), and KDE's own settings before finally landing on a solution for getting caps remapped to ctrl on my workstation.


In KDE, isn't that a single setting to select?

Apart from finding where the dialog is every 5 years or so, I've never had any trouble.


It is... Assuming you didn't also set the x11 option for it via localectl or similar. The two somehow conflict.


Did the idea come to out of the blue or did something inspire you? + what keyboards do you use?


Beware, the mucking-with-keybaords rabbit hole is deep. Don’t say nobody warned you.

https://geekhack.org https://deskthority.net


I started with the GH60, then handwired a broken ducky shine 3 with a teensy 2. I now use a jd40 and I'm waiting for a planck.

I didn't come up with it out of the blue... I think I was asking some IRC friends about dip switches and if there were any keyboards that supported a switch for disabling or remapping caps lock. Someone showed me the mechanical keyboards subreddit and that lead to a massive rabbit hole.

For anyone interested, handwiring an older mechanical keyboard is like the super budget way of getting a programmable keyboard since you don't have to buy switches, PCBs, keycaps, or plates. There's plenty of information online and the leopold and ducky cases are big enough to house everything once you desolder the PCB. Teensy 2 is like $17.


One very important remap: right meta (CMD/Windows) to backspace! Having such an easily reachable backspace makes a tremendous difference in day-to-day use :)


A buddy just PoC'd a key binding system for OS X to do arbitrary complex remappings like this (exactly to facilitate nonstandard esc, ctrl, hyper usage), represented as one or more state machines similar to this syntax:

  STATE1:
    caps down:
      ctrl+alt+cmd down
      STATE2
  STATE2:
    caps up:
      ctrl+alt+cmd up
      press esc
      STATE1
    after 1000ms, default:
      ctrl+alt+cmd up
      STATE1
This would allow us to layer, say, half qwerty on top of hyper with the same system. Or map caps to esc and ctrl, and map caps+shift to hyper, or a non-meta like tab to hyper.

Also could do state transitions on external events (like new app focused), and execute templated applescript.

An easy state machine to build would be this, which would prevent keypresses after focus stealing:

  STATE1:
    new window focused: STATE2
  STATE2:
    after 250ms: STATE1
    default:
      drop keypress
      STATE2


I just bought an ergodox ez (ergodox-ez.com) that has hyper and meh keys built in.

Quite a learning curve for the new layouts so far, but I think it will be great once I have it down.

For now, ctrl-alt-del is a big pita.


I have an Ergodox and I love it. I don't use hyper keys, but the sheer configurability of the keyboard has meant that I never feel limited by my keyboard (compare that with the new MacBook Pro keyboards which don't even have ESC keys!)

For some advice on how to deal with the layouts: I cleared most of the non alphanumeric keys in all layers and started adding things in when I needed them. It made the transition easier.


Thanks, I'll try that. I'm going to be doing a lot of remapping I can tell. The default layout makes some strange choices to me, like ctrl-alt-del difficulty.

I do love the mouse control layer already. Very handy to be able to toss in a quick mouse click without leaving the board.

It would be even better if they could add a thinkpad style mouse stick between a couple of the keys on the left hand. That would be a dream keyboard.


I have an ergodox infinity on the way, but for 9 months now, I have been very happy with my Atreus keyboard in dvorak configuration.


Slightly off-topic: Why is JSON so popular for this sort of thing? I think it's fine for programs communicating with each other, but I really don't understand why anyone would want to have to match brackets when writing a configuration file


I like using JSON because

- There are lots of great libraries for nearly every language to parse it, or they're built in

- It's got the benefits of XML (tags are right next to the data, unlike CSV) while being way less typing

- It's easy to scan since I'm already used to seeing [] and {} to represent common data structures

- I can pretty print it or remove whitespace

- It's popular, meaning there are lots of tools to work with it, but it's simple enough that a text editor will do

- Most text editors will match brackets and indentation for me, so it's not a huge issue


If it just had comments, trailing commas, and didn't require quoting names, I could forgive the brace matching. Really shortsighted.


Some implementations allow comments. There is a project called JSON5 that also allows trailing commas, and maybe omitting quotes for keys.

I have some (private) libraries in C++, Python, and Nim that support those features, too. Basically it understands JavaScript object literals. If I find some time, I'll package them up and publish them.

One thing I'd really like to change is to make the parser round-trippable, so it remembers all the whitespace and comments, and if you use these pseudo-json as config files, you can make programmatic changes without loosing anything.


I don't know about the other stuff, but I sort of see why comments were not supported: https://news.ycombinator.com/item?id=3912149

Personally I do miss them tremendously though.


If you just want to get the configuration file part of your program working so you can focus on other things, JSON is a fairly quick and easy option. You could make a more user-friendly format, but that might take longer.


YAML is better for this.


JSON has an advantage of not having significant whitespace: a bit more verbose with the { and [, but I'd argue it is more robust for complex configuration.

YAML feels to me like the creation of a person who has never fought with a makefile that imported another makefile that had an extra tab on line 9432: not quite true hell, but a few hours of trying to figure out WHY things aren't working right you would be hard pressed to tell the difference.


How is "no whitespace" an advantage for a human readable file format? You could write JSON with zero whitespace, but you wouldn't because whitespace is absolutely necessary for human comprehensibility.


Because humans make stupid accidental mistakes.

YAML says there's a world of difference between

    - flag1
    - option2
and

    -flag1
    -option2
but for a human who just wants their thing to work, that's inscrutable, but in JSON, they become

    [
        "flag1", 
        "config2"
    ]
and

    "-flag1 -config2"
respectively.

Personally, live python as config is my preference, followed by YAML because comments, but YAML isn't perfect.

If the options are right next to each other it's clear there's a misalignment:

    - option1
     -option2
won't work, but

     - option1
# if there is a huge explanatory

# multi-line comment

# as is sometimes seen in config

# files, sometimes it can be hard

# to see the misalignment.

      - option2


As @rockostrich and @fragmede pointed out, I'm talking about whitespace having parsing impact ("significant whitespace"), not just any whitespace. The fact that extra spaces changes the structure of the output seems like a total minefield to me, unless your config is being machine generated (in which case there are many more robust formats to choose).


No significant whitespace you say? Take a peek at this: https://paste.ofcode.org/n9q3dnDcPDK5KLex54z6uw


By "significant", fomojola meant whitespace does not affect parsing. That JSON you linked to could be minified into a single line with 0 whitespace and still be parsed.


I have a project with fairly complex YAML config files.

YAML quickly gets cranky and brittle, there are too many ways to do everything, and it's very challenging to easily debug some of the syntax errors. If I had to do it over again, I'd probably go with json over yaml.

With JSON, I can have my text editor do the validation before I even save. That kind of tooling just doesn't exist for YAML.


Completely agreed. For me, writing YAML always feels like a guessing game.

When I first encountered an ESLint config written in YAML, for example, it took me like a dozen tries (no exaggeration) to successfully convert a

    [2, "always"]
type value into a more advanced

    [2, { "options": blah, "foo": bar }]
value. The ways that intuitively seemed like they definitely should have worked, didn't work, and I consider myself a competent programmer.

I came to dislike it even more once I found out it had features like &anchors, <<:, etc. Not only do I find the syntax repulsive, but having custom user-named sections whose identifiers aren't actually significant and don't end up in the parsed structure is probably wasting a ton of people's time as they Google documentation for config section names that the consuming program doesn't actually understand because they don't really exist (they were just named at the author's whimsy).

It's not worth it. Use JSON, or possibly JSON5.


If yaml ever gets too cranky, just use JSON in your yaml document.

Since yaml is a superset of json, any valid json is valid yaml as well. This allows you to combine the two in very convenient ways:

  ---
  test:
    obj: {"solution": ["in", "the", "list", {"everything: "is possible"}]}


> yaml is a superset of json, any valid json is valid yaml as well

This is wrong.

http://p3rl.org/JSON::XS#JSON-and-YAML


Take a look at TOML next time, very simple syntax and a lot of libraries coming around. I've been using it in every new project I start when I end up wanting configuration.

https://github.com/toml-lang/toml


I can never remember the syntax for YAML, and it seems too complex and very fragile.

I rather just start with a real Python or JavaScript object literal in my source, and when it grows, move it to a new file, and run over it with a lenient JSON parser.


because you're allowed and able to use tools. then the popularity of json is an advantage, as you could just use whatever tool you wanted to edit it, and its popularity would mean you have tons of choices.

for example I just googled "lightweight online json editor mobile no registration" and was very pleased.

the more popular json gets, the objectively better choice it becomes.

you can edit it in a browser, as I just showed you, then copy the result over. it's great!


Probably the same reason you have people using XML for supposedly human read/writeable config files: it's hip.


Not to be confused with the actual, crufty old HYPER key, I guess. Which I'm reminded of solely because it was mentioned in something I was reading, yesterday.

https://en.wikipedia.org/wiki/Space-cadet_keyboard

More on-topic: Suggestions for comparable utilities on Linux as opposed to Mac? (Not complaining about Mac; just don't use one.) I've run across a few, without yet using any. Wonder what others use.


PC keyboards already have the "Super" key (Windows key), so there's less need for something to make global shortcuts on Linux.

xmodmap can alter the behaviour of Caps Lock, I have it swapped with the left control key. There are various utilities to control xmodmap, KDE and probably Gnome include a settings dialog.


It's a very personal preference of course, but I can't recommend higly enough to try mapping caps to command. My wrists are very grateful.

As a vim user I use Ctrl+[ for escape. I like it because it is a standard system mapping, so it works everywhere. Further, many systems (incl macOS) have standard options to map caps to control, so I can carry the habit pretty much everywhere, even if using someone else's computer temporarily.


You can have the best of both worlds: Caps for me is Control (could be cmd), but if i release it without having pressed another key, it sends escape.


Yeah, I used xcape for a year or so before coming to the conclusion it wasn't worth the trouble for me. It was mildly infuriating when switching systems.


Oh I meant to say Ctrl. Doh


How?


Caps as Ctrl & Esc guy here, too.

On OS X, I used to use Karabiner for this, but it stopped working after Sierra. Karabiner Elements hasn’t quite gotten back on par with its former self. I switched to Hammerspoon, and it’s been pretty good for this and other tasks (like remapping standalone left/right shift presses to insert left/right parens).


Here's what I have on my Linux machine:

    setxkbmap -layout us -option ctrl:swapcaps

    xcape&
xcape is available in plenty of distros, and it's what allows you to use both control and escape (when releasing) with caps lock.



I'd wager at least half of the people who struggle with the decision of if caps lock should be control or escape don't realize that Ctrl-[ is escape.


Unfortunately, on a German QWERTZ keyboard, to get "[" you have to press AltGr + 8.


maybe you like https://neo-layout.org/

at least the windows ahk driver can keep layers 1 und 2 in qwerty if you don't want to learn new letter positions.


The heading does not fit with the article body. I don't quite understand what it is about, but I can see it's not about Hyper keys.

If you lack a physical Hyper key and want to change Capslock into Hyper, simply run:

    xkbcomp -xkb $DISPLAY -o my.xkb
    perl -0777 -i -pe's/key <CAPS> [{]\K[^}]+/[ Hyper_L ]/ms' my.xkb
    xkbcomp my.xkb -o $DISPLAY
    xev  # for testing


I don't have the muscle memory to use CapsLock as Control, but I have enjoyed using it as a shortcut to double-click the left mouse button. Probably a symptom of the visual programming environments I use most of the time, but it does reduce strain on my clicker finger. For "hyper" duties the Windows key is conveniently located and easy to map in AutoHotKey.


I believe you need to add the .json extension in your Karabiner URL for this to work - once I did that locally I finally have my hyper key back! Thanks!


Thanks, I fixed it.


Does anyone else feel reluctant to install a tool that allows a link on a website to remap your keyboard? Am I misunderstanding this?


on windows I use autohotkey, and you can make it program specific what happens, like

  SetTitleMatchMode, RegEx
  #IfWinActive .*Microsoft Visual Studio|JetPopupMenuView|ReSharper|.*GVIM|.*Visual Studio Code
    Capslock::Esc
  #IfWinActive


Mandatory XKCD: https://xkcd.com/1172/




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: