VOGONS

Common searches


First post, by kin

User metadata
Rank Newbie
Rank
Newbie

Anyone know a TSR that allows you to remap specific keys?
For example a,w,s,d > arrow left, arrow up, arrow down, arrow right.

Only thing I found was using ansi.sys, but I'm not sure if a dos application will overrule that.
Also, I found some flat assembly code, but I'm not quite a programmer... and uh you need to compile that to 16-bit .exe?:

; Modified Keyboard Entry - 13/10/2009 
ORG 256
mov ax,cs
mov ss,ax
mov sp,MyStack+64*2
mov ds,ax
mov es,ax
; Some arbitrary modification
mov byte [Table+"a"],"z"
mov byte [Table+"z"],"a"
; Save existing Keyboard Interrupt Vector
push es
mov ax,3509h
int 21h ;DOS 'Get Interrupt Vector'
mov [Old_09h],bx
mov [Old_09h+2],es
pop es
; Setup new Keyboard Interrupt Vector
mov dx,New_09h
mov ax,2509h
int 21h ;DOS 'Set Interrupt Vector'
; Prompt user action
mov dx,Msg1
mov ah,09h
int 21h ;DOS 'Display String'
MainLoop:
mov ah,01h
int 21h ;DOS 'Keyboard Input & Echo'
cmp al,27 ;<ESC> ?
jne MainLoop
; Restore old Keyboard Interrupt Vector
push ds
lds dx,[Old_09h]
mov ax,2509h
int 21h ;DOS 'Set Interrupt Vector'
pop ds
; Terminate
mov dx,Msg2
mov ah,09h
int 21h ;DOS 'Display String'
mov ax,4C00h
int 21h ;DOS 'Terminate/ReturnCode'
; ----------------------------------------------
New_09h:
push ax bx si ds
mov ax,40h ;BIOS_DataSegment
mov ds,ax
mov si,[001Ch] ;BIOS_KeyboardBufferTailPointer
; Let BIOS take care of the hardware
pushf
call far dword [cs:Old_09h]
cmp si,[001Ch] ;BIOS_KeyboardBufferTailPointer
je .t1 ;No new key in buffer
mov al,[si] ;ASCII (SCAN in [si+1])
mov bx,Table
xlat [cs:bx]
mov [si],al ;Updated ASCII
.t1:
pop ds si bx ax
iret
Show last 16 lines
; ---------------------------------------------- 
ALIGN 4
Old_09h:
dd 0
Table:
times 256 db %-1
MyStack:
dw 64 dup (0)
Msg1:
db 'Watch <a> and <z> being swapped...',13,10
db 'Please press some keys. <ESC> exits!',13,10,'$'
Msg2:
db "-- That's all folks",13,10,'$'
; -----------------------------------------------

Reply 2 of 5, by NewRisingSun

User metadata
Rank Oldbie
Rank
Oldbie

I think the "pure DOS" part of the topic precludes the use of DOSBox.

What games should that TSR be used with? That would determine how the TSR would have to be set up and whether it is possible at all.

Reply 3 of 5, by kin

User metadata
Rank Newbie
Rank
Newbie
NewRisingSun wrote:

I think the "pure DOS" part of the topic precludes the use of DOSBox.

What games should that TSR be used with? That would determine how the TSR would have to be set up and whether it is possible at all.

I was hoping for one that is for all games. The reason is that I try to avoid modding my new keyboard, which has strange arrowkeys arrangement.
Quick edit, I have tried to compile this into an executable, though with slight modification. It did swap the a and z keys, but since this is not a TSR I can't really test it. Though it is possible to make it TSR.

format MZ
; Modified Keyboard Entry - 13/10/2009
mov ax,cs
mov ss,ax
mov sp,MyStack+64*2
mov ds,ax
mov es,ax
; Some arbitrary modification
mov byte [Table+"a"],"z"
mov byte [Table+"z"],"a"
; Save existing Keyboard Interrupt Vector
push es
mov ax,3509h
int 21h ;DOS 'Get Interrupt Vector'
mov [Old_09h],bx
mov [Old_09h+2],es
pop es
; Setup new Keyboard Interrupt Vector
mov dx,New_09h
mov ax,2509h
int 21h ;DOS 'Set Interrupt Vector'
; Prompt user action
mov dx,Msg1
mov ah,09h
int 21h ;DOS 'Display String'
MainLoop:
mov ah,01h
int 21h ;DOS 'Keyboard Input & Echo'
cmp al,27 ;<ESC> ?
jne MainLoop
; Restore old Keyboard Interrupt Vector
push ds
lds dx,[Old_09h]
mov ax,2509h
int 21h ;DOS 'Set Interrupt Vector'
pop ds
; Terminate
mov dx,Msg2
mov ah,09h
int 21h ;DOS 'Display String'
mov ax,4C00h
int 21h ;DOS 'Terminate/ReturnCode'
; ----------------------------------------------
New_09h:
push ax bx si ds
mov ax,40h ;BIOS_DataSegment
mov ds,ax
mov si,[001Ch] ;BIOS_KeyboardBufferTailPointer
; Let BIOS take care of the hardware
pushf
call far dword [cs:Old_09h]
cmp si,[001Ch] ;BIOS_KeyboardBufferTailPointer
je .t1 ;No new key in buffer
mov al,[si] ;ASCII (SCAN in [si+1])
mov bx,Table
xlat [cs:bx]
mov [si],al ;Updated ASCII
.t1:
pop ds si bx ax
iret
Show last 15 lines
; ----------------------------------------------
ALIGN 4
Old_09h:
dd 0
Table:
times 256 db %-1
MyStack:
dw 64 dup (0)
Msg1:
db 'Watch <a> and <z> being swapped...',13,10
db 'Please press some keys. <ESC> exits!',13,10,'$'
Msg2:
db "-- That's all folks",13,10,'$'
; -----------------------------------------------

Attachments

  • Filename
    testkb.zip
    File size
    1.47 KiB
    Downloads
    76 downloads
    File license
    Fair use/fair dealing exception

Reply 4 of 5, by Jepael

User metadata
Rank Oldbie
Rank
Oldbie

What interface your keyboard has (USB, PS/2, AT, XT)?

But no there is no easy way to do that, or it would be done already.

The code you posted hooks the keyboard hardware interrupt, and after the BIOS has determined what scan code & character it is, the key press is modified in the keyboard buffer.

So this will only work if a program uses BIOS keyboard interrupt to read keyboard (or at least if it uses the buffer directly to read keys if not through BIOS).

This won't work with programs that install their own keyboard interrupt handler, and most games do this.

Some keyboard controllers (in PS/2 machines I recall) used to have a command to inject whatever you like so it looks like the data came from keyboard. But it never worked in my PCs.

Modern USB keyboards need to be emulated somehow to look like the data is coming from a keyboard controller, I have no idea how that is done, but maybe someone knows if you can make some software that intercepts the keyboard data there. It could use the system management mode which I also don't know about.

If you are good with microcontrollers, you can easily build a small box that goes between your PC and keyboard and it has PS/2 connectors. Then the microcontroller software can convert certain buttons to other buttons.