Programming Guide



sm_getkey

Gets the logical value of the key hit

#include <smkeys.h>
int sm_getkey(void);

Returns

Description

sm_getkey gets and interprets keyboard input and returns its logical value. Panther returns normal characters unchanged; it interprets logical keys according to the current key translation file. sm_getkey is called by sm_input and is not usually called explicitly by the application program.

Logical keys include XMIT, EXIT, HELP, arrows, data modification keys like INS, user function keys PF1 - PF24, shifted function keys SPF1 - SPF24, and others. Defined values for all are in smkeys.h. Some logical keys like LP and REFR are processed locally in sm_getkey and are not returned to the caller.

Use sm_getkey to retrieve logical key values previously pushed back on the input stream by sm_ungetkey. Because all Panther input routines call sm_getkey, you can use sm_ungetkey to generate any input sequence automatically.

When sm_getkey reads a key from the keyboard, it flushes the display first so the user sees a fully updated display before typing on. This is not the case for keys pushed back by sm_ungetkey; because input comes from the program, it is responsible for updating the display itself.

sm_getkey can call a number of user-installed functions. For information on installing functions, refer to "Installing Functions" in Application Development Guide.

Like other Panther input functions, sm_getkey checks for externally established abort conditions on each iteration. If such a condition exists, sm_getkey returns the ABORT key and returns to its caller immediately. Refer to sm_isabort.

Note that Panther control strings are not executed within this function, but at a higher level in Panther's runtime system—that is, by functions that call sm_getkey.

The following outline shows how Panther processes sm_getkey. This presentation omits key translation for the sake of clarity; for a description of that algorithm, refer to Chapter 6, "Key Translation File," in Configuration Guide.

Step 1:

Step 2:

Step 3:

Example

#include <smdefs.h>
#include <smkeys.h>

int query (text)
char *text;
{
int key;

sm_d_msg_line(text, REVERSE);
for (;;)
{
switch (key = sm_getkey())
{
case XMIT:
case 'y':
case 'Y':
sm_d_msg_line("", WHITE);
return 1;
default:
sm_femsg(0, "%Mu So it's 'no'");
sm_d_msg_line("", WHITE);
return 0;
}
}
}

See Also

sm_keyfilter, sm_ungetkey