2016-04-11 Atreus, Windows, and Emacs

So, I want to define an interesting layout for my Atreus keyboard. On OSX, I used Ukulele to do it. On Windows, I’m using Microsoft Keyboard Layout Creator 1.4.

+---+---+---+---+---+          +---+---+---+---+---+
|Q  |W <|E >|R (|T )|          |Z {|U }|I [|O ]|P €|
|q 6|w 7|e 8|r 9|t 0|          |z 1|u 2|i 3|o 4|p 5|
+---+---+---+---+---+          +---+---+---+---+---+
|A  |S  |D  |F  |G $|          |H ^|J &|K  |L ×|: ||
|a  |s  |d  |f  |g @|          |h =|j +|k -|l *|. …|
+---+---+---+---+---+          +---+---+---+---+---+
|Y  |X  |C  |V  |B %|          |N ~|M 」|_ —|´ ’|` ”|
|y  |x  |c  |v  |b #|          |n ¨|m 「|- –|' ‘|" “|
+---+---+---+---+---+---+  +---+---+---+---+---+---+
|   |   |   |   |DEL|   |  |   |   |   |; »|? \|   |
+---+---+---+---+---+---+  +---+---+---+---+---+---+

When I switch to my new layout, I still have some problems with it:

  (setq w32-lwindow-modifier 'meta ; windows is meta
	w32-pass-lwindow-to-system nil
	w32-rwindow-modifier 'meta ; windows is meta
	w32-pass-rwindow-to-system nil
	w32-recognize-altgr t
	w32-pass-alt-to-system t   ; alt is alt
	w32-alt-is-meta nil)
   ;; w32-phantom-key-code??

Perhaps it would be easier if I changed that key to Meta using the keyboard’s firmware and it would work correctly on both OSX and Windows?

And I’m still not sure how to change bindings for simple keys using the Alt key. Perhaps I need a different utility? A good Microsoft Keyboard Layout Creator alternative...

I guess the alternative would be to use Fn together with these extra keys. But then I can’t bind them to something interesting like “...” because in order to that, I would need access to these keys on Microsoft Keyboard Layout Creator, which I do not.



Well, right now I am back at the US standard layout. Perhaps I can do everything else using dead keys? Might be simpler than all this extra fiddling. I’m hating everything about it already. I’m spending too much time worrying about programming the keyboard but as it stands, I won’t ever get a system, where I can just carry my keyboard to another desk and start typing. It just requires too many features by the operating system and the various solutions are incompatible anyway.

Current mood: frustrated.

– Alex Schroeder 2016-04-11 19:40 UTC

I want a keyboard with Super and Hyper that works on both Windows and OS X. I still don’t have a precise answer but this seems good ot know: https://ergodox-ez.com/pages/our-firmware They define a “Hyper” and a “Meh” key. I pre(re)invented that approach using AutoHotKey and duplicated bindings, and decided it was a poor use of my time. If it is built into your keyboard, however, might be nice. I still want to answer “Why can’t we have a GUI key that is separate from the SUPER key?”. Seems possible, and I would like it a lot because we do need a GUI key, too.

Grant Rettke 2016-04-11 21:00 UTC

Oh! Right. Whenever I have to use another computer I usually connect to it with my laptop using, er, Synergy. Synergy is great, but… it is an interesting case of a GPL-ed free software getting crippled so that they can sell it…

So I guess that it is just waiting for a fork to appear. Meanwhile you can get a bit older version from here: http://synergy-project.org/download/free/ (or compile it yourself, though in case of crippled software it is usually not as simple. But who knows). Same version is debian repos (so I haven’t really noticed).

It’s kinda interesting that instead of starting some crowd funding they decided to turn the software into something that I don’t really want to recommend to anybody just because of their “monetization“ shit. Awful.

But! It allows me to use my laptop (and therefore my own configuration) for any computer I connect with. So, perhaps that’s an option?

– AlexDaniel 2016-04-11 21:09 UTC

Grant, I saw you blog post just now and I’m reminded of what I discovered when I looked at the keycodes available in the firmware:

/* Modifiers */
KC_LCTRL            KC_LCTRL        E0 Keyboard LeftControl
KC_LSHIFT           KC_LSFT         E1 Keyboard LeftShift
KC_LALT                             E2 Keyboard LeftAlt
KC_LGUI                             E3 Keyboard Left GUI(Windows/Apple/Meta key)
KC_RCTRL            KC_RCTL         E4 Keyboard RightControl
KC_RSHIFT           KC_RSFT         E5 Keyboard RightShift
KC_RALT                             E6 Keyboard RightAlt
KC_RGUI                             E7 Keyboard Right GUI(Windows/Apple/Meta key)

No KC_RHYPER or KC_LHYPER! No KC_RSUPER or KC_LSUPER! The comment points to another document: “Keycodes are defined in ’common/keycode.h’. Range of 00-A4 and E0-E7 are identical with HID Usage.” In the header file mentioned, it says: “Virtual keycodes are defined out of above range to support special actions. Keycodes based on HID Usage Keyboard/Keypad Page(0x07) plus special codes.” As the URLs are no longer pointing anywhere, here’s what I think this refers to the USB HID Usage Tables on page 53ff.

I think this means that there cannot be a USB keyboard with a Hyper key. I think what you therefore need to do is make a key that sends multiple modifiers at the same time, ie. mapping Caps Lock to Shift+Ctrl+Option+Command or something like that. The solution for a Mac involves Karabiner and Seil for OSX. Like the ideas I had myself, this setup is hardly portable to other computers, unfortunately. Apparently, you can do something similar using AutoHotKey.

Xah Lee has collected some info the topic: Emacs: How to Define Super Hyper Keys, AutoHotkey Tutorial.

– Alex Schroeder 2016-04-12 07:31 UTC

How is it going?

– AlexDaniel 2016-04-24 06:23 UTC

I’ve been using the Atreus with my la-top at home, using the US standard layout. I use the Latin Prefix input method to write German. This also meant that I no longer require Alt/Option as AltGr and so I use Alt as Hyper again, but have no keys bound using Hyper. Boooo.

– Alex Schroeder 2016-04-24 16:37 UTC

Alex can you show your keyboard layout (like you did up above) showing your current mappings?

I’m confused by your post: did you get what you wanted when you re-configured left and right GUI?

I guessed that you would place LEFT_ALT and where you wanted it to be META, and RIGHT_ALT wherever you wanted it to be ALT. It would look confusing because the keycaps would have ALT all over, but for Emacs, it would be exactly what you want. Right? I think that I might have understood something wrong here.

Grant Rettke 2016-05-14 19:00 UTC

The end result of all the above is that I am using the default firmware for the keyboard. This means that I’m short one modifier on the Mac: I need the command key to run OSX commands; I need Alt to enter German characters; there’s no key for Meta. Under OSX, the usual solution is to use the Command key as Meta, of possible. So, in order to get that, I would have to swap Alt and Super on the Atreus firmware, assuming I wanted to use my right thumb for Meta. I guess I do?

But the main thing that I wanted to talk about when I replied to your message above was this: All USB keyboards will be limited by the USB standard for keyboards. You can find the necessary information in USB HID Usage Tables on page 53ff. There, on page 59, you’ll note that there is no way a USB keyboard will be able to send the Hyper modifier: There is only Control, Shift, Alt, and “GUI” (Super) for left and right. In order to get Hyper in addition to those present, you’ll have to map your key to something like F13 in the firmware and then you’ll have tell your operating system that F13 should act as Hyper. I think I could figure this out for a GNULinux environment, but I’m unwilling to spend the time necessary to figure it out for OSX and Windows.

And so I determined that the two easiest options right now are the following:

  1. don’t use the Atreus keyboard
  2. if I use the Atreus keyboard, use the default firmware, switch to a US layout in OSX, and use something like the following for Emacs:
(defun atreus-layout ()
  "If using the Atreus on a Mac, we want the Alt key to be Meta."
  (setq mac-option-modifier 'meta)
  (setq default-input-method 'german-prefix)
  (set-input-method 'german-prefix))

But, I don’t like any of it and I’m unhappy with the current state of affairs. The sad part is that I don’t see an easy way forward. Maybe during my summer break.

– Alex Schroeder 2016-05-15 00:19 UTC

Gotcha. I am sorry that it isn’t going as planned. Here is what I tried https://www.wisdomandwonder.com/article/10146/every-emacser-can-use-hyper-on-every-usb-hid-keyboard . This is how I came up with “using hyper in Emacs” given that there are only 8 modifiers (left or right, shift control alt gui) in the USB HID spec and there is no xmodmap option for Windows. It seemed happy on my Mac and Windows box; I tried the following on both boxes. The important thing for me was that Windows and OS X had their important modifiers: ALT and GUI so I could switch window focus and use OS actions like inserting special characters and opening the Run dialog in Windows. I read your post like it would work the same way for the Altreus. The way I read your post I figured that you MIGHT modify your default keyboard https://atreus.technomancy.us/ by changing the default layout (by names there): super as RIGHT_GUI (aka option), ctrl as RIGHT_CONTROL, alt as RIGHT_ALT (aka command), and then moving - ’ , to the Fn layer, so you can redefine - as LEFT_CONTROL (Meta), ’ as LEFT_ALT (Super), and , as LEFT_GUI (Hyper) only for Emacs using the mac-right--modifier and mac-left--modifier settings. I didn’t want the CONTROL-ALT-GUI-SHIFT style hyper key since I only want these modifiers in Emacs. I tried that approach and didn’t like it only because I only wanted the modifiers inside of Emacs. If things work like I am seeing them work on the Mac, then this will work on your Altreus. Otherwise I am wrong and need to revise my post ASAP.

Grant Rettke 2016-05-15 09:31 UTC

Hah, excellent! I’ll give this a try. :)

– Alex Schroeder 2016-05-15 10:44 UTC

Alex, how did it go?

Grant Rettke 2016-07-15 10:58 UTC

My summer break just started at the beginning of the month and I still haven’t used my Atreus keyboard for anything. :(

– Alex Schroeder 2016-07-15 20:19 UTC

First, have a great break. Do what you enjoy!

If you happen to enjoy configuring your Emacs keyboard then know that we are all dying to hear the results!

Grant Rettke 2016-07-18 18:31 UTC

Good afternoon Alex. Have you tried the keyboard with Emacs yet?

Grant Rettke 2016-12-03 21:13 UTC

Right now I’m trying to get used to the US keyboard layout again. This requires some changes in my motor patterns. The Atreus keyboard with standard config is here, next to the laptop, but I rarely use it.

– Alex Schroeder 2016-12-03 23:35 UTC

Good afternoon Alex. Have you tried the keyboard with Emacs yet?

Grant 2017-06-03 08:10 UTC

I ended up hardly ever using it.

– Alex Schroeder 2017-06-03 14:19 UTC

Alex: thank you for the update. Have a great one.

Grant 2017-06-04 23:57 UTC

Looking over this exchange again, I noticed that I have omitted something. Up above I said: “The end result of all the above is that I am using the default firmware for the keyboard. This means that I’m short one modifier on the Mac: I need the command key to run OSX commands; I need Alt to enter German characters; there’s no key for Meta.” I also said that within Emacs I had found a solution: switching to the german-prefix input-method. But as it turns out, there’s an even better solution: switch to the international US keyboard layout on both Mac and Windows. It works like the prefix input-methods within Emacs. Quote, double-quote, and caret/circumflex will create appropriate accents. This is great. And with that, I had longer stretches of using the Atreus keyboard.

I also noted, however, that the keyboard was easier to use when I was writing long stretches of text. When I’m programming, there’s a lot of extra keys I use, cursor movements and all that, and that all needs retraining.

– Alex Schroeder 2017-06-07 08:48 UTC

Excellent to hear and thanks for the update!

Grant 2017-06-12 01:14 UTC

Please make sure you contribute only your own work, or work licensed under the GNU Free Documentation License. Note: in order to facilitate peer review and fight vandalism, we will store your IP number for a number of days. See Privacy Policy for more information. See Info for text formatting rules. You can edit the comment page if you need to fix typos. You can subscribe to new comments by email without leaving a comment.

To save this page you must answer this question:

Please say HELLO.