Control key with Ncurses
Hi all,
I am writing a graphics-based application in Linux by making use of C and ncurses library.
The application needs that i take two numbers as input ( i make use of scanw for the same).
However at this point in the program i want the user to obtain the flexibility of exiting gracefully from the program(by pressing a cntrl key,like say F5).
Cntrl-D doesnt seem to work with ncurses..
Heres a snippet of the code.....
/*FORM INITIALIZATION*/
my_form = new_form(field);post_form(my_form);refresh();
mvprintw(1,8,"NOTE:THE ROW AND COLUMN ARE AS DEFINED IN MATRIXALGEBRA"); mvprintw(2,8,"Enter the row and column coordinates(i and j values):");
mvprintw(3,8,"i and j: ");scanw("%d %d",&i,&j);
// at this point i want to exit from the program if F5 key is pressed.
Any pointers ?
Regards,
Vidya
Signature · 13 lines
--------------------------------------------------------------------------
As far as the laws of mathematics refer to reality,they are not certain;
and as far as they are certain, they do not refer to reality.
- Albert Einstein (1879-1955)
--------------------------------------------------------------------------
Kotamraju Vidya
Marine HydroDynamics Lab,
Physical Oceanography Division,
National Institute of Oceanography,
Dona Paula, Goa 403 004, India.
Ph.: +91-832-2456700 *4400 (O)
+91-832-2541756 (R)
e-mail: [email protected]Quoted 7 lines · Vidya Kotamraju
I am writing a graphics-based application in Linux by making use of C and ncurses library.
The application needs that i take two numbers as input ( i make use of scanw for the same).
However at this point in the program i want the user to obtain the flexibility of exiting gracefully from theprogram(by pressing a cntrl key,like say F5).
You need to call keypad() to enable the use of "extended" keys (funcion keys, arrow keys etc). The various KEY_* macros define the codes for the extended keys; for function keys, use KEY_F(), e.g. KEY_F(5) for F5.
Quoted 1 line
Cntrl-D doesnt seem to work with ncurses..
Control codes should be reported by getch() etc as a code in the range 0 to 31 (e.g. Ctrl-D should be code 4).
Signature · 1 line
Glynn Clements <[email protected]>
I had enabled the keypad() along with the other graphics initializations.
Also, Control codes do work with getch().
But what i need to know is how to make use of a control key to exit out of a scanw input. (As control-D would work with scanf without needing to make use of getchar)
Regards,
Vidya.
Quoted 25 lines · Glynn Clements
Quoted 8 lines · Vidya Kotamraju
I am writing a graphics-based application in Linux by making use of C and ncurses library.
The application needs that i take two numbers as input ( i make use of scanw for the same).
However at this point in the program i want the user to obtain the flexibility of exiting gracefully from theprogram(by pressing a cntrl key,like say F5).You need to call
keypad()to enable the use of "extended" keys (funcion keys, arrow keys etc). The various KEY_* macros define the codes for the extended keys; for function keys, useKEY_F(), e.g.KEY_F(5)for F5.Quoted 2 lines
Cntrl-D doesnt seem to work with ncurses..
Control codes should be reported by
getch()etc as a code in the range 0 to 31 (e.g. Ctrl-D should be code 4).
Signature · 13 lines
--------------------------------------------------------------------------
As far as the laws of mathematics refer to reality,they are not certain;
and as far as they are certain, they do not refer to reality.
- Albert Einstein (1879-1955)
--------------------------------------------------------------------------
Kotamraju Vidya
Marine HydroDynamics Lab,
Physical Oceanography Division,
National Institute of Oceanography,
Dona Paula, Goa 403 004, India.
Ph.: +91-832-2456700 *4400 (O)
+91-832-2541756 (R)
e-mail: [email protected]Quoted 5 lines · Vidya Kotamraju
I had enabled the
keypad()along with the other graphics initializations. Also, Control codes do work withgetch().
But what i need to know is how to make use of a control key to exit out of a scanw input. (As control-D would work with scanf without needing to make use of getchar)
You can't; getstr() (which scanw() uses) won't return until you press Return/Enter. If you want to be able to interrupt it, you would have to read the string manually using repeated calls to getch(), then use sscanf() to parse it.
Signature · 1 line
Glynn Clements <[email protected]>