C Language Development Kit/Snippets/Input/KeyboardNumeric

From OptiWiki

Jump to: navigation, search
Description Input a numeric value by the keyboard, alignment is done from left to right.
Syntax
int KeyboardNumeric( char *string, int max_length, int typ, int x, int y, int display_length, int num, ... );
Arguments
char *string

Holds the scanned barcode, or a default value.

int max_length

The maximum length the scanned barcode may have.

int typ

typ is an orred parameter that specifies what keys can be typed. typ can be one or orred of these keys:

INPUT_NUM Numeric input is.
INPUT_NEGATIVE The first character of the input string can be a minus sign.
INPUT_SHOW_DEFAULT Show a default value that is placed in string.
int x

x start position where the input string is placed.

int y

y start position where the input string is placed.

int display_length

If more characters are inputted then display_length then the data is scrolled.

int num

The amount exception keys that are specified in the list.
...
Holds the list of exception keys.

Returns EOF when no exception keys are used, else returns the exception key.
Remarks BS_KEY cannot be used as an exception key.

when typ holds the INPUT_NEGATIVE value the max_length value is increaded by 1. This measn that the input string value also need to be increade to hold the possible minus sign.

Example
#include "lib.h"
#include <stdio.h>
#include "input.h"  //Holds the input functions
 
void main( void )
{
    int key;
    char string[ 8 ];
    for(;;)
    {
        string[0] = '1';
        string[1] = '\0';
        printf("\fKeyboardNumeric\n");
        if(KeyboardNumeric(string,6,INPUT_NEGATIVE|INPUT_NUM|INPUT_SHOW_DEFAULT,0,1,14,2,CLR_KEY,ENT_KEY) == CLR_KEY)
            printf("\fCLR key pressed\n");
        else
            printf("\ftyped:\n%s\n", string);
        printf("press a key\nto continue");
        WaitForKey();
    }
}


Views
Personal tools