Hacker News new | past | comments | ask | show | jobs | submit login
Hacking Your Keyboard (kaush.co)
115 points by sorcercode on Dec 27, 2019 | hide | past | favorite | 85 comments



Good read!

If folks are interested in getting deeper into keyboard hacking I highly recommend looking into a board that supports [QMK](https://qmk.fm/), which is a very hackable set firmware that works across a bunch of boards.


I've switched to QMK-powered keyboards and plan to stick with them. My big feature was being able to program shortcuts that I like for Chrome OS that Chrome OS doesn't allow customizing natively. Using the layer system I have "Chrome" layer and "Gnome" layer so I can use the same shortcuts on both Linux and Chrome OS. I just toggle on the right compatibility layer once at the beginning of the session.


I've recently gone off the deep end with QMK customization. I found a project [1] which allows you to send data from a host program to the keyboard controller. In [1]'s case it's used to power a secondary display on the keyboard with information like system stats and weather and stuff.

But I've been experimenting with using it for more integration with the host system. Imagine instead of having to toggle the layer yourself, you could have a small script running on the host system which could tell your keyboard the currently focused application, and your keyboard could switch layers automatically.

In my situation, I want a spare ortholinear keyboard to be used as a macro pad of sorts, but rather than just pressing a key combination I want to be able to run full commands (I have a button that opens HN in a new browser tab, one that opens a new terminal to my home directory, one that will open whatever I currently have highlighted in https://devdocs.io in a new tab, that kind of stuff).

I've also been working with trying to tie in things like the host machine's volume level to display on the keyboard display, and I tend to switch my keyboard between a windows and mac system, so I want to see if I can get it to auto-detect the OS and switch various keys around so I have a consistent experience without having to toggle anything myself.

There's so many options you can do when you open up true 2-way communication with a keyboard!

[1] https://github.com/BlankSourceCode/qmk-hid-display


appreciate it. I actually started out with QMK on my Tada68 to emulate a lot of this. I’ve found karabiner is a tad bit easier for cross keyboard compatibility (not to mention I bricked my Tada atleast twice attempting it ).

But QMK is definitely awesome cause no need of installing software. Just plug your keyboard anywhere and you’re off to the races.


I second this, use both QMK on my customized 40%-ish keyboards and Karabiner on Macbooks, with similar configuration


QMK is awesome. I built an Arduino box running QMK to sit between my old model M and the computer to give me a lot of flexibility.


QMK is great — I’ve been using a ‘SpaceFN’ layout on all my 60% keyboards for a few years now and love it.


Karabiner is great, but my daily driver is an Ergodox EZ, and it's truly the best. I can edit nearly everything in the web configurator gui, but if I wanted to get crazy, the gui can export the QMK source code and I could compile myself.

The thing that my workflow really needs now is a way to organize/focus specific windows (e.g. a particular IDE window or browser). like I want to be able to assign (on the fly) hotkeys like Alt-1 Alt-2 etc to specific windows.

This is Ubuntu 18 though if such a thing is easier on Mac I could make that my main dev environment (I'm thinking of switching soon anyways once I port my workflow)


For all the pains it introduces because everything Just Stops Working™, I find the i3 window manager to be fantastic for my windowing workflow.

Once you have decided what goes into each workspace and have a bit of muscle memory for the tiling, switching is instant and organizing is trivial. Never drag a window again!

These blog posts helped a lot in configuring some basic stuff (that IMO really should be available out of the box; I get that i3 is supposed to be light and customizable but it feels really user-hostile on a new install):

https://feeding.cloud.geek.nz/posts/creating-a-modern-tiling...

https://cravencode.com/post/essentials/enable-tap-to-click-i...


Yeah I've seen i3 and it looks cool but does it work with regular graphical X window applications? It seems like it's mostly text based though I have seen images in panes.


I switched to i3 about 2 months ago. I had some false starts with tiling window managers before but i3 just clicked. It’s very easy to configure.

I have a mix of 10 plus terminals, chrome, sublime text, slack and wireshark spread across multiple workspaces in various combinations and it’s brilliant. Some applications work better non-tiled, floating on top of the tiles and this can be configured. I have done that with wireshark.


Yup, it works with everything, not text-based.


BetterTouchTool can do what you're looking for, although it might be easier to do with Keyboard Maestro (I haven't used it). Also, you might want to checkout Contexts, which is a superb highly-configurable replacement for Spotlight.


Oo, this looks excellent! Definitely want to try magic mouse at some point, and this seems like a great ajunct for that.


So in combination with Keyboard Maestro (the other piece of software I mention in my post) you can pretty easily wire something like what you ask, on the Mac.

Keyboard Maestro is truly one of the best productivity software for the Mac.


This article begins by explaining that karabiner (software for macs) lets you remap caps lock to escape.

Which is true.

But very misleading: That is a feature the OS itself supports, out of the box: System Preferences, Keyboard, Modifier Keys... – and voila, here you can pick 'escape' in the dropdown next to 'caps lock key'.

And speaking of that option, go do that right now. Even if you don't have a touchbar :)


What MacOS can’t do natively, though - at least, last I checked - is allow caps lock to function as escape when tapped but ctrl when held. Karabiner does this and it’s seriously convenient.


If I can entice non-Karabiner users further, if you do this mod you can also configure Caps Lock to be enabled when you press both Shift keys at the same time. It's a super fun combo to hit.


Is there a way to achieve this on Windows? This sounds very convenient.

I used Randy Rants SharpKeys to remap CapsLock to Esc, but I don't think the double mapping is supported.


I have used TouchKeys on Windows, which doesn't do exactly what you ask for, but is also pretty nice: it makes Space into a modifier key, and you can configure the combinations. E.g. Space+J could be cursor down, or Space+G could be escape. Tapping Space itself just produces a space. But it does mean that you lose the key repeat functionality of the space bar. So I used Space+S to produce space, and that works well with key repeat.


I use AHK to do this for Windows. It's a lifesaver, but it is not as reliable and it is very finicky -- the capslock to ctrl/escape usually works but sometimes it doesn't. AHK sometimes run into problem with Remote Desktop and Synergy.


Yes, I was really hoping to get something other that AHK. SharpKeys is much more stable to the point of where it pretty much "just works". It doesn't need a daemon running in the background.


Autohotkey supports this on Windows


autohotkey.

Do the same for enter, so that Ctrl-L is not too painful


That's not completely true. Karabiner does something MacOS cannot do, which is a momentary switch functionality. For example, I use it so that tapping capslock will activate ESC but holding it down with another key will activate CTRL instead. It's such as cool feature that I can no longer use a keyboard without this functionality.

I can also do this using Hammerspoon, although I prefer doing it via keyboard that supports it (ie QMK firmware-based keyboard) so that I can use it on Windows / Linux as well.


Misleading is a tad bit extreme :).

FWIW: I did mention it in a first draft but removed it cause it seemed like fluff.

> You can do this pretty easily with Karabiner but it barely scratches the surface of Karabiner’s true power.

Karabiner is far far more powerful than just basic key mappings.

Also the linked blog post at the bottom mentions the exact point you make (viz if all you need is a caps lock to escape mapping, use the built in features on the Mac)


Don't know how it compares feature-wise to Karabiner/Goku, but on Windows, you can use AutoHotkey[0] to do all kinds of global input remapping, macros, etc. Someone even wrote a clone of DWM (tiling window manager) in AutoHotkey![1].

Personally, I use it mostly to remap CTRL to Caps Lock, but once I wrote a global GUI popup for inserting reaction emojis into conversations on my work machine. AHK is really easy to work with.

--

[0] - https://www.autohotkey.com/

[1] - https://github.com/fuhsjr00/bug.n


Neat! A few folks have asked how I would emulate Keyboard Maestro on Windows. I used Autokey back in the days of my Windows usage. I’ll more confidently recommend it now


> I use it mostly to remap CTRL to Caps Lock

Heh, I had to do a similar thing with AHK when I vacuumed a key off my laptop.


On Windows 10, Win + . should bring up a global emoji toolbar that also supports searching by name.


Didn't know that, thanks! .


If you get deep enough into it, the path of least resistance slowly becomes using Emacs for everything. Macros at the keyboard level still have their uses, for all the things Emacs can't do. As emacs becomes more popular, expect that list to get smaller.

Of course, if you're not a coder, emacs will never replace your Excel / Photoshop / AutoCAD etc. custom macros.


Don't know about least resistance. I found that trying to replace emacs' utterly unergonomic bindings and other insane defaults without conflicting with all the plugins you kinda need to work around its dated built-in features is an uphill swim.


Spacemacs is the best answer to that problem I've seen yet, if you ever want to give it another shot.

https://www.spacemacs.org/


Does it offer a simple way to remove smart indenting in C mode and just copy the indentation from previous line?


Looks like a clusterfuck composed for you by other people is still a clusterfuck.

I gave it a couple hours and ran into a bunch of issues just by using spacemacs master and enabling a few layers.

For example, semantic seems to be pretty broken and unmaintained, and only googling around is how you find out. Yet other layers' documentation kinda (not so) subtly nudge you towards installing broken crap like this, without telling you that it's broken. https://www.reddit.com/r/emacs/comments/5yxxrl/what_is_that_...

Enabling version-control layer breaks a bunch of magit functionality, including basics such as commit. Don't enable that broken layer, I guess? Funny, apparently fixed in develop and still broken in master 9 months later.. https://github.com/syl20bnr/spacemacs/issues/12056

git blame is broken: https://github.com/magit/magit/issues/3883

Does anyone actually use this stuff?!

And I still haven't found a way out of silly autoindentation so I'm forced to waste time trying to configure features that I did not want in the first place :(

Stuff like ^N and ^P aren't quite working like in vim either..

This kind of stuff is pretty much exactly what pushed me away from emacs the second time I tried to use it for real. A tangled mess of a bazillion packages that interfere with each other and come in various degrees of unmaintained, broken, or obviously broken is not a good foundation for building good software.


Did you try master-branch? For whatever reason development-culture at spacemacs is very broken and most work happens in develop-branch which rarely is merged into master. I think at the moment they are around 1-2 years behind on master and only add critical patches AFAIK. For this reason most people use develop-branch and avoid master-branch.

I think the bigger problem with spacemacs is that they have a vision too big, and emacs just does not offer tools and culture to support it. So they are constantly working against the hill.


Emacs had its chance. It lost to Vim, and then VSCode ate what remained of its lunch.


VScode ate everyone's launch, even Jetbrains must be cursing Microsoft every day.

That said, as emacs user, I see vim users switching to emacs/evil by the day.


I switched recently from Vim to Evil after more than two decades, mainly because I prefer proportional fonts these days, and also because of Magit (I’m really annoyed by “free” Git GUIs going the subscription route after building up a big enough user base).

The road has been bumpy so far, but I’m slowly getting used to Emacs’ idiosyncrasies. The journey has been worth it.


The sound of my eyes rolling ever harder at tech faddism.


If eye movement makes an audible sound, you might want to get those checked out :)


This isn't keyboard hacking so much as desktop environment hacking


If you like Karabiner-Elements, please support the developer: https://pqrs.org/osx/karabiner/pricing.html

Takayama Fumihiko has been keeping the kernel extension up to date for many, many years now. Apple is putting up road limits here and there, to provide security, and he jumps through all of their hoops.

Every year I upgrade to the latest version of macOS, Karabiner-Elements is ready for the new OS. And every time I donate.


IIUC, most people here are talking about hacking the keyboard itself. Another option is to hack the mapping of key presses to emitted codes, at the OS level. Windows allows you to do this using the SetWindowsHookEx() process. I set this up to do my mapping back in the days of Win3.1, and it's worked more or less unchanged since then.

My mapping resembles the one described in the article, e.g. ^K --> <up arrow>. (And ^U maps to a series of 8 up arrows, for faster movement.) But I have two states, one in which a ^K simply moves the cursor one line up, and one in which it selects while doing that (and the same for the other keys that do <left>, <right>, <down>, <pgup> etc.). I toggle between the two states using ^Q (and ^C, ^X and a few other keys go to the non-selecting state from the selecting state).

The last time I looked, other keyboard mapping techniques I've seen don't have this 2-state possibility, or even in some cases to output a sequence of codes.

One advantage of doing the mapping this way is that it's hardware-independent: I can use it not only on my home desktop, but also on laptops, my office computer, etc., anywhere I can run a tiny .exe + .dll.


I use karabiner to map capslock to control when held down, and to escape when just pressed. It's really handy for vim.


I like mapping my right cmd key to ctrl, and doing the same thing as you for caps lock but tapping yields an escape.


I usually buy laptops with Japanese keyboard, which gives you three extra keys and use Karabiner to repurpose them.


Absolutely love the idea, will do the same thing in the future! Since I started remapping many keys with Karabiner, I became annoyed that the spacebar is so huge and wished that they had added more keys instead. The Japanese keyboard looks fantastic for my purposes. Thank you very much!


Or you know, buy a gaming keyboard that has a ton of extra macro keys and besides those, the dedicated software can do way more then just the article says. Personally I love my gaming Razor keyboard/mouse, it allows me to do a lot more stuff then what's in article about Karabiner.


But now don’t you need to run Razer’s proprietary software? Things like QMK are open-source


Perhaps, but Razer software is free and on top of that I'm lazy and accustomed with it already. I know it's a sin for HN crowd, so forgive me father :).


