SilverScreen Solid Modeler

Keyboard and Pointer

Keyboard and Pointer

Previous topic Next topic  

Keyboard and Pointer

Previous topic Next topic JavaScript is required for the print function  

SilverScreenAPI

 

Keyboard and Pointer

 

 

 


INCHAR and NEXTKEY

Keyboard and pointer events are handled in an event queue that is internal to SilverScreen. In a program, events are removed from the queue with the inchar function. The event may be a keystroke, a pointer movement, or a pointer button press. If the queue is empty when inchar is called, then the function waits until an event occurs.

 

A second function, nextkey , may be used to view the event that is at the front of the queue without removing this event. If the queue is empty, nextkey does not wait for an event to occur, but instead, returns 0.

 

The combination of nextkey and inchar can be used to clear the queue. First, nextkey checks to see if an event is in the queue. If so, then inchar is used to remove the event. Here is the code:

 

C / C++ Code

 

 while ( nextkey () )

    inchar ();

 

 

 


Pointer Functions

Events handled in SilverScreen, both keys and pointer events, are defined in sskeys.h . This header file defines the function keys, the control keys, and the pointer button and motion events.

 

SilverC programs are able to monitor the location of the arrow and to determine its location. Here are the functions:

 

Function

Description

pointer_mode

sets the pointer mode

pointer_locate

locates the arrow at a screen coordinate

pointer_char_locate

locates the arrow at a position on a line

pointer_position

returns the screen coordinates of the arrow

pointer_char_position

returns the line and position of the arrow

 

 


Pointer Modes

The events received from the pointing device are dependent on a pointer mode that can be set with pointer_mode. There are three modes: 0, 1 and 2.

 

Mode


0

Disables the pointer so that no pointer events occur.

1

Places the pointing device into key translation mode. When in this mode, pointer mode is translated to keyboard arrow movement, and certain button events are translated to keyboard keys.

2

Causes all pointer events to be returned. pointer_locate and pointer_position functions are used when in this mode.

 


Example

The following section illustrates the use of several of the pointer functions:

 

C / C++ Code

 

 pointer_mode ( 2 );

 pointer_char_locate (20,20);

 

 for ( ; ; )

    {

    switch ( inchar () )

       {

       case ESCAPE:

            . . .

       case M_BOTH:

            . . .

       case M_LEFT:

            pointer_char_position ( &line, &position );

            . . .

       case M_RIGHT:

            pointer_char_position ( &line,&position );

            . . .

       }

    }

 

 

The pointer is placed in mode 2, located at position 20 of line 20, and made visible. The program then reads events with inchar , identifying Esc from the keyboard and the three mouse events.