Problem about emitting key event in neutrino RTP

I am working with Neutrino RTP. In my program , I realized a virtrul
Keyboard ,and use following program to send a key event:
static void send_key( long key )
{
PhEvent_t event;
PhRawKeyEvent_t key_event;

memset( &event , 0, sizeof(event) );
memset( &key_event, 0, sizeof(key_event) );

event.type = Ph_EV_KEY;
event.emitter.rid = Ph_DEV_RID;
event.data_len = sizeof(key_event);

key_event.key_cap = key;
key_event.key_sym = key;

if ( isascii( key ) && isupper( key ) )
{
key_event.key_mods = Pk_KM_Shift;
}

key_event.key_flags = Pk_KF_Sym_Valid | Pk_KF_Cap_Valid |
Pk_KF_Key_Down;

PhEventEmit( &event, NULL, &key_event );

key_event.key_flags &= ~Pk_KF_Key_Down;

PhEventEmit( &event, NULL, &key_event );

return;
}
this function is a part of the example program-- keypad , the key event is
sent well , but the letter I gotten was always doubled, that is ,when I emit
a ‘a’ key event , I get “aa” .
How do I solve this problem? another mothed?
My Email :zmc@263.net
thanks for anyone’s help .

zmc <zmc@263.net> wrote:

I am working with Neutrino RTP. In my program , I realized a virtrul
Keyboard ,and use following program to send a key event:
static void send_key( long key )

this function is a part of the example program-- keypad , the key event is
sent well , but the letter I gotten was always doubled, that is ,when I emit
a ‘a’ key event , I get “aa” .

That’s because the Pk_KF_Sym_Valid flag is set in both events. Change

key_event.key_flags &= ~Pk_KF_Key_Down;

to

key_event.key_flags &= ~( Pk_KF_Key_Down | Pk_KF_Sym_Valid );


\

Wojtek Lerch (wojtek@qnx.com) QNX Software Systems Ltd.

Thanks for your help! but the problem is still exist after I modified
program with your instruct.
But now ,I have resolved this problem , the key is that add a “rect”
parameter in function “PhEventEmit”.the
program is like following:
static void send_key( long key )
{
struct{
PhEvent_t event;
PhRect_t rect;
PhKeyEvent_t pevent;
} new_event;

PhEvent_t event;
PhKeyEvent_t key_event;

PhRect_t rect;


rect.ul.x = rect.ul.y =0;
rect.lr.x = rect.lr.y =SHRT_MAX;

memset( &event , 0, sizeof(event) );
memset( &key_event, 0, sizeof(key_event) );

event.type = Ph_EV_KEY;
event.emitter.rid = Ph_DEV_RID;
event.num_rects = 1;
event.data_len = sizeof(key_event);
event.input_group = 1;

key_event.key_cap = key;
key_event.key_sym = key;

if ( isascii( key ) && isupper( key ) )
{
key_event.key_mods = Pk_KM_Shift;
}

key_event.key_flags = Pk_KF_Sym_Valid | Pk_KF_Cap_Valid |
Pk_KF_Key_Down;
PhEventEmit( &event, &rect, &key_event );

key_event.key_flags &= ~(Pk_KF_Key_Down | Pk_KF_Sym_Valid) ;
PhEventEmit( &event ,&rect, &key_event );

return;
}
The virtual keyboard works well, but I still have some doubt .when I set
a negative value to rect.ul.x and rect.ul.y
,the problem arises again .


Wojtek Lerch <wojtek@qnx.com> wrote in message
news:8tpc4d$3r0$1@nntp.qnx.com

zmc <> zmc@263.net> > wrote:
I am working with Neutrino RTP. In my program , I realized a virtrul
Keyboard ,and use following program to send a key event:
static void send_key( long key )

this function is a part of the example program-- keypad , the key
event is
sent well , but the letter I gotten was always doubled, that is ,when I
emit
a ‘a’ key event , I get “aa” .

That’s because the Pk_KF_Sym_Valid flag is set in both events. Change

key_event.key_flags &= ~Pk_KF_Key_Down;

to

key_event.key_flags &= ~( Pk_KF_Key_Down | Pk_KF_Sym_Valid );


\

Wojtek Lerch (> wojtek@qnx.com> ) QNX Software Systems Ltd.

zmc <zmc@263.net> wrote:

Thanks for your help! but the problem is still exist after I modified
program with your instruct.
But now ,I have resolved this problem , the key is that add a “rect”
parameter in function “PhEventEmit”.the
program is like following:

rect.ul.x = rect.ul.y =0;
rect.lr.x = rect.lr.y =SHRT_MAX;

The virtual keyboard works well, but I still have some doubt .when I set
a negative value to rect.ul.x and rect.ul.y
,the problem arises again .

Oh yes, sorry I forgot about that…

I have a possible explanation of why you might be getting duplicate
events, and I’ll think of a fix for that, but setting the rect to
(0,0,0,0) is a simple fix, and that’s the best value for the rectangle
anyway.

The only problem you could have is when there is no window manager or
(possibly) when the window manager is set to “Cursor focus”. To make it
work even in those cases, you would have to emit raw events instead of
regular key events. I wonder if there’s an example of how to do that
somewhere in the docs…


Wojtek Lerch (wojtek@qnx.com) QNX Software Systems Ltd.