If you'll read the license agreement you'll know it's far from free.


It's free for me. Same way iOS is free for iPhone and MacOS is free for Macs. I thought that's implied since I already paid for the hardware, but here you have it now, more clearly


A Razer Naga MMO mouse [1] has 12 thumb buttons (and a couple of others which are rather hard to reach). They are perfect for cut, copy & paste, and other frequent macros / actions. The vendor software is crap, though, especially on a Mac. It often forgets or messes up bindings and macros and you have to reconfigure them. I really got annoyed after doing this a couple of times and switched to SteerMouse [2] which lets you do almost everything the Razer software does, but in a nice and straight forward GUI.

[1] https://www.razer.com/gaming-mice/razer-naga-trinity

[2] http://www.plentycom.jp/en/steermouse/download.php


No idea what are mine, they were a gift from a client as bonus for a project well done. And I got them in 2014. Just felt natural using them and the software as well and I just do my job with them on daily basis. No problems at all, not even a slight hiccup. Though my Mac programming is done in virtual machines, so Windows is still the software for keyboard in that scenario.


What are some examples of these macros ? I’d love to hear more ideas and tricks.


For me, with 10 macro keys on my keyboard and 4 on my mouse and combined with Razor profile on their software it means that depending on what I do I can:

1- On online RPG games like GuildWars1/2 I can press one macro key and a full chain of several keystrokes simulating skills with intended delays between them is send to the game. I don't even have all 14 macro keys programmed, most is 10 when I play monk (healer class).

