| EV_sendEvent | Function (ROM Call 0xCE)

events.h

void EV_sendEvent (short TaskID, EVENT *event);

Sends an event message from the current side.

EV_sendEvent sends the event message described in the structure pointed to by event to the task/application with ID number TaskID (see below for more info about task IDs). Note that the user needs to pre-fill only Type field of the event structure and eventually extra field (if the message has extra information attached). All other fields will be filled by EV_sendEvent function before sending the message.
The Type field of the event structure is interpreted as following:

- If Type >=0x700, the message is an event command message (like CM_KEYPRESS, CM_WPAINT, etc. These codes are defined in enum EventIDs. These messages are the most common messages, and such messages are the most usable messages in user applications. See EventIDs for detailed description of the meaning of such messages.
- If 0x500 <=Type < 0x700, the message is a custom command message. The interpretation of such messages is strictly task-dependent. The TIOS uses such messages in dialogs, etc.
- If Type < 0x500, XR_string (see XR_stringPtr) is sent as the message. This is used for internal purposes in TIOS.

Here is the description what EV_sendEvent exactly does:

- If EV_hook pointer is not NULL, then a routine pointed to by it is called, passing event to it.
- If there is an user event handler installed (using EV_captureEvents), the user handler is called, and event is passed to it. In this case, parameter TaskID is ignored. The only exception is when the message is CM_WPAINT. In this case, the user handler is called only if TaskID is AP_NULL.
- If there is no user event handler installed, the message event is sent to the default application-dependent event handler, which is determined by parameter TaskID. Note that default application-dependent event handler will not be called if there is an user event handler installed. The exception is when the message is CM_WPAINT. This message is always dispatched to the default application-dependent handler, except if TaskID is AP_NULL.

Note that task ID numbers are inconsistent between AMS versions, so always call EV_getAppID before to determine an appropriate task ID, or use special task IDs AP_CURRENT, AP_RUNNING and AP_NONE, which are AMS-independent.
If you want to send an event from the user event handler, you can enter into an infinite recursion. Here is an example how to avoid this. The following program will change the behaviour of the ENTER key to behave like pressing DIAMOND+ENTER. So, run the following program (called "Approximation Mode"). After this, the ENTER key will behave like DIAMOND+ENTER (note that the program is "resident": it is active for whole time, although you have feeling that you are in "Home screen" for example). The ENTER key will remain redefined until the user press DIAMOND+ENTER. After this, the original function of the ENTER key is restored, and the program finishes working.

    // Run Home Screen in approximation mode

    #define USE_TI89              // Compile for TI-89
    #define USE_TI92PLUS          // Compile for TI-92 Plus
    #define USE_V200              // Compile for V200

    #define OPTIMIZE_ROM_CALLS    // Use ROM Call Optimization
    #define MIN_AMS 100           // Compile for AMS 1.00 or higher
    #define SAVE_SCREEN           // Save/Restore LCD Contents

    #include <tigcclib.h>         // Include All Header Files

    volatile EVENT_HANDLER Old_Handler;

    CALLBACK void Handler(EVENT *ev)
    {
      if (ev->Type == CM_KEYPRESS)
        {
          if (ev->extra.Key.Code == KEY_DIAMOND + KEY_ENTER)
            ER_throw (1);
          if (ev->extra.Key.Code == KEY_ENTER)
            ev->extra.Key.Code = KEY_DIAMOND + KEY_ENTER;
        }
      /* Send the event to the default application handler,
         but be careful to avoid infinite recursion! */
      EV_captureEvents (Old_Handler);
      EV_sendEvent (AP_CURRENT, ev);
      Old_Handler = EV_captureEvents (Handler);
    }

    void _main(void)
    {
      Old_Handler = EV_captureEvents (Handler);
      TRY
        EV_eventLoop ();
      ONERR
        EV_captureEvents (Old_Handler);
      ENDTRY
    }

Of course, this program is not extremely useful: the much easier method to achieve the same functionality is to set the calculator to "APPROX" mode. But, note that this is just an example, which should give you an idea how to redefine the keyboard.
Note: The destination application does not have to be started or active to receive messages. You should first start the application using EV_startApp if it is important that the application be on the screen before it receives an event.

Uses: EV_sendEventSide, EV_appSide
Used by: EV_centralDispatcher, EV_defaultHandler, EV_eventLoop, EV_notifySwitchGraph, EV_paintOneWindow, EV_sendString, EV_startApp, EV_startTask, EV_switch, handleRclKey, handleVarLinkKey, MO_notifyModeChange, cmd_disptbl, cmd_table, HomeExecute, CustomMenuItem, GraphActivate, ROM Call 0x424, ROM Call 0x428, ROM Call 0x455