Resources | developer.brewmp.com Resources | developer.brewmp.com

Developer

resources

Capturing all keypress events

Prior to BREW version 3.1, key events could be received only by the top-visible BREW application. (Only one application can be top-visible; other applications can either be running in the background or in a suspended state.) A privileged Brew MP application can receive all key events (in the form of key hook events) before they are sent to any other Brew MP application. To create the privileged Brew MP application, follow the steps below when creating its MIF file.

Receiving key hook events

There are two ways to create an application that receives key hook events; both require that the application be granted privileges. The first way is to grant the application the AEEPRIVID_KeyHooks privilege, which is specific to key hook events. The second is to set the AEE_AFLAG_PHONE flag, which requires that you also grant system privileges to the entire application.

Regardless of the method used to register for key hook events, when more than one key-hook-event registered application is running, Brew MP attempts to send each key hook event in a non-determined order. Any such registered application can consume the event by returning TRUE, so there is no guarantee that other registered applications will receive the event.

At least one privileged application will get EVT_KEY_HOOK, EVT_KEY_HOOK_PRESS, and EVT_KEY_HOOK_RELEASE events for every key pressed. If the key hook event is consumed by any privileged application, the corresponding EVT_KEY event will not be delivered to any other application, including the top-visible application. The AVK (AEE Virtual Key) code for the key will be in the wParam parameter of the event handler function of the application.

AEEPRIVID_KeyHooks privilege

  1. Open the module's CIF file.
  2. Look at the Applet primitive in the CIF file.
  3. Set the Privilege element in the Applet primitive to AEEPRIVID_KeyHooks. For example, the Applet primitive might look like the following:
    include "myapp.bid" // To use AEECLSID_MYAPP for appletid 
    include "AEEPLPrivs.bid" // To use AEEPRIVID_PLXXXX" 
      
    Applet {  
        appletid       = AEECLSID_MYAPP, 
        resbaseid      = 20, 
        applethostid   = 0,  
        flags          = 0,
        privs          = {AEEPRIVID_KeyHooks}, 
    }

AEE_AFLAG_PHONE privilege

  1. Open the module's CIF file.
  2. Look at the Applet primitive in the CIF file.
  3. Set the Flag element in the Applet primitive to AEE_AFLAG_PHONE, which causes the application to receive key hook events.

    Note: The AEE_AFLAG_PHONE flag requires system privileges.

    For example, the Applet primitive might look like the following:
    include "myapp.bid" -- Need to include to use AEECLSID_MYAPP for appletid 
    include "AEEAFlags.h" -- Need to include to use AEE_AFLAG_XXX for flags 
    include "AEEPLPrivs.bid" -- Need to include to use AEEPRIVID_PLXXXX" 
      
    Applet {  
        appletid       = AEECLSID_MYAPP, 
        resbaseid      = 20, 
        applethostid   = 0,  
        flags          = AEE_AFLAG_PHONE, 
        privs          = {AEEPRIVID_PLSystem}, 
    }

The AFLAG_PHONE privileged application has consumed the key event if it returns TRUE to the key hook events. If the key hook event is consumed, the key event is not passed to the current top-visible application. This provides a way for privileged applications to provide custom handling for specific key events such as AVK_END.

Note: There should be a very small number of applications on the device (preferably just one) that have AFLAG_PHONE set. Having the AFLAG_PHONE flag set on numerous applications can cause slowness on the device because every key event may be sent to each of these currently running applications before it is sent to the top-visible application.