DEV Community

Cover image for Javascript Operators with AutoHotKey
Camilo Martinez
Camilo Martinez

Posted on • Updated on

Javascript Operators with AutoHotKey

Languages: [🇪🇸] Español - [🇺🇸] English


If you are a software developer and the major time write code in JavaScript (or TypeScript) this post can be useful.

With AutoHotKey you can remap some key behavior to write quick and easy all those operators used day to day.


You need to have installed AutoHotKey and create a file called js-remapkeys.ahk with this script.

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

!7::Send {&}{&}                             ; Alt+7         &&          Logical AND
!+7::Send {&}{&}{=}                         ; Shift+Alt+7   &&=         AND Assignment
!8::Send {*}{*}                             ; Alt+8         **          Math Power
!9::Send {=}{>}                             ; Alt+9         =>          Arrow
!+9:: Send {(}{)}{space}{=}{>}              ; Shift+Alt+9   () =>       Arrow Function, implicit return
!^9:: Send {(}{)}{space}{=}{>}{space}{{}{}} ; Ctrl+Alt+9    () => {}    Arrow Function, explicit return
!\::Send {|}{|}                             ; Alt+\         ||          Logical OR
!+\::Send {|}{|}{=}                         ; Shift+Alt+\   ||=         OR Assignment
!=:: Send {=}{=}{=}                         ; Alt+=         ===         Strict Equality
!+=:: Send {!}{=}{=}                        ; Shift+Alt+=   !==         Strict Inequality
!,:: Send {<}{/}{>}{left 1}                 ; Alt+,         </>         HTML Close Tag
!^,:: Send {<}{/}{>}{left 2}                ; Ctrl+Alt+,    </>         React Component Tag
!.:: Send {?}{.}                            ; Alt+.         ?.          Optional Chaining
!+,:: Send {<}{=}                           ; Shift+Alt+,   <=          Less than or equal to
!+.:: Send {>}{=}                           ; Shift+Alt+.   >=          Greater than or equal to
!+;:: Send {?}{:}{left 1}                   ; Shift+Alt+;   ?:          Ternary Operator
!/:: Send {?}{?}                            ; Alt+/         ??          Nullish Coalescing
!+/:: Send {?}{?}{=}                        ; Shift+Alt+/   ??=         Nullish Coalescing Assignment
Enter fullscreen mode Exit fullscreen mode

Save the file and open it with AutoHotkey.

Finally, we will have a powered keyboard for JS/TS development.

js-keys


That’s All Folks!
Happy Coding 🖖

beer

Top comments (0)