Switching to en-US keyboard layout for development
Tags: productivity, tutorial, qwerty, keyboard
Published: 2021-03-13 16:51:17

Languages: [🇪🇸] [Español](https://dev.to/equimancho/migrando-a-teclado-en-ingles-para-desarrollo-a91) - [🇺🇸] [English](https://dev.to/equiman/switching-to-en-us-keyboard-layout-for-development-4b5a)

---

When I started to work I remember a senior developer advise: 

> Install and use everything in English. The whole developer world is focused on English first. Your life will be easier because when you found an error only need to copy it and paste it on a search engine, sure you will find that this question was already made. 

```javascript
catch(error){
   console.log(`https://stackoverflow.com/search?q={error.message}`)
}
```

So, the first time that I see this joke, his words got sense. 😎

---

Last few days, I started to see a lot of non-American developers (Latam, Spain, France, Germany, India, and Hungary) that recommend moving to use the **en-US** keyboard layout.

And again his advise came before my very eyes: 

> If we are using the software in English and write code in English. Why not use hardware too?

Programming languages, IDEs, and Code Editors were designed and developed to use in English first, and if I'm not wrong I'm very sure were written with an English keyboard.

![enUS](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pvuwsepv7783ghlsev7p.png)

When these people were changed to this layout says that feel more natural, comfortable, and productive. I think this is due because symbols and keyboard shortcuts are made to use with **en-US** keyboard layout. I don't know if I'm right or not, but it has a lot of sense to me.

Switching to **en-US** keyboard also comes with an added benefit: never will be easy to buy a mechanical keyboard. For me, it's very hard or even impossible to found a good keyboard with **es-LATAM** layout.

> Sound good, but... where are the accents? and the `Ñ` letter?

---

# Quick Solution

Everyone who needs any sort of diacritic or accent would ask the same question because the use **en-US** layout makes it unsuitable unless the **US International** layout is used.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o0wo1zc9j5u60kmevtr4.png)

This layout changes the `` ` `` (grave), `~` (tilde), `^` (circumflex), `"` (double quote, to make diaeresis), and `'` (apostrophe, to make acute accent) keys into **dead keys** for producing accented characters: thus for example `'` (release) `a` will produce `á`. The US International layout also uses the AltGr (Alt+Ctrl) as a modifier to enter special characters.

But this International layout has a critical downside (at least on Windows) for programming due to **dead keys**. We are going to lose speed because need to press two keys instead of one: the diacritic or accent followed by an ending character (space, tab or enter) to produce it.

> So what can we do?

Just roll back to **en-US** layout and create a customs script for diacritic or accent. 

---

# Custom Solution