2- For programming, depending on what I am in (Code view / Visual / SQL builder etc) I do use all 14 keys and combined with different profiles, I can type most used declaring prototypes / build a test form / write most common SQL queries - to the extent that I can press a few keys and the equivalent of several dozens of key presses are poured in, which allows me to be truly proficient.

Of course, all these are based on my experience and they piled up in years, but the end idea is the same - get a cross-platform IDE and you can create just as easy in Raspberry Pi as in Windows your applications.


Personnaly I use Hammerspoon as my main desktop environment hacking and added a few shortcuts with Karabiner.

By using the two of them, you can use any keyboard (native macbook pro or external) and manipulate your windows, setup pomodoro timer or launch/activate your favorite programs.

Feels great!


Yup, me too.

I've configured Hammerspoon with a bunch of functions that put my windows at 25%, 33%, 50%, 66% or 75% to the left or right. I couldn't find a window manager that can do both quarters and thirds, and now I'm in love with Hammerspoon.


Sweet! I’ve heard of Hammerspoon but Keyboard Maestro has been my poison for sometime. Offers every bit of programming functionality with a super easy UI.


May not be relevant to the article, but the 80% keyboard is what I want (I never use the numpad, but I use home/end/page up/page down a lot), but I can't find many choices on the market.


65% might work for you. I have a tada68, and it has arrow keys, page up/down and delete. Has the added benefit of getting rid of the function key row (but you can still use them using the fn key), the home and end keys are also pretty easy to access with the fn modifier.


