Every Emacser Can Use Hyper on Every USB HID Keyboard

Every Emacser wishes that they could use Hyper.

Hyper is the last free-range where you can bind how you want without any conflicts. It isn’t that way everywhere else you see!

The Control and Meta namespaces are overflowing with bindings. Super was supposedly reserved, but most packages used it anyway. Hydra and Key-Chord provide a nice work around, but it would be so much simpler just to have another modifier, like Hyper… so why don’t we? Simple answer: the USB standard only supports 4 modifier keys and that doesn’t include Hyper.

Here is the standard. On page 56 it explains that there is one byte allocated to store the modifier key. There are four of them: CTRL, SHIFT, ALT, GUI. For each modifier, there is LEFT and there is a RIGHT, hence the 8 bits. Here is what I want to have happen:

  • Alt is for the OS
    • Change windows
    • Take screenshots
  • Gui is for the OS
    • Show run dialogs
    • Insert characters
  • Control is for both the OS and Emacs
    • Beyond Windows copy, there is no overlap
  • Meta is for Emacs
  • Super is for Emacs
  • Hyper is for Emacs

Like all things Emacs, you just say what you want, read the literature, and 99% of the time you find an awesome solution already in place. Yet again, it is true. Here is how to make it happen in OS X

There are virtually eight modifiers available. Ignore their location and use them individually across the keyboard. From Emacs perspective, the left keys cannot be ignored. This must be by design and it makes total sense. The right keys can be ignored. This lets us use Alt and Gui exclusively for the operating system. Here is the ultimate part: since Control doesn’t have any conflicting bindings between the OS and Emacs, we can re-define the Right Control to do something else and make the Left Control act as control both for Windows and for Emacs. That frees up on control key, giving us space to redefine another key for Hyper. Here is how it looks:

Configure the OS Specific Modifiers

Emacs does not interpret these keys. They are passed directly to the operating system.

