Skip to content

Instantly share code, notes, and snippets.

@jtsiomb jtsiomb/capsctrl.asm
Last active Sep 8, 2018

What would you like to do?
DOS TSR for remapping caps lock to control (see comment at the end for pre-built binaries)
; DOS caps lock -> ctrl remapper
; Author: John Tsiombikas <>
; This program is public domain. Do whatever you like with it
; build with: nasm -o -f bin capsctrl.asm
org 100h
bits 16
mov ax, 0900h
mov dx, msg
int 21h
; get current keyboard interrupt handler
mov ax, 3509h
int 21h
mov [orig_seg], es
mov [orig_off], bx
; set our own interrupt handler in its place
mov ax, 2509h
mov dx, kbintr
int 21h
mov ax, 0900h
mov dx, msg_done
int 21h
; terminate and stay awesome
mov dx, end_of_code
int 27h
KB_INTR equ 09h
KB_PORT equ 60h
PIC1_CMD_PORT equ 20h
OCW2_EOI equ 20h
KBFLAGS0 equ 0x17
KBFLAGS1 equ 0x18
KBF0_CTRL equ 0x04
KBF1_LCTRL equ 0x01
push ax
in al, KB_PORT
jz .caps_press
jz .caps_release
; otherwise jump to the original handler
pop ax
push word [cs:orig_seg]
push word [cs:orig_off]
; set ctrl flags
mov ax, es
push word 0x40
pop es
or byte [es:KBFLAGS0], KBF0_CTRL
or byte [es:KBFLAGS1], KBF1_LCTRL
mov es, ax
jmp .end
; clear ctrl flags
mov ax, es
push word 0x40
pop es
and byte [es:KBFLAGS0], ~KBF0_CTRL
and byte [es:KBFLAGS1], ~KBF1_LCTRL
mov es, ax
.end: mov al, OCW2_EOI
out PIC1_CMD_PORT, al
pop ax
msg db 'Installing capslock -> ctrl mapper... $'
msg_done db 'done.',13,10,'$'
orig_seg dw 0
orig_off dw 0

This comment has been minimized.

Copy link
Owner Author

jtsiomb commented Sep 8, 2018

Update: I since generalized this hack, made it able to remap caps lock to any key (configurable with rebuild), added a utility for finding the proper scancode to use for configuring it, and made it a full project at:

The release archive of capsmap includes pre-built binaries and for remapping caps lock to ctrl or escape:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.