Thank you. However, I do need Home/End keys, because I use Home/End, shift+Home/End, ctrl+Home/End, ctrl+shift+Home/End frequently.

I also like low-profile keys (effortless key pressing) like the ones on a laptop keyboard.

I found the 75% on this page could also be a good choice: https://blog.wooting.nl/the-ultimate-guide-to-keyboard-layou...

Edit:

Ha! I just found a 75% keyboard on Amazon: https://www.amazon.com/dp/B07M9PGMT9/

Another one: https://www.amazon.com/dp/B07JGQP89G/


This reminds me: I need to port my yuio keys to home/pg down/pg up/end + caps lock.


shift+Home/End, ctrl+Home/End, ctrl+shift+Home/End

What does this ones do?


Those are shortcuts on Windows

shift+Home/End: select from current cursor to the beginning / end of the line

ctrl+Home/End: jump to the beginning / end of the document

ctrl+shift+Home/End: select from current cursor to the beginning / end of the document


Those work as well with the function layer, and the function key doesn't make the combo harder on your hands but I can understand wanting dedicated keys for some stuff, this is why I went for a 65% instead of 60% in the first place


I think this is a clever 60/80% keyboard implementation: https://kinesis-ergo.com/shop/advantage2/ (have been using the advantage model since 2006)


