![]() | ![]() | Programming Guide |
Gets the logical value of the key hit
#include <smkeys.h>int sm_getkey ( void );
- · The standard ASCII value of a displayable key.
- · A value greater than 255 (FF hex) for a key sequence in the key translation file.
sm_getkeygets 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_getkeyis called bysm_inputand 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 insm_getkeyand are not returned to the caller.Use
sm_getkeyto retrieve logical key values previously pushed back on the input stream bysm_ungetkey. Because all Panther input routines callsm_getkey, you can usesm_ungetkeyto generate any input sequence automatically.When
sm_getkeyreads 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 bysm_ungetkey; because input comes from the program, it is responsible for updating the display itself.
sm_getkeycan 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_getkeychecks for externally established abort conditions on each iteration. If such a condition exists,sm_getkeyreturns the ABORT key and returns to its caller immediately. Refer tosm_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:
- If an abort condition exists, return the ABORT key.
- If there is a key pushed back by
sm_ungetkey, return the key.- Step 2:
- Pass the key to the keychange function. If that function specifies to discard the key, repeat step 1; otherwise, if an abort condition exists, return the ABORT key.
- If recording is active, pass the key to the recording function.
- Step 3:
- If the routing table says to process the key locally, do so.
- If the routing table says to return the key, return it; otherwise, return to step 1.
#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;
}
}
}