Solved

EASY Question, How to detect delete key and backspace input for scanf

Posted on 2004-04-28
6
1,522 Views
Last Modified: 2007-12-19
Hi,

Title is a little confusing, but my program asks for input
and if they mess up and press the backspace it inserts weird characters, or when they press the back arrow key or forward error key.

How to detect that these keys were pressed and the input is deleted one space or if arrow key is pressed the cursor goes back or forward one place?

I am doing this program in C and some C++, so either solution would be nice.
This is a command line program.

Thanks,
Matt
0
Comment
Question by:LinkLink
6 Comments
 
LVL 46

Accepted Solution

by:
Sjef Bosman earned 45 total points
ID: 10941244
You can't on a Linux-system. Normally the system is in "cooked" mode, unless you set "raw" mode. In "cooked" mode, some or all special characters are dealt with by the O/S itself.

What system are you on, what O/S??
0
 

Author Comment

by:LinkLink
ID: 10941314
I am on a Linux machine, Red Hat

A Project for school we are writing our own bash shell type thing,  I have got the whole thing working just need to make it so when you input something you can delete, and use arrow keys like a normal shell would do.
0
 

Author Comment

by:LinkLink
ID: 10941365
It is not part of the assignment, but just for my own satisfaction of making it the best I can
0
ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

 
LVL 10

Assisted Solution

by:Mercantilum
Mercantilum earned 40 total points
ID: 10941544
I guess your problem is actually that the default behaviour of backspace is not well configured,

e.g.

   typing
     "abcdx" you want to remove the "x" to put a "e" and you get
     "abcdx^H" for instance.
 
Have a look to http://www.tldp.org/HOWTO/Keyboard-and-Console-HOWTO-5.html
0
 
LVL 2

Assisted Solution

by:Avik77
Avik77 earned 40 total points
ID: 10941615
Hi,
  try to use the terminfo capabilities in term.h and temios.h
There u have to properly configure the terminal environment at the start of the program.
Moreover u can also search for the tgoto function manuals. I don't remember whether it is available in ur Red Hat L. There is also the curses or ncurses library. Go through the manuals of each of them . You may get a possible solution. Because these libraries lets u configure the terminal of the Linux system.

Avik.
0
 

Author Comment

by:LinkLink
ID: 10941982
Thanks,

you all had right answers so I split the points amongst you,
The thing is I was ssh ing into  the linux machine from my Mac, so the backspace keys are different and linux wasn't recognizing that.

Matt
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Dll Dynamic way c/c++ 9 139
Why this code doesn't work? 8 97
Read file descriptor 3 in C 14 104
How to build c program using make in mingw environment? 9 54
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…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now