(setq ns-right-command-modifier 'none)
(setq ns-right-option-modifier 'none)

Configure the Control Modifier using the Right Control

(setq ns-right-control-modifier 'control)

Configure Emacs Meta Keys

(setq ns-control-modifier 'meta)
(setq ns-command-modifier 'super)
(setq ns-option-modifier 'hyper)

Layout & Results

Here is how it can look to the left side of the spacebar:

all-modifiers-for-emacs.png

I tested it out on a Mac and it worked as expected from the documentation.

The work now is to set up a keyboard that has the modifier keys appear in this layout twice on a single keyboard.

This is why I want a custom keyboard layout:

  • Emacs makes it EASY to use all of the modifier keys for Emacs
  • Emacs makes it EASY to use all of the modifier keys for the operating system
  • You just need a keyboard layout that lets you do what you want

This is empowering because you keep everything for the OS and Emacs, so excited to learn about this.

With this in mind, I hope that Emacs never throws away the Meta key!

11 thoughts on “Every Emacser Can Use Hyper on Every USB HID Keyboard”

  1. “The work now is to set up a keyboard that has the modifier keys appear in this layout twice on a single keyboard. ”
    Do you know how to do this on Linux (preferable in a way that affects VTs as X11)?
    Thanks, gregor

    1. I don’t. I haven’t tried yet.
      I’m banking everything on the LEFT_CONTROL and RIGHT_CONTROL modifiers being first-class citizens on every operating system. Since it works on OS X, I’m assuming that it will work fine on Windows and Linux, too.
      Please report back your findings.

    2. For X, you can use xmodmap and xkeycaps to remap modifier keys. It can be confusing, but google around and you’ll find some info. Arch’s wiki has some good info, and there are posts on StackExchange, etc. This won’t affect VTs though. That’s probably possible, but it gets really arcane and confusing…

  2. Thanks for this post. You might clarify that this only affects Emacs. As the title mentions USB HID, it seems to imply that it’s remapping keys at an OS or X server level, which is not the case.
    BTW, I hate to be negative, but I’m not digging this theme. There’s an enormous amount of whitespace, especially vertical whitespace (e.g. there’s over 200 pixels of vertical padding in the header), which makes me have to scroll a lot more than should be necessary. Vertical space is the most valuable with these wide-screen monitors, and unnecessary padding and margins are wasteful.
    Also, the thick black border around the entire page is annoying. I feel like my web browser is wearing blinders, and it blocks my view of text at the top and bottom of the screen. When I inspect the CSS and disable it I can see text at the edges of the screen that was covered up before.
    Combine that with the 1.75 line height, and there’s not much article text actually visible on each screen. Makes for a frustrating reading experience.

  3. By the way, I find your anti-adblock banner very off-putting, and borderline irresponsible of you. Ad networks are a primary route by which computers are infected with malware. Even mainstream ad networks on top-100 web sites have carried malware and infected users’ systems. This is a documented fact. The only responsible recommendation to all web users is to use ad-blocking software on every device for their own safety.
    We’re just talking about a blog here. Emacs and the Emacs community have given us all so much, isn’t it enough to just give back, without having to make a dime on the side?

    1. 1) Writing content and hosting still consume time and money.
      2) Do offer micro-payment options to visitors with ad-blocker on for ads free experience.
      webpass.io should be ideal.
      3) After implementing webpass.io. Ad blockers that still insist on getting free lunch should be directed to blockadblock.com
      3) Keep the banner and theme on. You are the webmaster and should have the final word.

      1. // Writing content and hosting still consume time and money.
        Yes, and? I spend time contributing back to the Emacs community in the form of code, support on groups and mailing lists, reaching out to new and potential users, reporting bugs, writing how-to guides, etc. I don’t ask for anything in return, because I’ve already received more than I could ever give.
        // Do offer micro-payment options to visitors with ad-blocker on for ads free experience.
        Do you think that will bring in a noticeable amount on a blog for Emacs users? What about all the other Emacs blogs? Imagine if irreal.org, endlessparentheses, (or emacs, Sacha Chua, etc, all asked visitors to pay for their posts. Is everyone going to make micropayments for every post they read on Planet Emacsen? Would that be a good way to run a community?
        // After implementing webpass.io. Ad blockers that still insist on getting free lunch should be directed to blockadblock.com
        1. That would be one of the most unfriendly, anti-community stances one could take, and I would say borderline unethical, considering how much the FSF, Emacs developers, and Emacs community give freely.
        2. You need to pay more attention to what’s going on. e.g. http://arstechnica.com/security/2016/03/big-name-sites-hit-by-rash-of-malicious-ads-spreading-crypto-ransomware/
        “Mainstream websites, including those published by The New York Times, the BBC, MSN, and AOL, are falling victim to a new rash of malicious ads that attempt to surreptitiously install crypto ransomware and other malware on the computers of unsuspecting visitors, security firms warned. The tainted ads may have exposed tens of thousands of people over the past 24 hours alone”
        The bottom line is that it is not safe to browse the Internet without an ad blocker, and it’s irresponsible to discourage others from using one.
        // Keep the banner and theme on. You are the webmaster and should have the final word.
        Of course, it’s his site, and he should do what he wants–including taking feedback line mine into account to make the site more readable for others, if he so chooses.
        There’s no need to thoughtlessly argue with everything I said. 😐

        1. My apologies to Grant. While what I said may have merit, the comments section of one of his blog posts is not the place to have an argument. My feedback was intended to be helpful to him and his efforts here, and thereby to the community. I’ll leave it to him to take it or leave it as he sees fit. Thanks for sharing your insights here, Grant.

  4. Personally (on Ubuntu) I use xkb (via ~/.config/xkb/symbols/local) with
    – caps lock as control left
    – control right as hyper
    – control left as super
    – alt as meta
    I’ll try your approach soon, thanks for sharing!

Leave a Reply to Ng Swee Meng Cancel reply

Your email address will not be published. Required fields are marked *