Partilhar via


_EdSendKey( ) API Library Routine

Simulates the key press associated with the ASCII character number specified by charNum.

void _EdSendKey(WHANDLE wh, int charNum)
WHANDLE wh;            /* Handle of editing window. */
int charNum;               /* Number of character. */

Example

The following example opens for editing a file specified by a parameter. It inserts a line of text, "Hello, World", by sending the individual characters with _EdSendKey( ). It then uses _EdSendKey( ) to send a carriage return and linefeed and to insert an ASCII escape character. Notice that the escape character isn't interpreted as "discard editing session."

Visual FoxPro Code

SET LIBRARY TO EDSENDKE
= SENDKEY("x")

C Code

#include <pro_ext.h>

void putLong(long n)
{
   Value val;

   val.ev_type = 'I';
   val.ev_long = n;
   val.ev_width = 10;

   _PutValue(&val);
}

FAR Example(ParamBlk FAR *parm)
{
#define pFILENAME ((char FAR *) _HandToPtr(parm->p[0].val.ev_handle))

   WHANDLE wh;
   EDENV EdEnv;

   if (!_SetHandSize(parm->p[0].val.ev_handle,
      parm->p[0].val.ev_length+1))
   {
      _Error(182); // "Insufficient memory"
   }
   pFILENAME[parm->p[0].val.ev_length] = '\0';

   _HLock(parm->p[0].val.ev_handle);
   wh = _EdOpenFile(pFILENAME, FO_READWRITE);
   _HUnLock(parm->p[0].val.ev_handle);

   // Insert a line of text using _EdSendKey()
   _EdSetPos(wh, 0);
   _EdSendKey(wh, 'H');
   _EdSendKey(wh, 'e');
   _EdSendKey(wh, 'l');
   _EdSendKey(wh, 'l');
   _EdSendKey(wh, 'o');
   _EdSendKey(wh, ',');
   _EdSendKey(wh, ' ');
   _EdSendKey(wh, 'W');
   _EdSendKey(wh, 'o');
   _EdSendKey(wh, 'r');
   _EdSendKey(wh, 'l');
   _EdSendKey(wh, 'd');
   _EdSendKey(wh, '.');
   _EdSendKey(wh, 0x0d); // carriage return
   _EdSendKey(wh, 0x0a); // line feed
   _EdSendKey(wh, 0x1b); // esc char code is inserted in file
}

FoxInfo myFoxInfo[] = {
   {"SENDKEY", (FPFI) Example, 1, "C"},
};
FoxTable _FoxTable = {
   (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo
};

See Also

_EdInsert( ) API Library Routine | _EdGetChar( ) API Library Routine | _ASCIICOLS System Variable | _ASCIIROWS System Variable