Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 354
  • Last Modified:

Keyboard Buffer

In a TSR program,How to read the contents of a Keyboard Buffer and store it in a file?
0
sarun007
Asked:
sarun007
  • 2
1 Solution
 
TheBeaverCommented:
Assuming you are using DOS...

Install a keyboard interrupt. In that interrupt you write to the file.
If you still want normal behaviour then  add a call to the original interrupt.

The keyboard interrupt is int 9.

This code will work for DJGPP ...

#include <dpmi.h>
#include <go32.h>

_go32_dpmi_seginfo old_handler, new_handler;

FILE *fp;

void KeyKill()
{
}

void KeyInt()
{
  unsigned char ch = getch();

  if( ch == 'x' )
  {
    printf("Closing file\n");
    fclose(fp);

    printf("Removing interrupt\n");
    _go32_dpmi_set_protected_mode_interrupt_vector(0x09, &old_handler);
    _go32_dpmi_free_iret_wrapper(&new_handler);
  }
  else
    fprintf( fp, "%c", ch );  
}

void KeyInit()
{
  printf("Creating file\n");
  fp = fopen("FILE.TXT", "wb");

  printf("Installing interrupt\n");
  _go32_dpmi_get_protected_mode_interrupt_vector(0x09, &old_handler);
  new_handler.pm_offset = (int)KeyInt;
  new_handler.pm_selector = _go32_my_cs();
  _go32_dpmi_allocate_iret_wrapper(&new_handler);
  _go32_dpmi_set_protected_mode_interrupt_vector(0x09, &new_handler);
}

main()
{
  KeyInit();
}
0
 
TheBeaverCommented:
Of course KeyKill() is useless... i moved the code from here to KeyInt because I noticed you want a TSR
0
 
jmcgOwnerCommented:
Nothing has happened on this question in over 7 months. It's time for cleanup!

My recommendation, which I will post in the Cleanup topic area, is to
accept answer by TheBeaver.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now