keyboard buffer

This is a discussion on keyboard buffer within the C Programming forums, part of the General Programming Boards category; i am reletavely new to programming so please be patient. i am trying to write a turboc program which will ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    5

    Talking keyboard buffer

    i am reletavely new to programming so please be patient.
    i am trying to write a turboc program which will sit in the background (of windows), read in the state of some switches on the parallel port (this bit i can do no problems) and depending on the state of the switches, pass a particular string of scan codes to the keyboard buffer.
    now, i understand the workings of the buffer, tail, head etc.
    i just dont know how to do it in turbo c. what commands i need to use. any conditioning i need to do to the buffer before using it. like, the head at a particular address then the scan codes and then the tail etc. if someone could give me a few pointers that would be great.
    also, (bearing in mind that i am reletively new so correct me if i am wrong) as far as i understand whether in windows or dos this program would need to be a TSR because it needs to do its job continously and 'on the fly'

    thanks in advance for any help

    Adrian

  2. #2
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,220
    It's beyond me and I've been programming C (on and off) for four years.

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    5

    this any good?

    i found this code on the net but dont really understand how it works.
    i tried to adapt this code for my use but i dont really understand it.
    does it make any sense to you?


    /*
    Turbo C Technical Support Notes:
    Stuff the keyboard buffer with characters.

    Created:
    7/1/88

    Revision History:
    */

    #include <dos.h>
    #include <string.h>

    #define START_BUF 30
    main()
    {
    int i;
    int len;
    static char s[] = "dir\r";

    int far *kbhead = MK_FP(0x40,26);
    int far *kbtail = MK_FP(0x40,28);
    int far *kbuffer = MK_FP(0x40,30);

    len = strlen(s);

    *kbhead = START_BUF;
    *kbtail = START_BUF+(len<<1);
    for (i=0; i<len; i++)
    kbuffer[i] = s[i];

    }

  4. #4
    B26354 Deckard's Avatar
    Join Date
    Jan 2002
    Posts
    633
    This works on my Linux box, your mileage may (and probably will) vary. You should consider this super-platform-dependant. If you would like to know more about the guts of stdin on your machine, fire up your favorite debugger and pick it apart.

    Code:
    #include <stdio.h>
    
    int main( void )
    {
      char x[10];
      void *ptr;
    
      fgets( x, 10, stdin );
    
      ptr = stdin->_IO_buf_base;
    
      memcpy( ptr, "HAHAHA", 6 );
    
      stdin->_IO_read_ptr = ptr;
    
      fgets( x, 7, stdin );
    
      printf( "%s\n", x );
    
      return (0);
    }
    Regardless of what you type into the buffer on the first call to fgets(), the printf() will display: HAHAHA

    Hope this helps.
    Jason Deckard

  5. #5
    Registered User
    Join Date
    Jan 2002
    Posts
    5

    ah yeah

    i think i understand your code but it wont work for me.
    i am using borland turbo c. maybe thats the problem.


    i keep geting "undifined symbol '_IO_read_ptr' in function main and the same for _IO_buf_base

    any idea whats happening here. sorry, this is probably a completely stupid question but i would really appreciate your help on this.

    also, i need to be able to push the scan codes for keys like enter, backspace etc. getting these codes isnt a problem, just putting them into the buffer.

    thanks for the help guys, apreciate it.

    ado

  6. #6
    B26354 Deckard's Avatar
    Join Date
    Jan 2002
    Posts
    633

    Re: ah yeah

    Originally posted by adocon
    i think i understand your code but it wont work for me. i am using borland turbo c. maybe thats the problem.
    This isn't due to your compiler. It is due to the way your operating system handles the standard input (keyboard) buffer. See my comment about "super-platform-dependant".
    i keep geting "undifined symbol '_IO_read_ptr' in function main and the same for _IO_buf_base
    You operating system probably has a pointer to the keyboard buffer, but is not calling it _IO_buf_base. What you need to do is fire up your favorite debugger and print out the data that stdin points to. If you are unable to do that, you might consider posting your question to the Windows or DOS forum (depending on your OS), as you really need OS specific guidance.

    Cheers,
    Jason Deckard

  7. #7
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    The only way to track stuff on the fly is to write a TSR that monitors the device you need to monitor. Writing TSRs is an advanced topic and not easy to do, albeit near impossible to do it right in C. It can be done, but it's not as easy as in assembly.

    The first example is creating 3 pointers to areas of memory. These pointers point to the keyboard buffer.

  8. #8
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    for writing a dos TSR look for Advanced DOS programming by Ray Duncan I think. From memory that book goes into all dos functions, tsr writing,device driver writing. Only prerequisite.... You need to understand 16 bit assembly or you are f***ed!

    For windows there are no TSR's as such. What windows has instead are called services. There is a lot of information on msdn . Look for information on writing background services for your particular version of windows. Things are done differently between 9x, and 2k
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  9. #9
    Registered User
    Join Date
    Jan 2002
    Posts
    5

    all right

    all right then.
    i think i will look into assemley. we have done a small bit of that in college. can anyone recomend a good assembler?
    i have a lot of stuff to try now. will look out for that book.
    thanks for the help guys, much appreciated.

    -ado

  10. #10
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Send output to keyboard buffer
    By DReynolds in forum C Programming
    Replies: 2
    Last Post: 06-06-2007, 03:44 PM
  2. Replies: 16
    Last Post: 10-29-2006, 04:04 AM
  3. buffer contents swapping
    By daluu in forum C++ Programming
    Replies: 7
    Last Post: 10-14-2004, 02:34 PM
  4. Console Screen Buffer
    By GaPe in forum Windows Programming
    Replies: 0
    Last Post: 02-06-2003, 04:15 AM
  5. : Difference between message queue and keyboard buffer...
    By Unregistered in forum Windows Programming
    Replies: 0
    Last Post: 02-21-2002, 02:47 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21