[comp.sys.ibm.pc] Want to remap ` and ESC keys on XT

bob@omni.com (Bob Weissman) (02/17/90)

I can't take it any more.  Every time I go to hit ESC on my XT's keyboard,
I get open-single-quote (`).  And vice versa.  This is because the keys
are in the wrong places.  This makes using vi a big pain.

Does anyone have software (a TSR, presumably) to exchange these
two keys?

Thanks,
-- 
Bob Weissman
Internet:	bob@omni.com
UUCP:		...!{apple,pyramid,sgi,tekbspa,uunet}!koosh!bob

GMoretti@massey.ac.nz (Giovanni Moretti) (02/22/90)

> Re swapping ESC and ` key

I'm interested in this also - ` doesn't work as a META character in EMACS
(although I could reconfigure emacs :-).

Please reply to the net, If you have such a TSR available.

Cheers 
Giovanni

-- 
-------------------------------------------------------------------------------
|   GIOVANNI MORETTI, Consultant     | EMail: G.Moretti@massey.ac.nz          |
|Computer Centre,  Massey University | Ph 64 63 69099 x8398, FAX 64 63 505607 |
|   Palmerston North, New Zealand    | QUITTERS NEVER WIN, WINNERS NEVER QUIT |
-------------------------------------------------------------------------------

braner@batcomputer.tn.cornell.edu (Moshe Braner) (02/26/90)

In the book DOS POWER TOOLS by the editors of PC Mag (highly recommended!)
there is a utility (in the accompanying disk) called IBMFIX.  It swaps the
ctrl and capslock keys.  It is a small .com file so it should be easy to patch
it to swap ` and esc instead.  (It is a TSR that traps the keyboard interrupt.)

If anybody enhanced it to swap BOTH pairs of keys, can I have a copy?  Thanks.

- Moshe

Ralf.Brown@B.GP.CS.CMU.EDU (02/26/90)

In article <9799@batcomputer.tn.cornell.edu>, braner@batcomputer.tn.cornell.edu (Moshe Braner) wrote:
}In the book DOS POWER TOOLS by the editors of PC Mag (highly recommended!)
}there is a utility (in the accompanying disk) called IBMFIX.  It swaps the
}ctrl and capslock keys.  It is a small .com file so it should be easy to patch
}it to swap ` and esc instead.  (It is a TSR that traps the keyboard interrupt.)
}
}If anybody enhanced it to swap BOTH pairs of keys, can I have a copy?  Thanks.

Well, this is not an enhancement, it is one that I wrote myself.  Swaps
Escape/backquote and CapsLock/LeftCtrl (the right control key remains a
control key).

section 1 of uuencode 3.07 of file swapkeys.com    by R.E.M.

