Keyboard Input

This is a discussion on Keyboard Input within the C Programming forums, part of the General Programming Boards category; i'm reading in characters from the keyboard and i'm wanting to check if the character entered is a backspace and ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    4

    Keyboard Input

    i'm reading in characters from the keyboard and i'm wanting to check if the character entered is a backspace and if it is i want to output the ASCII value 08.

    i have this snippet of my code:

    c = fgetc(stdin);

    if (c== '\127')
    fputc('\08',stdout);

    I'm not sure if this is right as it doesn't seem to be working

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Unfortunately, with buffered input you can't read a backspace keypress with fgetc. You'll need to use a raw input function such as getch:
    Code:
    #include <stdio.h>
    #include <conio.h>
    
    int main ( void )
    {
      int c;
    
      c = getch();
    
      if ( c == '\b' )
        printf ( "Backspace pressed\n" );
    
      return 0;
    }
    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help using inline assembly for keyboard input
    By sleventeen in forum C Programming
    Replies: 7
    Last Post: 05-10-2009, 01:31 AM
  2. Keyboard Input
    By CaliJoe in forum C++ Programming
    Replies: 3
    Last Post: 05-08-2009, 09:51 AM
  3. Keyboard input in a Dialog
    By ksarkar in forum C++ Programming
    Replies: 1
    Last Post: 05-20-2005, 05:39 AM
  4. Intercepting keyboard input
    By EvBladeRunnervE in forum Windows Programming
    Replies: 3
    Last Post: 01-08-2004, 08:03 AM
  5. FAQ Keyboard Input ? (C++)
    By Malikive in forum FAQ Board
    Replies: 6
    Last Post: 11-07-2001, 08:30 PM

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