
Help needed: QB 4.5 and TSR
Quote:
> I have a program written in QB 4.5 that uses certain function keys
> to bring up menus. Example: I use 'ON KEY(1) GOSUB subroutine' with
> 'KEY(1) ON' so that when F1 is pressed I do the subroutine. This works fine
> with the regular keyboard. I have a universal 32 key keypad that has the
> function keys on it. The keypad is interfaced to a serial port and uses
> a TSR to control it. Here's the problem: the keypad's function keys do not
> work while I run the program either in the QB environment or using an EXE
> file. They do work however in the QB environment. F1 brings up the HELP menu,
> F5 starts the program, etc. It seems like they should work in the program.
> Can anyone help me? PLEASE.
The problem is most likely caused by the way your keypad TSR emulates the
keyboard. Normally, pressing a key causes a scan code to appear in a I/O
port and triggers hardware Interrupt 9. The handler for Int 9 reads the
value from the port, translates it into an ASCII code (or pseudocode), and
places that code into the keyboard buffer.
Presumably, your keypad TSR reads values from the com port, translating
them into ASCII/pseudo codes (much the same way the Int 9 handler
translates keyboard scan codes), and places those in the buffer.
The QB IDE sees these "fake" codes because it reads from the keyboard
buffer. But ON KEY GOSUB intercepts scan codes directly from the hardware
port by hooking in ahead of the Int 9 handler, so ON KEY GOSUB never sees
the codes your keypad TSR stuffs into the buffer.
There's no real easy solution to this. Since Int 9 is a hradware interrupt,
you can't call it properly from software. There are ways to hook Int 9 so
that you can *alter* a code coming from the keyboard, but you can't insert
a code when the keyboard didn't generate one.
If you can use INKEY$, or INPUT$(1), or any of the other standard input
functions, they read from the keyboard buffer, so they should work with your
keypad TSR. But that does mean that you'll have to poll for input
instead of just letting ON KEY interrupt your program whenever a key is
pressed. This is generally a better method anyway, since it eliminates the
overhead of ON KEY event-checking, and the program is in a known state
rather than being interrupted at unpredictable moments.
---
Glen Blankenship