I got the same keyboard this month and the only thing I regret is that I didn’t buy it already 9 years ago when I got a Das Keyboard instead (which is still an excellent and fully functioning keyboard, but it has just a regular, rather unergonomic layout compared to the Advantage).


Hmm - I think you'll have better luck searching for 'TKL' keyboards (Ten Key Less). They are extremely popular and a wide variety are available. For instance: Drop 'ctrl' ($200): https://drop.com/buy/drop-ctrl-mechanical-keyboard

GMMK offers a fullsize, TKL and 60% : https://www.pcgamingrace.com/products/gmmk-full-brown-switch

HTH and Happy New Year!


I rebuilt a Vortex Cypher as my daily driver. Internally its the same board as the Pok3r. But I get a nice split spacebar for an 'extra' key. Swapped out the switches, added LEDs, and painted the case trim.

Rebuild pix here: https://photos.app.goo.gl/33qzHsgjVStY75F58


I've really enjoyed my Anne Pro 2. It has software for Linux so you get tons of customizations out of the box graphically.


By reading this article I discovered the Anne Pro 2. Seems very similar to the Pok3r keyboard.


The article sent me down a 60% rabbit hole for the past hour or so. Almost bought a Pok3r v2.


Vimium extension for browsers allows Vi-like movement and mouse-free navigation. Things you learn from sysadmins ;)


Or Vimari, the Safari port.

https://github.com/televator-apps/vimari


FYI, the basic features mentioned are available in plain macOS.

Remap caps lock to control in system preferences.

Then ctrl-p: up, ctrl-n: down, ctrl-b: left, ctrl-f: right

ctrl-d for forwards delete, also ctrl-a/e for home/end, ctrl-u/k for delete line forwards/backwards

Works in almost all text entry boxes with no config or other software.


Thanks for mentioning this! A lot of people don't know that macOS has a lot of Emacs keybindings as defaults. You can even customize it by putting a DefaultKeyBinding.dict file in ~/Library/KeyBindings/. The defaults are in `/System/Library/Frameworks/AppKit.framework/Resources/StandardKeyBinding.dict` to use as a reference, but you can also find lots of examples around GitHub and various blogs.

Documentation seems to be a bit sparse (maybe I'm just terrible at searching), but this should get anybody who is interested going:

https://developer.apple.com/library/archive/documentation/Co...

More helpful and practical documentation: http://xahlee.info/kbd/osx_keybinding.html


Vim users, why are you all remapping your escape key? <C-[> is already a map. I know it is two buttons, but they are with different hands and you don't have to stretch or lift your palms to reach them.

Benefits over remapping: you can open a random vim terminal and it still works.


jj for the win


I always remap Caps Lock to Compose (built in functionality in Linux, WinCompose for Windows).

But what I want more than anything is to be able to modify the laptop keyboard firmware on my Surface Book 2 so that FnLock can never be turned off. Does anyone have any tips for this?


That is more a case of gui configuration

Here is a real keyboard hacker: https://spritesmods.com/?art=rapidisnake


I wonder how much latency that adds up.


I don't know about the latency that's intentionally inserted. But I'm using Karabiner for the past years, and I haven't noticed any. It probably helps that it's implemented as a kernel module.




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

Search: