How to POKE Keystrokes Such as F3 (Last Command) into Keyboard (66744)



The information in this article applies to:

  • Microsoft QuickBASIC 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBASIC 4.5
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0b
  • Microsoft Basic Professional Development System for MS-DOS 7.0
  • Microsoft Basic Professional Development System for MS-DOS 7.1

This article was previously published under Q66744

SUMMARY

Instead of using CALL INTERRUPT to push keystrokes into the keyboard buffer, the code example below POKEs a key directly into the keyboard buffer area in memory under MS-DOS.

This information applies to QuickBasic versions 3.0, 4.0, 4.0b, and 4.5 for MS-DOS; to Microsoft Basic Compiler versions 6.0 and 6.0b for MS-DOS; and to Microsoft Basic Professional Development System (PDS) versions 7.0 and 7.1 for MS-DOS.

MORE INFORMATION

In many applications, it is often useful to echo the command line to the screen during repetitive execution of a program. This makes the program easier to use by allowing you to avoid typing in the command line at the completion of each instance of the program. The code example below shows a quick way to push the F3 keystroke into the keyboard buffer, which echoes the previously entered command line to the screen.

Code Example

DEF SEG = 0      ' Set default segment to 0
POKE 1054,0      ' Push 0 for extended key into keyboard buffer
POKE 1055, 61    ' Push F3 key scan code into keyboard buffer
POKE 1050, 30    ' Set beginning (head) buffer position
POKE 1152, 32    ' Set ending (tail) buffer position
DEF SEG          ' Return current segment pointer to default segment
				

REFERENCES

For more articles about reading from and writing to the keyboard buffer, search in this Knowledge Base for the following words:

interrupt and keyboard and buffer

The addresses for the keyboard buffer area, head, and tail (used in the above code example) are documented in "The New Peter Norton Programmer's Guide to the IBM PC & PS/2" by Peter Norton and Richard Wilton, published by Microsoft Press (1988).

Keyboard scan codes are documented in Appendix D of "Microsoft QuickBasic 4.5: Programming in Basic"; in Appendix A of "Microsoft QuickBasic 4.0: Language Reference" for 4.0 and 4.0b; in Appendix A of "Microsoft Basic Compiler 6.0: Language Reference" for 6.0 and 6.0b; and in Appendix A of "Microsoft Basic 7.0: Language Reference" manual for Basic PDS versions 7.0 and 7.1.

Modification Type:MinorLast Reviewed:8/16/2005
Keywords:KB66744