C Language Development Kit/Functions/SetEcho

From OptiWiki

Jump to: navigation, search
Description This function sets the echo mode on or off, or returns the current echo mode.

When echo mode is on, the character is automatically displayed on the screen after a key-press, without having to use putchar() or printf(). Note however, that still the getchar() or kbhit() function must be called to display the character. This feature is useful when entering alphanumerical characters with the SHIFT key. For example, if one presses the SHIFT key and then the '1' key the display will show the letter 'A'. Pressing the '1' key again will change the 'A' into 'B'. Pressing the SHIFT key, or another key than the '1' key, will then place the 'B' character into the keyboard buffer. Only when the character has been placed in the keyboard buffer will the getchar() function return with the character. The example shows how to call getchar() in a loop until it returns with a character. When echo mode is off, the key-press will be placed in the keyboard buffer in the way as described above, but the character will not be displayed.

int setecho(int echomode);
int echomode
echomode can have the following values:
ON Switches the echo mode on.
OFF Switches the echo mode off.
-1 Does not change echo mode, but returns the current echo mode.
Returns setecho() always returns the (new) echo mode.
Remarks The default state of echo mode is OFF.

On the OPH100x (and the OPL97xx), to disable any displaying of characters while entering alphanumerical characters with the SHIFT key, see 'System settings' chapter 'Text display options'.

#include "lib.h"
#include <stdio.h>
void readln( char *string)
    int c,x;
    for( x=0 ;;)
        switch( c=getchar() )
            case EOF:
            case '\r':
                string[x] = '\0';
            case BS_KEY:
                if( x != 0)
                    string[x] = '\0';
                    printf("\r%s ", string);
                    gotoxy( x, wherey());
                if( (c >= ' ') && (c < 0x80) && (x < 16))
                    string[x++] = (char)c;
void main( void )
    char string[20];
    setecho( ON );
    systemsetting("WK"); // Key click ON
    cursor( BLINKING );
    printf("\tr   Echo test    \tr\n");
        printf("\n\tr%s\tr\n", string);

Personal tools