Your program is obviously, for some strange reason, interpreting keyboard scancodes as ASCII character codes. I have no idea why any sane DOS program would do this, as the two sets were always quite different.
Edit: I seem to remember, very deep in the back of my head, that there was some BIOS (or DOS?) function that returned ASCII codes for normal keys and some marker byte (was it 0x00?) followed by the raw scancode for special keys. Maybe that's what happening and for some reason the marker byte isn't reaching your prog or isn't being interpreted correctly. But don't quote me on this, and don't ask me for the function number.
Edit again: I now think it was not a BIOS or DOS function but rather some function from either QuickBasic or Turbo Pascal. Is your program written in any of these languages? Though I'm still not sure. I did Turbo in High School and I earned a bit of money doing QuickBasic stuff during university, but that was really long ago.