?
Solved

Keyboard Buffer

Posted on 2003-02-19
4
Medium Priority
?
347 Views
Last Modified: 2010-04-15
In a TSR program,How to read the contents of a Keyboard Buffer and store it in a file?
0
Comment
Question by:sarun007
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 1

Expert Comment

by:TheBeaver
ID: 7984499
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
 
LVL 1

Accepted Solution

by:
TheBeaver earned 200 total points
ID: 7984510
Of course KeyKill() is useless... i moved the code from here to KeyInt because I noticed you want a TSR
0
 
LVL 20

Expert Comment

by:jmcg
ID: 10006290
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question