> **TLDR** if you are not interested in the dirty aspects can jump directly to the [Summary](https://dev.to/equiman/switching-to-en-us-keyboard-layout-for-development-4b5a#summary)

I will **detail** the process to create a script to use with [AutoHotKey](https://www.autohotkey.com/) for Spanish accents (my native language) and you can use it as an example in case you need to create your own.

- First, you need to recognize the accents `áéíóúñ` letters and symbols `¡¿` that you want to remap and search his correspondent decimal value on the [ASCII table](https://www.ascii-code.com/).

|Char|Dec|Char|Dec|
|---|---|---|---|
|á|0225|Á|0193|
|é|0233|É|0201|
|í|0237|Í|0205|
|ó|0243|Ó|0211|
|ú|0250|Ú|0218|
|ñ|0241|Ñ|0209|
|¿|0191|?|63|
|¡|0161|!|33|

- Next, we need to remap each key with desired destinations following this format `OriginKey::DestinationKey` taken attention of his [modifiers keys](https://www.autohotkey.com/docs/KeyList.htm#modifier).

|Char|Modifier|
|---|---|
|^|<kbd>Ctrl</kbd>|
|!|<kbd>Alt</kbd>|
|+|<kbd>Shift</kbd>|
|#|<kbd>Win</kbd>|
|<|Left|
|>|Right|

- Create a script file called `en-US_accents.ahk` adding the remap configuration.

```cpp
!a::Send {Asc 0225}    ; Alt+a -> á
!+a::Send {Asc 0193}   ; Shift+Alt+a -> Á
!d::Send {Asc 0233}    ; Alt+e -> é
!+d::Send {Asc 0201}   ; Shift+Alt+e -> É
!g::Send {Asc 0237}    ; Alt+i -> í
!+g::Send {Asc 0205}   ; Shift+Alt+i -> Í
!s::Send {Asc 0243}    ; Alt+o -> ó
!+s::Send {Asc 0211}   ; Shift+Alt+o -> Ó
!f::Send {Asc 0250}    ; Alt+u -> ú
!+f::Send {Asc 0218}   ; Shift+Alt+u -> Ú
!l::Send {Asc 0241}    ; Alt+n -> ñ
!+l::Send {Asc 0209}   ; Shift+Alt+n -> Ñ
```

> It was easy!

Not too fast my friend. We recently defined the shortcut `Alt+Shift+A`, but for example, **VSCode also uses this same shortcut** to toggle comments.

We need to change the Left Alt as a modifier, updating all the `Alt+Shift+` maps to only works with `(Right)Alt+Shift+`. Just change `!+` modifiers with `>!+`.

Now you can still use the `(Left)Alt+Shift+a` on VScode and `(Right)Alt+Shift+a` to write the `Á` (with accent). It's up to you if you like to convert all Alt modifiers to (Right)Alt or only the combinations with conflicts.

```cpp
!a:: Send {Asc 0225}    ; Alt+a -> á
>!+a:: Send {Asc 0193}  ; Shift+(Right)Alt+a -> Á
!e:: Send {Asc 0233}    ; Alt+e -> é
>!+e:: Send {Asc 0201}  ; Shift+(Right)Alt+e -> É
!i:: Send {Asc 0237}    ; Alt+i -> í
>!+i:: Send {Asc 0205}  ; Shift+(RightAlt+i -> Í
!o:: Send {Asc 0243}    ; Alt+o -> ó
>!+o:: Send {Asc 0211}  ; Shift+(Right)Alt+o -> Ó
!u:: Send {Asc 0250}    ; Alt+u -> ú
>!+u:: Send {Asc 0218}  ; Shift+(Right)Alt+u -> Ú
!n:: Send {Asc 0241}    ; Alt+n -> ñ
>!+n:: Send {Asc 0209}  ; Shift+(Right)Alt+n -> Ñ
```

> Woohoo! Amazing!

Additionally in Spanish, the exclamation and question mark symbols need to be open at the beginning and close at the end.

```cpp
!/:: Send {Asc 0191}{Asc 63}{left 1}    ; Alt+/ -> ¿?
!1:: Send {Asc 0161}{Asc 33}{left 1}    ; Alt+1 -> ¡!
```

![accents](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yrambmp175octsbv55o8.gif)

The last two have another trick. It will create open and close symbols and with the `{left 1}` command move the cursor between them.

---

# Extra

If it's not enough. I have other cool optional tricks. 

If you already have a keyboard with a number pad at the right. Why not use the numbers row directly with symbols when Num Lock is active?

```cpp
#if GetKeyState("NumLock", "T")
    *1::!
    *2::@
    *3::#
    *4::$
    *5::Send `%
    *6::^
    *7::&
    *8::Send `*
    *9::(
    *0::)
    $+1::Send 1
    $+2::Send 2
    $+3::Send 3
    $+4::Send 4
    $+5::Send 5
    $+6::Send 6
    $+7::Send 7
    $+8::Send 8
    $+9::Send 9
    $+0::Send 0
#if
```

![numpad](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ielb5m23bvosj35gw570.gif)

> Those who use a Laptop or a TKL (Ten Key Less) keyboards can use `Insert` instead of `NumLock` or remove the if condition.

And how many times did you use the `Caps Lock` key? For me as developer results more useful to remap it as `Backspace` and have it directly on the home row.

```cpp
CapsLock::Backspace
!CapsLock::CapsLock
```

![caps](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vdj6gfodm0if3m5rxk29.gif)

But if sometimes you will need to use the `Caps Lock`, for example for writing SQL, can be enabled/disable with `Alt+CapsLock`

---

# Summary

Finally, we will have a compatible, fast, reliable, and useful **en-US** layout keyboard for development without leaving **Qwerty**.

![en-us](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jbrvg5qoaqs66p91jc7x.gif)

With a simple AutoHotkey script:

```cpp
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

; Modifiers
; ^ Ctrl
; ! Alt
; + Shift
; # Win
; < Left
; > Right

; Action
CapsLock::Backspace
!CapsLock::CapsLock     ; Alt+CapsLock -> Enable/Disable Caps Lock
PrintScreen::Send #+s

; Accents
!a:: Send {Asc 0225}    ; Alt+a -> á
>!+a:: Send {Asc 0193}  ; Shift+(Right)Alt+a -> Á
!e:: Send {Asc 0233}    ; Alt+e -> é
>!+e:: Send {Asc 0201}  ; Shift+(Right)Alt+e -> É
!i:: Send {Asc 0237}    ; Alt+i -> í
>!+i:: Send {Asc 0205}  ; Shift+(RightAlt+i -> Í
!o:: Send {Asc 0243}    ; Alt+o -> ó
>!+o:: Send {Asc 0211}  ; Shift+(Right)Alt+o -> Ó
!u:: Send {Asc 0250}    ; Alt+u -> ú
>!+u:: Send {Asc 0218}  ; Shift+(Right)Alt+u -> Ú
!n:: Send {Asc 0241}    ; Alt+n -> ñ
>!+n:: Send {Asc 0209}  ; Shift+(Right)Alt+n -> Ñ

; Symbols
!/:: Send {Asc 0191}{Asc 63}{left 1}    ; Alt+/ -> ¿?
!1:: Send {Asc 0161}{Asc 33}{left 1}    ; Alt+1 -> ¡!

; Swap Numbers Row
#if GetKeyState("NumLock", "T")
    *1::!
    *2::@
    *3::#
    *4::$
    *5::Send `%
    *6::^
    *7::&
    *8::Send `*
    *9::(
    *0::)
    $+1::Send 1
    $+2::Send 2
    $+3::Send 3
    $+4::Send 4
    $+5::Send 5
    $+6::Send 6
    $+7::Send 7
    $+8::Send 8
    $+9::Send 9
    $+0::Send 0
#if
```

I know there are a lot of keyboard layouts like Dvorak, Colemak, Workman, Norman, and so on. I've tested a pair of them and I convinced myself that there is no perfect layout to rule them all.

But with the changes I propose to introduce with AutoHotkey, you will still be using **Qwerty** and will not have too many problems in case you will need to use another computer or someone use yours.

The good thing is that we have multiple options depending on our needs and tastes. Choose wisely whatever you think it's better for you.

---

One last shout-out. If you are a software developer, also be cool to use these JS/TS operators shortcuts.

{% post https://dev.to/equiman/javascript-operators-with-autohotkey-37kn %}

---

**Sources:**

- [Wikipedia - Keyboard Layouts](https://en.wikipedia.org/wiki/Keyboard_layout)
- [Wikipedia - British and American Keyboards](https://en.wikipedia.org/wiki/British_and_American_keyboards)

---

**That’s All Folks!**
**Happy Coding** 🖖

[![beer](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mkgsx4aw6qn9i9ax6as9.png)](https://github.com/sponsors/deinsoftware)