
Hacking Your Keyboard - sorcercode
https://blog.kaush.co/2019/12/25/hacking-your-keyboard/
======
davefp
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/](https://qmk.fm/)), which is a very hackable set
firmware that works across a bunch of boards.

~~~
markstos
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.

~~~
Klathmon
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](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](https://github.com/BlankSourceCode/qmk-hid-display)

------
kortex
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)

~~~
pedrovhb
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://feeding.cloud.geek.nz/posts/creating-a-modern-tiling-
desktop-environment-using-i3/)

[https://cravencode.com/post/essentials/enable-tap-to-
click-i...](https://cravencode.com/post/essentials/enable-tap-to-click-
in-i3wm/)

~~~
kortex
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.

~~~
lttlrck
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.

------
rzwitserloot
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 :)

~~~
darkteflon
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.

~~~
ahakki
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.

~~~
otterpro
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.

~~~
ahakki
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.

------
TeMPOraL
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/](https://www.autohotkey.com/)

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

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

~~~
TeMPOraL
Didn't know that, thanks! .

------
vinceguidry
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.

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

~~~
Scarbutt
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.

~~~
chiefsucker
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.

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

------
cerberusss
If you like Karabiner-Elements, please support the developer:
[https://pqrs.org/osx/karabiner/pricing.html](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.

------
mcswell
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.

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

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

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

~~~
aptidude187
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!

------
unnouinceput
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.

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

~~~
unnouinceput
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 :).

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

~~~
unnouinceput
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

------
geniium
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!

~~~
cerberusss
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.

------
datashow
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.

~~~
Kwantuum
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.

~~~
datashow
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...](https://blog.wooting.nl/the-ultimate-guide-to-keyboard-layouts-and-
form-factors/)

Edit:

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

Another one:
[https://www.amazon.com/dp/B07JGQP89G/](https://www.amazon.com/dp/B07JGQP89G/)

~~~
Scarbutt
_shift+Home /End, ctrl+Home/End, ctrl+shift+Home/End_

What does this ones do?

~~~
datashow
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

~~~
Kwantuum
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

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

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

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

~~~
chiefsucker
Or Vimari, the Safari port.

[https://github.com/televator-apps/vimari](https://github.com/televator-
apps/vimari)

------
fnoof
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.

~~~
filchermcurr
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...](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/EventOverview/TextDefaultsBindings/TextDefaultsBindings.html)

More helpful and practical documentation:
[http://xahlee.info/kbd/osx_keybinding.html](http://xahlee.info/kbd/osx_keybinding.html)

------
godelski
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.

~~~
kalyantm
jj for the win

------
MiddleEndian
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?

------
benibela
That is more a case of gui configuration

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

------
bbmario
I wonder how much latency that adds up.

~~~
cerberusss
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.