begin 644 swapkeys.com
MZ:X`@/Q/=5,\^G-./.%U`K#@@#Y4`."B5`!T/CP==02P.NLV/)UU!+"ZZRX\\
M.G4$L!WK)CRZ=02PG>L>/`%U!+`IZQ8\@74$L*GK#CPI=02P`>L&/*EU`K"!E
M^2[_+E``4U=!4$M%65,@("AC*2!#;W!Y<FEG:'0@,3DX.2!286QF($)R;W=NR
M#0I3=V%P<R!%<V,O=&EL9&4@86YD($-A<'-,;V-K+TQE9G1#=')L#0HDNF`!_
MM`G-(;@5-<TAB1Y0`(P&4@#&!E0``+X#`;]5``X'N5T`_/.DNE4`N!4ES2&ZA
$L@#-)P#-E
``
end
sum -r/size 1645/356 section (from "begin" to "end")
sum -r/size 5952/229 entire input file

--
UUCP: {ucbvax,harvard}!cs.cmu.edu!ralf -=- 412-268-3053 (school) -=- FAX: ask
ARPA: ralf@cs.cmu.edu  BIT: ralf%cs.cmu.edu@CMUCCVMA  FIDO: Ralf Brown 1:129/46
"How to Prove It" by Dana Angluin              Disclaimer? I claimed something?
14. proof by importance:
    A large body of useful consequences all follow from the proposition in
    question.

mccarthy@well.sf.ca.us (Patrick McCarthy) (02/27/90)

In article <9799@batcomputer.tn.cornell.edu> braner@tcgould.tn.cornell.edu (Moshe Braner) writes:
>In the book DOS POWER TOOLS by the editors of PC Mag (highly recommended!)
>there is a utility (in the accompanying disk) called IBMFIX.  It swaps the
>ctrl and capslock keys.  It is a small .com file so it should be easy to patch
>it to swap ` and esc instead.  (It is a TSR that traps the keyboard interrupt.)
>
>If anybody enhanced it to swap BOTH pairs of keys, can I have a copy?  Thanks.
>
>- Moshe

Attached is the MASM 5.0 source for a TSR I wrote which switches the ctrl and
capslock keys.  It relies on Interrupt 15h, function 45h, which according
to IBM is invoked by the keyboard BIOS on all AT class machines, and
most XT machines.  I can't guarantee it will work on all XTs or even
all clone XTs, but it does work on all AT clones I've tried.
It's pretty simple-minded, but it's small and it works.

Pat McCarthy
mccarthy@well.uucp

--- Cut Here ---
page 82,132
Title CTRLCAPS key switcher source
;==============================================================================
;
;
;	CTRLCAPS  TSR which "switches" the Caps Lock key with the left
;		  Ctrl key.
;
;	Version 1.10 November 15, 1989	PKM
;
;==============================================================================
;
	name	    ctrlcaps
	mycode	   segment byte public 'code'
 
	assume cs:mycode
	assume ds:mycode
 
vector_save	    dd	    0		; Previous contents of INT 15H vector.
 
ctrl_make	    equ     01dh	; Keyboard (hardware) make and break
ctrl_break	    equ     09dh	; scan codes for the left Ctrl key
caps_make	    equ     03ah	; and he Caps Lock key.
caps_break	    equ     0bah	;
 
;==============================================================================
;
;	DO_SWITCH is an interrupt service routine  which gins control
;	whenever interrupt 15H is invoked.  If function 4F is requested,
;	the value of the AL register is examined to determine whether it
;	contains a make or break code for the Caps Lock key or the left
;	Ctrl key.  If it does, it is changed to the corresponding make or
;	break code for he other key, effectively switching the operation
;	of the Caps Lock and left Ctrl keys.
;
;	Note that there are three different sets ofscan codes that the
;	keyboard can be programmed to send.  do_switch assumes that set
;	1 (as documented by IBM) is currently in effect.
;
;	The IBM BIOS interrupt 9 handler on many XT and AT machines
;	invovkes software interrupt 15H, function 4F, after receiving a
;	keyboard make/break code from the keyboard controller, but before
;	any translation takes place.  The value contained in the AL
;	register is the (hardware) scan code the BIOS is about to process.
;	That scan code can be changed by the 15H handler; if the carry flag
;	is clear upon return from the 15H handler, the BIOS will discard the
;	keystroke entirely.
;
;==============================================================================
 
do_switch	proc	near
		assume	ds:nothing
 
		cmp	ah, 4Fh 	; Function 4Fh requested?
		jne	shot jump_prev ; If not, chain to previous handler.
 
check_ct_make:
		cmp	al, ctrl_make	; Make code for left Ctrl key?
		jne	check_ct_break	; No, check next code.
		mov	al, caps_make	; Yes, change it to Caps make,
		jmp	shor jump_prev ; and exit.
 
check_ct_break:
		cmp	al, ctrl_break	; Break code for left Ctrl key?
		jne	check_cp_make	; No, check next code.
		mov	al, caps_break	; Yes, change it to Caps break,
		jmp	short jump_prev ; and exit.
 
check_cp_make:
		cmp	al, caps_make	; Make code for Caps Lock key?
		jne	check_cp_break	; No, check next code.
		mov	al, ctrl_make	; Yes, change it to Ctrl make,
		jmp	short jump_prev ; and exit.
 
check_cp_break:
		cmp	al, caps_break	; Break code for Caps Lock key?
		jne	jump_prev   	; No, exit.
		mov	al, ctrl_break	; Yes, change it to Ctrl make.
 
jumpprev:				; Jump to the previous handler.
		jmp	dword pt vector_save
 
endcode 	label	near		; This marks the end of the code
					; which will remain resident when
					; CTRLCAPS goes TSR.
 
do_switch	endp
 
 
;==============================================================================
;
;	MAIN is the entry point for CTRLCAPS.  It frees CTRLCAPS' copy of
;	the DOS environment, saves the address of the current int 15H
;	handler in the variable vector_save, places the address of
;	do_switch (the int 15H handler) in the vector, and calls DOS to
;	terminate and stay resident.  Note that the label endcode is used
;	to determine the size of the memory block which remains.  Thus,
;	main itself does not stay in memory when CTRLCAPS terminates.
;
;==============================================================================
 
main		proc	near
 
		mov	cx, ds		; Save the value of DS for later.
 
		mov	ah, 49h
		mov	es, word ptr ds:[2ch]
		int	21h		; Free the environment segmnt.
 
					; Save the address of the current
					; 15H handler, then install
					; do_switch as the 15H handler.
		mov	ax, 0
		mov	ds, ax
		assume	ds:nothing
 
		les	si, ds:[54H]
		mov	word ptr vector_save, si
		mov	word ptr vector_save+2, es
 
		cli			; Disable interrupts, install ISR.
		mov	word ptr ds:[54h], offset do_switch
		mov	ds:[56h], cs
		sti
 
		mov	ah, 31h 	; Prepare to terminate and stay
		mov	al, 0		; resident.
 
					; Compute resident size.
		mov	dx, seg endcode
		sub	dx, cx		; CX still contains initial DS,
					; which points to the PSP.
		mov	cx, 4
		shl	dx, cl		; Convert from paragraphs to bytes.
		add	dx, (offset endcode + 15)
		mov	cx, 4
		shr	dx, cl	; Convert from bytes to paragraphs.
		int	21h		; Terminat and stay resident.
 
main		endp
 
mycode		ends
		end main

--- Cut Here ---

austin@bucsf.bu.edu (Austin H. Ziegler, III) (02/27/90)

>>>>> On 25 Feb 90 20:41:50 GMT, braner@batcomputer.tn.cornell.edu (Moshe
>>>>> Braner) said:

Moshe> In the book DOS POWER TOOLS by the editors of PC Mag (highly
Moshe> recommended!)  there is a utility (in the accompanying disk) called
Moshe> IBMFIX.  It swaps the ctrl and capslock keys.  It is a small .com
Moshe> file so it should be easy to patch it to swap ` and esc instead.
Moshe> (It is a TSR that traps the keyboard interrupt.)

	I recommend many of the utilities in the book (especially INSTALL
and REMOVE) but I do not recommend IBMFIX.  The description of the program
is that it swaps the LEFT-Control and CAPSLOCK keys, but it switches BOTH
control keys with the capslock.  So, if you don't want TWO CapsLock keys,
don't use this program.  Further, it uses a different sort of check for
this swap than another.  It is far easier to install ANSI.SYS or one of its
replacements and use the following sequence to swap the keys:

	<ESC>[27;"`";p<ESC>[96;27;p

	where <ESC> is character 27.  That should swap the keys physically.
The alternate method is to redefine the output character translation (this
may work only in NANSI.SYS) using this sequence:

	<ESC>[27;96y<ESC>[96;27y

Hope this helps,
just my two bytes,
austin
--
+--------------------------------------------------------------------------+
| The surgeon general of the United States of America has determined that  |
| reading USENET turns your brain to jelly, leaving nothing to claim or to |
| disclaim. +--------------------------------------------------------------+
+-----------+ Austin Ziegler   austin@bucsf.bu.edu or austin@buengf.bu.edu |
| 700 Commonwealth Box 2094, Boston, Massachusetts  02215    BUENG '93     |
+--------------------------------------------------------------------------+

wales@valeria.cs.ucla.edu (Rich Wales) (03/08/90)

Here is a TSR I wrote some time back that switches the ESC, backspace,
and `/~ keys on an 84-key keyboard.  It works by hooking into the key-
stroke interrupt vector (09h) and modifying the BIOS typeahead buffer
before any other program has a chance to see what was originally put
there by the BIOS' keyboard routine.

I wrote this because I was losing my mind trying to cope with the dif-
ferences between my clone's keyboard at home and my Sun-3/50's keyboard
at school.  With this program (and after rearranging the relevant key
caps at home), the main set of keys are the same on both keyboards.

Load this TSR as early as possible in your AUTOEXEC.BAT file.

This program doesn't use Int 15h function 4Fh, so it should work on any
XT-type machine.  On the other hand, it assumes that each keystroke puts
at most one entry into the typeahead buffer -- so it won't work with an
"extended" keyboard that represents some keys with two buffer entries.

Note that the program needs to look at the status of the "shift" keys in
order to tell how to map the backspace key (~ if shifted, ` if not).  I
was unable to figure out any way to address this issue via the keyboard
remapping facilities of an ANSI console driver; hence this TSR.

I'd welcome any comments on this program.

-- Rich Wales <wales@CS.UCLA.EDU> // UCLA Computer Science Department
   3531 Boelter Hall // Los Angeles, CA 90024-1596 // +1 (213) 825-5683
   "I never lie when I've got sand in my shoes, Commodore."

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

begin 644 kb84fix.com
MZU<``%!34AZX0`".V(L>'`"<+O\>``$['AP`=#>+%X'Z&P%U!L<'"`[K*8'Z
M8"EU!L<'&P'K'8'Z?BET]('Z"`YU$?8&%P`#=0;'!V`IZP3'!WXI'UI;6,\S
CP([8H20`+J,``:$F`"ZC`@'ZN`0!HR0`C,BC)@#[NED!S2?'
`
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

; ======================================================================
;
;	KB84FIX.ASM
;
;	(C) Copyright 1990 Richard B. Wales <wales@CS.UCLA.EDU>
;	May be distributed and used freely, so long as the original
;	source is included in any distribution, no charge (other than
;	a nominal communications or handling charge) is assessed, and
;	this notice is retained intact.
;
;	This TSR hooks into Int 9H and switches the BKSP, ESCAPE, and
;	Tilde/Grave keys on an 84-key keyboard.  It needs to be loaded
;	as early as possible -- before any other TSR's that hook into
;	the Int 9H vector.
;
;	I wrote this program because I wanted the keys on the top row
;	of my home "clone" system to be arranged in the same way as on
;	the Sun 3/50 workstation I use at school.  I pried off the caps
;	for the three keys in question; this TSR intercepts the key-
;	strokes and makes the keys generate the characters on the caps.
;
;	This program should be readily adaptable to other applications
;	that need to swap keys (e.g., a Dvorak keyboard mapper) or
;	otherwise manipulate the BIOS keystroke buffer.  Note, however,
;	that I assume each keystroke will result in at most one entry
;	being placed in the BIOS buffer; hence, this program would have
;	to be modified somewhat to work with an "extended" keyboard.
;
;	Assembled using Microsoft Assembler (MASM) version 5.1.  After
;	assembly and linkage, use EXE2BIN to convert the program into a
;	.COM file.
;
; ======================================================================

; Segment 0000H (interrupt vectors)
INTVECS	segment	at 0000H
	org	24H
int9vec	dw	?		; Interrupt vector 09H
	dw	?
INTVECS	ends

; Segment 0040H (BIOS data area)
BIOSDTA	segment	at 0040H
	org	17H
kbflags	db	?		; Keyboard flags
	org	1CH
buftail	dw	?		; Tail pointer (character buffer)
BIOSDTA	ends

; Shift-key mask for kbflags
SHFTMSK	equ	03H		; look for left and/or right shift key

; Character codes we are interested in changing
ESCAPE	equ	011BH		; escape
BKSP	equ	0E08H		; backspace
GRAVE	equ	2960H		; grave accent
TILDE	equ	297EH		; tilde

; ======================================================================

CODESEG	segment
	assume	cs:CODESEG, ds:BIOSDTA
	org	100H

; Buffer to hold address of original system Int 9H
; (will overlay the "jmp" at the start of the program)
oldint9	label	dword

begin:	jmp	short init	; Will be overlaid by "oldint9" value
	dw	0		; ditto

; New Int 9H handler
newint9	proc	far

	; Save the registers we'll be playing with
	push	ax
	push	bx
	push	dx
	push	ds

	; Establish the BIOS segment register for accessing BIOS data
	mov	ax, seg BIOSDTA
	mov	ds, ax

	; Get the tail pointer to the character buffer
	mov	bx, [buftail]

	; Call the original (BIOS) Int 9H routine first, and
	; let it put a new character into the circular buffer
	pushf
	call	[oldint9]

	; Did the BIOS routine add a character to the buffer?
	; If so, copy it into a register so we can examine it
	cmp	bx, [buftail]
	je	short done
	mov	dx, [bx]

	; Check for the four codes of interest, and switch them around

	; ESCAPE -> BKSP
	cmp	dx, ESCAPE
	jne	short notesc
	mov	[bx], BKSP
	jmp	short done
notesc:

	; (GRAVE or TILDE) -> ESCAPE
	cmp	dx, GRAVE
	jne	short notgrv
makesc:	mov	[bx], ESCAPE
	jmp	short done
notgrv:	cmp	dx, TILDE
	je	short makesc

	; BKSP -> GRAVE (if unshifted) or TILDE (if shifted)
	cmp	dx, BKSP
	jne	short done
	test	byte ptr kbflags, SHFTMSK
	jnz	short shift
	mov	[bx], GRAVE
	jmp	short done
shift:	mov	[bx], TILDE

	; All done.
done:	pop	ds
	pop	dx
	pop	bx
	pop	ax
	iret
newint9	endp

; ======================================================================

; TSR initialization code

init:
	assume	ds:INTVECS

	; Establish a zero segment register for interrupt vector area
	xor	ax, ax
	mov	ds, ax

	; Save the old Int 9H pointer
	mov	ax, [int9vec]
	mov	word ptr oldint9, ax
	mov	ax, [int9vec+2]
	mov	word ptr oldint9[2], ax

	; Hook in the new Int 9H handler
	cli
	mov	ax, offset newint9
	mov	[int9vec], ax
	mov	ax, cs
	mov	[int9vec+2], ax
	sti

	; Exit via a TSR call
	mov	dx, offset init
	int	27H

CODESEG	ends
	end	begin

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

-- Rich Wales <wales@CS.UCLA.EDU> // UCLA Computer Science Department
   3531 Boelter Hall // Los Angeles, CA 90024-1596 // +1 (213) 825-5683
   "Then they hurl heavy objects. . . .  And claw at you. . . ."