Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Simulating Pointer Events

From Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): Nokia 5800 XpressMusic.
Platform(s): S60 5th Edition and later
Nokia Belle
Symbian Anna
S60 5th Edition
Platform Security
Signing Required: Self-Signed
Keywords: HandlePointerEventL().
Created: vasant21 (30 Nov 2008)
Last edited: hamishwillee (07 Aug 2012)



This snippet shows how to Simulate Pointer events in a Control.

S60 5th Edition devices are Touch UI ( Pointer ) Devices. Pointer events are handled by the controls. A control should implement the function HandlePointerEventL() to be able to handle pointer events. The HandlePointerEventL() function is called by the framework whenever a pointer event occurs within the control.

There are 10 kind of events listed in S60 platform, but we are only concerned with the following four events.

TPointerEvent::EButton1Down  /** Button 1 or pen down. */
TPointerEvent::EButton1Up /** Button 1 or pen up. */
/** This Event is only received after EButton1Down Event. */
/** These events are only received when button 1 is up and the XY input mode is not pen. */


Here we assume that we already have a working code for UI based Application.

MMP file

The following capabilities and libraries are required:

LIBRARY cone.lib 
#include <COECNTRL.H>

Simulating Pen Down Event.

TPointerEvent pointerEvent;
pointerEvent.iType = TPointerEvent::EButton1Down;
HandlePointerEventL( pointerEvent );

Simulating Pen Up Event.

TPointerEvent pointerEvent;
pointerEvent.iType = TPointerEvent::EButton1Up;
HandlePointerEventL( pointerEvent );

Simulating Pen Drag Event.

TPointerEvent pointerEvent;
pointerEvent.iType = TPointerEvent::EDrag;
HandlePointerEventL( pointerEvent );

Simulating Pen Move Event.

TPointerEvent pointerEvent;
pointerEvent.iType = TPointerEvent::EMove;
HandlePointerEventL( pointerEvent );

Simulating Pointer Events for a specific Control

Note that when a Control is a Compound Control, and if you want to simulate Pointer Events for a Component Control, then you have to get the two-dimensional Point Position in order to enable that pointer event to be processed successfully, because all the pointer events are ignored if the pointer events are not inside the control's window.

For example, If I want to produce/simulate Pen Down Event for Edwin and then I want Edwin->HandlePointerEventL() to handle/process it correctly, then i have to first get the location within the edwin window.

// Getting the cursor position 
TInt edwinCurPos = iEdwin->CursorPos();
// Get the Text View
CTextView* textView = iEdwin->TextView();
TPoint textViewPos;
// Gets the window coordinates of the Cursor position.
textView->DocPosToXyPosL(edwinCurPos, textViewPos);
// Then simulate Pen Down Event for Edwin.
TPointerEvent pointerEvent;
pointerEvent.iPosition = textViewPos;
pointerEvent.iType = TPointerEvent::EButton1Down;
// Now Pen Down Event will be handled correctly by Edwin.
iEdwin->HandlePointerEventL( pointerEvent );


Dummy Pointer Events will be passed to Control.

This page was last modified on 7 August 2012, at 02:39.
93 page views in the last 30 days.